Explorar o código

2006-04-18 Senganal T <[email protected]>

	* Test/ProviderTests/System.Data.SqlClient/SqlConnectionTest.cs :
		- OpenTest_1 : test InvalidOperationException is raised if
		ConnectionString is empty
		- DisposeTest : test nullreference exception is not raised
	* System.Data.SqlClient/SqlConnection.cs :
		- SetConnectionString : set the pareameter to default values
		if connection string is empty or null
		- Open : Raise InvalidOperationException if Connection String
		is empty or null
		- Dispose : Test exception not raised if dispose called on a
		connection with empty connection string

	slight modification of the patch by Jonel Rienton


svn path=/trunk/mcs/; revision=59582
Senganal T %!s(int64=19) %!d(string=hai) anos
pai
achega
5cd065b00a

+ 12 - 0
mcs/class/System.Data/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,15 @@
+2006-04-18  Senganal T  <[email protected]>
+
+	* SqlConnection.cs :
+		- SetConnectionString : set the pareameter to default values
+		if connection string is empty or null
+		- Open : Raise InvalidOperationException if Connection String
+		is empty or null
+		- Dispose : Test exception not raised if dispose called on a
+		connection with empty connection string
+
+	slight modification of the patch by Jonel Rienton
+
 2006-04-07  Senganal T  <[email protected]>
 
 	* SqlCommandBuilder.cs :

+ 18 - 17
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs

@@ -436,19 +436,19 @@ namespace System.Data.SqlClient {
 
 		protected override void Dispose (bool disposing) 
 		{
-			if (!disposed) { 
-                                try {
-                                        if (disposing) {
-                                                if (State == ConnectionState.Open) 
-                                                        Close ();
-                                                parms.Reset ();
-                                                ConnectionString = "";
-						SetDefaultConnectionParameters (this.connStringParameters); 
-                                        }
-                                } finally {
-                                        disposed = true;
-                                        base.Dispose (disposing);
-                                }
+			if (disposed)
+				return;
+
+			try {
+				if (disposing) {
+					if (State == ConnectionState.Open) 
+						Close ();
+					ConnectionString = "";
+					SetDefaultConnectionParameters (this.connStringParameters); 
+				}
+			} finally {
+				disposed = true;
+				base.Dispose (disposing);
 			}
 		}
 
@@ -503,7 +503,7 @@ namespace System.Data.SqlClient {
 			if (state == ConnectionState.Open)
 				throw new InvalidOperationException ("The Connection is already Open (State=Open)");
 
-			if (connectionString == null)
+			if (connectionString == null || connectionString.Trim().Length == 0)
 				throw new InvalidOperationException ("Connection string has not been initialized.");
 
 			try {
@@ -552,7 +552,7 @@ namespace System.Data.SqlClient {
 			string theInstanceName = "";
 	
 			if (theDataSource == null)
-				throw new ArgumentException("Format of initialization string doesnot conform to specifications");
+				throw new ArgumentException("Format of initialization string does not conform to specifications");
 
 			thePort = 1433; // default TCP port for SQL Server
 			bool success = true;
@@ -633,8 +633,9 @@ namespace System.Data.SqlClient {
                         NameValueCollection parameters = new NameValueCollection ();
                         SetDefaultConnectionParameters (parameters);
 
-			if ((connectionString == null) || (connectionString.Length == 0)) {
-                                this.connectionString = connectionString;
+			if ((connectionString == null) || (connectionString.Trim().Length == 0)) {
+				this.connectionString = connectionString;
+				this.connStringParameters = parameters;
 				return;
                         }
 

+ 7 - 0
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,10 @@
+2006-04-18  Senganal T  <[email protected]>
+
+	* SqlConnectionTest.cs :
+		- OpenTest_1 : test InvalidOperationException is raised if
+		ConnectionString is empty
+		- DisposeTest : test nullreference exception is not raised
+
 2006-04-07  Senganal T  <[email protected]>
 
 	* SqlDataAdapterTest,cs :

+ 26 - 2
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlConnectionTest.cs

@@ -169,9 +169,9 @@ namespace MonoTests.System.Data
 				try {
 					conn.ConnectionString = connString;
 					conn.Open();
-					Assert.AreEqual (typeof (SqlException), null,
-						string.Format (
+					Assert.Fail (String.Format (
 							"#1_{0} Incorrect Connection String",count));				
+						
 				}catch (AssertionException e) {
 					throw e;
 				}catch (Exception e) {
@@ -215,6 +215,26 @@ namespace MonoTests.System.Data
 			 */
 		}
 
+		[Test]
+		public void OpenTest_1 ()
+		{
+			SqlConnection conn  = new SqlConnection ();
+
+			conn.ConnectionString = "";
+			try {
+				conn.Open ();
+				Assert.Fail ("#1 Should throw ArgumentException and not SqlException");
+			} catch (InvalidOperationException) {
+			}
+
+			conn.ConnectionString = "    ";
+			try {
+				conn.Open ();
+				Assert.Fail ("#2 Should throw ArgumentException and not SqlException");
+			} catch (InvalidOperationException) {
+			}
+		}
+
 		[Test]
 		public void CreateCommandTest ()
 		{
@@ -257,6 +277,10 @@ namespace MonoTests.System.Data
 				"#6 Default Workstationid : hostname");
 			Assert.AreEqual (ConnectionState.Closed, conn.State, 
 				"#7 Default State : CLOSED ");
+
+			conn = new SqlConnection ();
+			//shud not throw exception
+			conn.Dispose ();
 		}
 
 		[Test]