SqlConnectionTest.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // SqlConnectionTest.cs - NUnit Test Cases for testing the
  3. // SqlConnection class
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. //
  7. // Copyright (c) 2004 Novell Inc., and the individuals listed
  8. // on the ChangeLog entries.
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Data;
  31. using System.Data.SqlClient;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Data.SqlClient
  34. {
  35. [TestFixture]
  36. public class SqlConnectionTest
  37. {
  38. [Test]
  39. public void DefaultConnectionValues()
  40. {
  41. SqlConnection cn = new SqlConnection ();
  42. Assert.AreEqual (15, cn.ConnectionTimeout,
  43. "Default connection timeout should be 15 seconds");
  44. Assert.AreEqual ("", cn.Database,
  45. "Default database name should be empty string");
  46. Assert.AreEqual ("", cn.DataSource,
  47. "Default data source should be empty string");
  48. Assert.AreEqual (8192, cn.PacketSize,
  49. "Default packet size should be 8192 bytes");
  50. Assert.AreEqual (ConnectionState.Closed, cn.State,
  51. "Default connection state should be closed");
  52. }
  53. [Test]
  54. public void ConnectionTimeoutSynonyms()
  55. {
  56. SqlConnection cn = null;
  57. cn = new SqlConnection ();
  58. cn.ConnectionString = "Connection Timeout=25";
  59. Assert.AreEqual (25, cn.ConnectionTimeout);
  60. cn = new SqlConnection ();
  61. cn.ConnectionString = "Connect Timeout=25";
  62. Assert.AreEqual (25, cn.ConnectionTimeout);
  63. cn = new SqlConnection ();
  64. cn.ConnectionString = "Timeout=25";
  65. Assert.AreEqual (25, cn.ConnectionTimeout);
  66. }
  67. [Test]
  68. public void NetworkLibrarySynonyms()
  69. {
  70. SqlConnection cn = new SqlConnection ();
  71. cn.ConnectionString = "Net=DBMSSOCN";
  72. cn.ConnectionString = "Network=DBMSSOCN";
  73. cn.ConnectionString = "Network library=DBMSSOCN";
  74. }
  75. [Test]
  76. public void DatabaseSynonyms()
  77. {
  78. SqlConnection cn = null;
  79. cn = new SqlConnection ();
  80. cn.ConnectionString = "Initial Catalog=db";
  81. Assert.AreEqual ("db", cn.Database);
  82. cn = new SqlConnection ();
  83. cn.ConnectionString = "Database=db";
  84. Assert.AreEqual ("db", cn.Database);
  85. }
  86. [Test]
  87. public void DataSourceSynonyms()
  88. {
  89. SqlConnection cn = null;
  90. cn = new SqlConnection ();
  91. cn.ConnectionString = "Data Source=server";
  92. Assert.AreEqual ("server", cn.DataSource);
  93. cn = new SqlConnection ();
  94. cn.ConnectionString = "addr=server";
  95. Assert.AreEqual ("server", cn.DataSource);
  96. cn = new SqlConnection ();
  97. cn.ConnectionString = "address=server";
  98. Assert.AreEqual ("server", cn.DataSource);
  99. cn = new SqlConnection ();
  100. cn.ConnectionString = "network address=server";
  101. Assert.AreEqual ("server", cn.DataSource);
  102. cn = new SqlConnection ();
  103. cn.ConnectionString = "server=server";
  104. Assert.AreEqual ("server", cn.DataSource);
  105. }
  106. [Test]
  107. public void OtherConnectionStringKeywords()
  108. {
  109. SqlConnection cn = new SqlConnection ();
  110. cn.ConnectionString = "Application Name=test";
  111. cn.ConnectionString = "App=test";
  112. cn.ConnectionString = "Connection LifeTime=1000";
  113. cn.ConnectionString = "Connection Reset=true";
  114. cn.ConnectionString = "Current Language=test";
  115. cn.ConnectionString = "Language=test";
  116. cn.ConnectionString = "Encrypt=false";
  117. cn.ConnectionString = "Enlist=true";
  118. cn.ConnectionString = "Integrated Security=true";
  119. cn.ConnectionString = "Trusted_connection=true";
  120. cn.ConnectionString = "Max Pool Size=10";
  121. cn.ConnectionString = "Min Pool Size=10";
  122. cn.ConnectionString = "Password=scrambled";
  123. cn.ConnectionString = "Pwd=scrambled";
  124. cn.ConnectionString = "Persist Security Info=true";
  125. cn.ConnectionString = "PersistSecurityInfo=true";
  126. cn.ConnectionString = "Pooling=true";
  127. cn.ConnectionString = "User Id=test";
  128. cn.ConnectionString = "User=test";
  129. cn.ConnectionString = "Uid=test";
  130. /*
  131. * NOT IMPLEMENTED YET
  132. */
  133. /*
  134. cn.ConnectionString = "Encrypt=true";
  135. cn.ConnectionString = "Enlist=false";
  136. cn.ConnectionString = "attachdbfilename=dunno";
  137. cn.ConnectionString = "extended properties=dunno";
  138. cn.ConnectionString = "initial file name=dunno";
  139. */
  140. }
  141. }
  142. }