//
-// SqlDataAdapterTest.cs - NUnit Test Cases for testing the
-// SqlDataAdapter class
+// SqlConnectionTest.cs - NUnit Test Cases for testing the
+// SqlConnection class
// Author:
// Senganal T (tsenganal@novell.com)
//
//
using System;
+using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Net;
+using System.Threading;
+
using NUnit.Framework;
-using System.Collections;
-namespace MonoTests.System.Data
+namespace MonoTests.System.Data.Connected.SqlClient
{
[TestFixture]
[Category ("sqlserver")]
public class SqlConnectionTest
{
- SqlConnection conn = null ;
- String connectionString = ConnectionManager.Singleton.ConnectionString;
-
- ArrayList invalidConnectionStrings = null;
- int stateChangeEventCount = 0;
- int disposedEventCount = 0;
- int infoMessageEventCount = 0;
-
- void populateTestData ()
- {
- invalidConnectionStrings = new ArrayList ();
- // shud be got from a config file ..
- //list of invalid and valid conn strings;
- invalidConnectionStrings.Add ("InvalidConnectionString");
- invalidConnectionStrings.Add ("invalidKeyword=10");
- invalidConnectionStrings.Add ("Packet Size=511");
- invalidConnectionStrings.Add ("Packet Size=32768");
- invalidConnectionStrings.Add ("Connect Timeout=-1");
- invalidConnectionStrings.Add ("Max Pool Size=-1");
- invalidConnectionStrings.Add ("Min Pool Size=-1");
- }
+ SqlConnection conn;
+ String connectionString;
+ ArrayList events;
+ EngineConfig engine;
[SetUp]
public void SetUp ()
{
+ events = new ArrayList ();
+ connectionString = ConnectionManager.Instance.Sql.ConnectionString;
+ engine = ConnectionManager.Instance.Sql.EngineConfig;
}
[TearDown]
{
if (conn != null)
conn.Dispose ();
- }
-
- [Test]
- public void DefaultConstructorTest ()
- {
- SqlConnection conn = new SqlConnection ();
- Assert.AreEqual ("", conn.ConnectionString,
- "#1 Default Connection String should be empty");
- Assert.AreEqual (15, conn.ConnectionTimeout,
- "#2 Default ConnectionTimeout should be 15" );
- Assert.AreEqual ("", conn.Database,
- "#3 Default Database should be empty");
- Assert.AreEqual ("", conn.DataSource,
- "#4 Default DataSource should be empty");
- Assert.AreEqual (8192, conn.PacketSize,"#5 Default Packet Size is 8192");
- Assert.AreEqual (Dns.GetHostName().ToUpper (), conn.WorkstationId.ToUpper (),
- "#6 Default Workstationid shud be hostname");
- Assert.AreEqual (ConnectionState.Closed, conn.State,
- "#7 Connection State shud be closed by default");
+ if (connectionString != null)
+ SqlConnection.ClearAllPools ();
}
[Test]
public void OverloadedConstructorTest ()
{
- // Test Exceptions are thrown for Invalid Connection Strings
- int count=0 ;
- populateTestData ();
- foreach (String invalidConnString in invalidConnectionStrings) {
- count++;
- try {
- conn = new SqlConnection ((string)invalidConnString);
- Assert.Fail ("#1 Exception must be thrown");
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof(ArgumentException), e.GetType(),
- "Incorrect Exception" + e.StackTrace);
- }
- }
-
- //check synonyms..
+ //check synonyms.
//do i need to check for all the synonyms..
- conn = new SqlConnection (
- "Timeout=10;Connect Timeout=20;Connection Timeout=30");
- Assert.AreEqual (30, conn.ConnectionTimeout,
- "## The last set value shud be taken");
- conn = new SqlConnection (
- "Connect Timeout=100;Connection Timeout=200;Timeout=300");
- Assert.AreEqual (300, conn.ConnectionTimeout,
- "## The last set value shud be taken");
- conn = new SqlConnection (
- "Connection Timeout=1000;Timeout=2000;Connect Timeout=3000");
- Assert.AreEqual (3000, conn.ConnectionTimeout,
- "## The last set value shud be taken");
+ conn = new SqlConnection ("Timeout=10;Connect Timeout=20;Connection Timeout=30");
+ Assert.AreEqual (30, conn.ConnectionTimeout, "#A1");
+ conn = new SqlConnection ("Connect Timeout=100;Connection Timeout=200;Timeout=300");
+ Assert.AreEqual (300, conn.ConnectionTimeout, "#A2");
+ conn = new SqlConnection ("Connection Timeout=1000;Timeout=2000;Connect Timeout=3000");
+ Assert.AreEqual (3000, conn.ConnectionTimeout, "#A3");
- // Test if properties are set correctly
-
//'==' doesent work correctly in both msdotnet and mono
/*
conn = new SqlConnection ("server=local==host;database=tmp;");
Assert.AreEqual ("local==host", conn.DataSource,
"# Datasource name is set incorrectly");
*/
- string connStr = "Server='loca\"lhost';Database='''Db'; packet Size=\"512\";";
- connStr += "connect Timeout=20;Workstation Id=\"'\"\"desktop\";";
+ string connStr = "Server='loca\"lhost';Database='''Db'; packet Size=\"512\";"
+ + "connect Timeout=20;Workstation Id=\"'\"\"desktop\";";
conn = new SqlConnection (connStr);
- Assert.AreEqual (connStr , conn.ConnectionString , "#1");
- Assert.AreEqual ("loca\"lhost" , conn.DataSource , "#2");
- Assert.AreEqual ("'Db" , conn.Database , "#3");
- Assert.AreEqual (512 , conn.PacketSize , "#4");
- Assert.AreEqual (20 , conn.ConnectionTimeout , "#5");
- Assert.AreEqual ("'\"desktop" , conn.WorkstationId , "#6");
- Assert.AreEqual (ConnectionState.Closed , conn.State , "#7");
+ Assert.AreEqual (connStr , conn.ConnectionString , "#B1");
+ Assert.AreEqual ("loca\"lhost" , conn.DataSource , "#B2");
+ Assert.AreEqual ("'Db" , conn.Database , "#B3");
+ Assert.AreEqual (512 , conn.PacketSize , "#B4");
+ Assert.AreEqual (20 , conn.ConnectionTimeout , "#B5");
+ Assert.AreEqual ("'\"desktop" , conn.WorkstationId , "#B6");
}
[Test]
- public void OpenTest ()
+ public void Open ()
+ {
+ conn = new SqlConnection (connectionString);
+ conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
+ conn.Open ();
+
+ Assert.AreEqual (ConnectionState.Open, conn.State, "#1");
+ Assert.AreEqual (1, events.Count, "#2");
+ StateChangeEventArgs args = events [0] as StateChangeEventArgs;
+ Assert.IsNotNull (args, "#3");
+ Assert.AreEqual (ConnectionState.Closed, args.OriginalState, "#4");
+ Assert.AreEqual (ConnectionState.Open, args.CurrentState, "#5");
+
+ conn.Close ();
+ }
+
+ [Test]
+ public void Open_Connection_Open ()
{
conn = new SqlConnection (connectionString);
- ArrayList validIncorrectConnStrings = new ArrayList();
- string validConnString = connectionString;
-
- validIncorrectConnStrings.Add (
- validConnString+"user id=invalidLogin");
- validIncorrectConnStrings.Add (
- validConnString+"database=invalidDB");
- validIncorrectConnStrings.Add (
- validConnString+";password=invalidPassword");
- validIncorrectConnStrings.Add (
- validConnString+";server=invalidServerName");
-
- int count=0;
- foreach (string connString in validIncorrectConnStrings) {
- count++;
- try {
- conn.ConnectionString = connString;
- conn.Open();
- Assert.Fail (String.Format (
- "#1_{0} Incorrect Connection String",count));
-
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof (SqlException), e.GetType (),
- "#2 Incorrect Exception" + e.StackTrace);
- }
- }
-
- // Test connection is Opened for a valid Connection String
- conn.ConnectionString = connectionString;
conn.Open ();
- Assert.AreEqual (ConnectionState.Open, conn.State,
- "#3 Connection State Should be OPEN");
- // Test Exception is thrown on opening an OPEN Connection
try {
conn.Open ();
- Assert.AreEqual (typeof (InvalidOperationException), null,
- "#1 Connection is Already Open");
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof(InvalidOperationException), e.GetType (),
- "#2 Incorect Exception.");
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // The connection was not closed. The connection's
+ // current state is open
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ } finally {
+ conn.Close ();
}
- conn.Close();
-
- /*
- // Test if localhost is assumed when servername is empty/missing
- // NOTE : msdotnet contradicts doc
+ }
- Assumes the server is localhost .. need to test this with mono on windows
- conn.ConnectionString = connectionString + "server=;";
+ [Test]
+ public void Open_ConnectionString_LoginInvalid ()
+ {
+ // login invalid
+ conn = new SqlConnection (connectionString + "user id=invalidLogin");
try {
conn.Open ();
- }catch (Exception e) {
- Assert.Fail ("## If server name is not given or empty ,localhost shud be tried");
+ Assert.Fail ("#1");
+ } catch (SqlException ex) {
+ // Login failed for user 'invalidLogin'
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
+ Assert.AreEqual ((byte) 14, ex.Class, "#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.AreEqual (18456, ex.Number, "#7");
+ Assert.AreEqual ((byte) 1, ex.State, "#8");
+ } finally {
+ conn.Close ();
}
- ex = null;
- conn.Close ();
- */
}
[Test]
- public void OpenTest_1 ()
+ public void Open_ConnectionString_DatabaseInvalid ()
{
- SqlConnection conn = new SqlConnection ();
-
- conn.ConnectionString = "";
+ conn = new SqlConnection (connectionString + "database=invalidDB");
try {
conn.Open ();
- Assert.Fail ("#1 Should throw ArgumentException and not SqlException");
- } catch (InvalidOperationException) {
+ Assert.Fail ("#1");
+ } catch (SqlException ex) {
+ // Cannot open database "invalidDB" requested
+ // by the login. The login failed
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
+ Assert.AreEqual ((byte) 14, ex.Class, "#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.AreEqual (18456, ex.Number, "#7");
+ Assert.AreEqual ((byte) 1, ex.State, "#8");
+ } finally {
+ conn.Close ();
}
- conn.ConnectionString = " ";
+ }
+
+ [Test]
+ public void Open_ConnectionString_PasswordInvalid ()
+ {
+ // password invalid
+ conn = new SqlConnection (connectionString + ";password=invalidPassword");
try {
conn.Open ();
- Assert.Fail ("#2 Should throw ArgumentException and not SqlException");
- } catch (InvalidOperationException) {
+ Assert.Fail ("#1");
+ } catch (SqlException ex) {
+ // Login failed for user '...'
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
+ Assert.AreEqual ((byte) 14, ex.Class, "#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.AreEqual (18456, ex.Number, "#6");
+ Assert.AreEqual ((byte) 1, ex.State, "#7");
+ } finally {
+ conn.Close ();
}
}
[Test]
- public void CreateCommandTest ()
+ public void Open_ConnectionString_ServerInvalid ()
{
- conn = new SqlConnection (connectionString);
- IDbCommand cmd = conn.CreateCommand ();
- Assert.AreSame (conn, cmd.Connection,
- "#1 Connection instance should be the same");
+ Assert.Ignore ("Long running");
+
+ // server invalid
+ conn = new SqlConnection (connectionString + ";server=invalidServerName");
+ try {
+ conn.Open ();
+ Assert.Fail ("#1");
+ } catch (SqlException ex) {
+ // An error has occurred while establishing a
+ // connection to the server...
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
+ Assert.AreEqual ((byte) 20, ex.Class, "#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.AreEqual (53, ex.Number, "#6");
+ Assert.AreEqual ((byte) 0, ex.State, "#7");
+ } finally {
+ conn.Close ();
+ }
+ }
+
+ [Test] // bug #383061
+ [Category("NotWorking")]
+ public void Open_MaxPoolSize_Reached ()
+ {
+ connectionString += ";Pooling=true;Connection Lifetime=6;Connect Timeout=3;Max Pool Size=2";
+
+ SqlConnection conn1 = new SqlConnection (connectionString);
+ conn1.Open ();
+
+ SqlConnection conn2 = new SqlConnection (connectionString);
+ conn2.Open ();
+
+ DateTime start = DateTime.Now;
+
+ try {
+ using (SqlConnection sqlConnection = new SqlConnection (connectionString)) {
+ sqlConnection.Open ();
+ }
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ // System.InvalidOperationException: Timeout expired.
+ // The timeout period elapsed prior to obtaining a
+ // connection from the pool. This may have occurred
+ // because all pooled connections were in use and max
+ // pool size was reached.
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ }
+
+ TimeSpan elapsed = DateTime.Now - start;
+
+ Assert.IsTrue (elapsed.TotalSeconds >= 3, "#B1:" + elapsed.TotalSeconds);
+ Assert.IsTrue (elapsed.TotalSeconds < 4, "#B2:" + elapsed.TotalSeconds);
+
+ conn2.Close ();
+
+ // as the second connection is closed, we should now be
+ // able to open a new connection (which essentially
+ // uses the pooled connection from conn2)
+ SqlConnection conn3 = new SqlConnection (connectionString);
+ conn3.Open ();
+ conn3.Close ();
+
+ conn1.Close ();
}
- [Test]
- public void CloseTest ()
- {
+ [Test] // bug #412574
+ public void Close ()
+ {
conn = new SqlConnection (connectionString);
conn.Open ();
- Assert.AreEqual (ConnectionState.Open, conn.State,
- "#1 Connection State should be : Open");
+ conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
conn.Close ();
- Assert.AreEqual (ConnectionState.Closed, conn.State,
- "#1 Connection State Should : Closed");
- // Test Closing an already closed connection is Valid..
+
+ Assert.AreEqual (ConnectionState.Closed, conn.State, "#1");
+ Assert.AreEqual (1, events.Count, "#2");
+ StateChangeEventArgs args = events [0] as StateChangeEventArgs;
+ Assert.IsNotNull (args, "#3");
+ Assert.AreEqual (ConnectionState.Open, args.OriginalState, "#4");
+ Assert.AreEqual (ConnectionState.Closed, args.CurrentState, "5");
+
conn.Close ();
+
+ Assert.AreEqual (1, events.Count, "#6");
}
[Test]
- public void DisposeTest ()
+ public void ChangeDatabase ()
{
- SqlConnection conn = new SqlConnection (connectionString);
- conn.Dispose ();
- Assert.AreEqual ("", conn.ConnectionString,
- "#1 Dispose shud make the Connection String empty");
- Assert.AreEqual (15, conn.ConnectionTimeout,
- "#2 Default ConnectionTimeout : 15" );
- Assert.AreEqual ("", conn.Database,
- "#3 Default Database : empty");
- Assert.AreEqual ("", conn.DataSource,
- "#4 Default DataSource : empty");
- Assert.AreEqual (8192, conn.PacketSize,
- "#5 Default Packet Size : 8192");
- Assert.AreEqual (Dns.GetHostName().ToUpper (), conn.WorkstationId.ToUpper (),
- "#6 Default Workstationid : hostname");
- Assert.AreEqual (ConnectionState.Closed, conn.State,
- "#7 Default State : CLOSED ");
+ conn = new SqlConnection(connectionString);
+ conn.Open();
- conn = new SqlConnection ();
- //shud not throw exception
- conn.Dispose ();
+ if (ConnectionManager.Instance.Sql.IsAzure)
+ {
+ var exc = Assert.Throws<SqlException>(() => conn.ChangeDatabase("master"));
+ Assert.Equals(40508, exc.Number); //USE statement is not supported to switch between databases (Azure).
+ }
+ else
+ {
+ conn.ChangeDatabase("master");
+ Assert.AreEqual("master", conn.Database);
+ }
}
[Test]
- public void ChangeDatabaseTest ()
+ public void ChangeDatabase_DatabaseName_DoesNotExist ()
{
+ if (ConnectionManager.Instance.Sql.IsAzure)
+ Assert.Ignore("SQL Azure doesn't support 'ChangeDatabase'");
+
conn = new SqlConnection (connectionString);
+ conn.Open ();
+
String database = conn.Database;
- //Test if exception is thrown if connection is closed
try {
- conn.ChangeDatabase ("database");
- Assert.AreEqual (typeof (InvalidOperationException), null,
- "#1 Connection is Closed");
- }catch (AssertionException e){
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof (InvalidOperationException), e.GetType(),
- "#2 Incorrect Exception : " + e.StackTrace);
+ conn.ChangeDatabase ("doesnotexist");
+ Assert.Fail ("#1");
+ } catch (SqlException ex) {
+ // Could not locate entry in sysdatabases for
+ // database 'doesnotexist'. No entry found with
+ // that name. Make sure that the name is entered
+ // correctly.
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
+ Assert.AreEqual ((byte) 16, ex.Class, "#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.IsTrue (ex.Message.IndexOf ("'doesnotexist'") != -1, "#6");
+ Assert.AreEqual (911, ex.Number, "#7");
+ Assert.AreEqual ((byte) 1, ex.State, "#8");
+
+ Assert.AreEqual (database, conn.Database, "#9");
+ } finally {
+ conn.Close ();
}
+ }
- //Test if exception is thrown for invalid Database Names
- //need to add more to the list
+ [Test]
+ public void ChangeDatabase_DatabaseName_Empty ()
+ {
+ conn = new SqlConnection (connectionString);
conn.Open ();
- String[] InvalidDatabaseNames = {"", null, " "};
- for (int i = 0; i < InvalidDatabaseNames.Length ; ++i) {
- try {
- conn.ChangeDatabase (InvalidDatabaseNames[i]);
- Assert.AreEqual (typeof (ArgumentException), null,
- string.Format ("#3_{0} Exception not thrown",i));
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof(ArgumentException), e.GetType (),
- string.Format( "#4_{0} Incorrect Exception : {1}",
- i, e.StackTrace));
- }
- Assert.AreEqual (database, conn.Database,
- "#4 The Database shouldnt get changed if Operation Failed");
+ try {
+ conn.ChangeDatabase (string.Empty);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Database cannot be null, the empty string,
+ // or string of only whitespace
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName);
}
-
- //Test if exception is thrown if database name is non-existent
+ }
+
+ [Test]
+ public void ChangeDatabase_DatabaseName_Null ()
+ {
+ conn = new SqlConnection (connectionString);
+ conn.Open ();
try {
- conn.ChangeDatabase ("invalidDB");
- Assert.Fail ("#5 Exception must be thrown if database doesent exist");
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof(SqlException), e.GetType (),
- "#6 Incorrect Exception" + e.StackTrace);
+ conn.ChangeDatabase ((string) null);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Database cannot be null, the empty string,
+ // or string of only whitespace
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName);
}
- conn.Close ();
+ }
- //Test if '-' is a valid character in a database name
- //TODO : Check for database names that have more special Characters..
- conn.ConnectionString = connectionString;
+ [Test] // bug #412581
+ public void ChangeDatabase_DatabaseName_Whitespace ()
+ {
+ Assert.Ignore ("bug #412581");
+
+ conn = new SqlConnection (connectionString);
conn.Open ();
try {
- conn.ChangeDatabase ("mono-test");
- Assert.AreEqual ("mono-test", conn.Database,
- "#7 Database name should be mono-test");
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e){
- Assert.Fail ("#8 Unexpected Exception : DB Name can have a '-' : "
- + e);
+ conn.ChangeDatabase (" ");
+ Assert.Fail ("#1");
+ } catch (SqlException ex) {
+ // Could not locate entry in sysdatabases for
+ // database ' '. No entry found with that name.
+ // Make sure that the name is entered correctly
+ Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
+ Assert.AreEqual ((byte) 16, ex.Class, "#3");
+ Assert.IsNull (ex.InnerException, "#4");
+ Assert.IsNotNull (ex.Message, "#5");
+ Assert.IsTrue (ex.Message.IndexOf ("' '") != -1, "#6");
+ Assert.AreEqual (911, ex.Number, "#7");
+ Assert.AreEqual ((byte) 1, ex.State, "#8");
}
}
[Test]
- public void BeginTransactionTest()
+ [Category("NotWorking")]
+ public void ClearAllPools ()
+ {
+ SqlConnection conn1 = new SqlConnection (connectionString + ";Pooling=false");
+ conn1.Open ();
+
+ int initial_connection_count = GetConnectionCount (conn1);
+
+ SqlConnection conn2 = new SqlConnection (connectionString + ";App=A");
+ conn2.Open ();
+ conn2.Close ();
+
+ SqlConnection conn3 = new SqlConnection (connectionString + ";App=B");
+ conn3.Open ();
+ conn3.Close ();
+
+ Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
+
+ SqlConnection.ClearAllPools ();
+
+ Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#2");
+ conn1.Close ();
+ }
+
+ [Test] // bug #443131
+ [Category("NotWorking")]
+ public void ClearPool ()
+ {
+ SqlConnection conn1 = new SqlConnection (connectionString);
+ conn1.Open ();
+
+ int initial_connection_count = GetConnectionCount (conn1);
+
+ SqlConnection conn2 = new SqlConnection (connectionString);
+ conn2.Open ();
+
+ SqlConnection conn3 = new SqlConnection (connectionString);
+ conn3.Open ();
+ conn3.Close ();
+
+ Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
+
+ SqlConnection.ClearPool (conn1);
+
+ // check if pooled connections that were not in use are
+ // actually closed
+ Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn1), "#2");
+
+ conn2.Close ();
+
+ // check if connections that were in use when the pool
+ // was cleared will not be returned to the pool when
+ // closed (and are closed instead)
+ Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#3");
+
+ SqlConnection conn4 = new SqlConnection (connectionString);
+ conn4.Open ();
+
+ SqlConnection conn5 = new SqlConnection (connectionString);
+ conn5.Open ();
+
+ SqlConnection conn6 = new SqlConnection (connectionString);
+ conn6.Open ();
+
+ Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#4");
+
+ conn5.Close ();
+ conn6.Close ();
+
+ // check if new connections are stored in the pool again
+ Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#5");
+
+ conn1.Close ();
+
+ Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn4), "#6");
+
+ SqlConnection.ClearPool (conn3);
+
+ // the connection passed to ClearPool does not have to
+ // be open
+ Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#7");
+
+ SqlConnection conn7 = new SqlConnection (connectionString);
+ conn7.Open ();
+ conn7.Close ();
+
+ Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#8");
+
+ conn3.ConnectionString += ";App=B";
+ SqlConnection.ClearPool (conn3);
+
+ // check if a pool is identified by its connection string
+ Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#9");
+
+ SqlConnection conn8 = new SqlConnection (connectionString);
+ SqlConnection.ClearPool (conn8);
+
+ // connection should not have been opened before to
+ // clear the corresponding pool
+ Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#10");
+
+ SqlConnection conn9 = new SqlConnection (connectionString);
+ conn9.Open ();
+ conn9.Close ();
+
+ Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#11");
+
+ conn3.ConnectionString = connectionString;
+ SqlConnection.ClearPool (conn3);
+
+ Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#12");
+
+ SqlConnection conn10 = new SqlConnection (connectionString);
+ conn10.Open ();
+
+ SqlConnection conn11 = new SqlConnection (connectionString + ";App=B");
+ conn11.Open ();
+
+ SqlConnection conn12 = new SqlConnection (connectionString + ";App=B");
+ conn12.Open ();
+
+ SqlConnection conn13 = new SqlConnection (connectionString + ";App=B");
+ conn13.Open ();
+
+ conn10.Close ();
+ conn11.Close ();
+ conn12.Close ();
+ conn13.Close ();
+
+ Assert.AreEqual (initial_connection_count + 4, GetConnectionCount (conn4), "#13");
+
+ // check that other connection pools are not affected
+ SqlConnection.ClearPool (conn13);
+
+ Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#14");
+
+ SqlConnection conn14 = new SqlConnection (connectionString);
+ conn14.Open ();
+ conn14.Dispose ();
+
+ // a disposed connection cannot be used to clear a pool
+ SqlConnection.ClearPool (conn14);
+
+ Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#15");
+
+ SqlConnection.ClearPool (conn4);
+
+ Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#16");
+
+ conn4.Close ();
+ }
+
+ [Test]
+ public void InterfaceTransactionTest ()
{
conn = new SqlConnection (connectionString);
- SqlTransaction trans = null ;
+ conn.Open ();
+ IDbCommand idbCommand = new SqlCommand ("use [mono-test]", conn);
+ idbCommand.Connection = null;
+ Assert.AreEqual (null, idbCommand.Connection, "Connection should be null");
+ idbCommand.Transaction = null;
+ Assert.AreEqual (null, idbCommand.Transaction, "Transaction should be null");
- try {
- trans = conn.BeginTransaction ();
- Assert.Fail ("#1 Connection must be Open to Begin a Transaction");
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof (InvalidOperationException), e.GetType(),
- "#2 Incorrect Exception" + e.StackTrace);
- }
+ conn.Close ();
+ }
+ [Test]
+ public void BeginTransaction ()
+ {
+ conn = new SqlConnection (connectionString);
conn.Open ();
- trans = conn.BeginTransaction ();
- Assert.AreSame (conn, trans.Connection,
- "#3 Transaction should reference the same connection");
- Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel,
- "#4 Isolation Level shud be ReadCommitted");
+
+ SqlTransaction trans = conn.BeginTransaction ();
+ Assert.AreSame (conn, trans.Connection, "#A1");
+ Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel, "#A2");
trans.Rollback ();
+ trans = conn.BeginTransaction ();
+
try {
- trans = conn.BeginTransaction ();
- trans = conn.BeginTransaction ();
conn.BeginTransaction ();
- Assert.Fail ("#5 Parallel Transactions are not supported");
- }catch (AssertionException e) {
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
- "#6 Incorrect Exception" + e.StackTrace);
- }finally {
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ // SqlConnection does not support parallel transactions
+ Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ } finally {
trans.Rollback();
}
trans = conn.BeginTransaction ();
trans.Rollback ();
trans = conn.BeginTransaction ();
- trans.Commit();
+ trans.Commit ();
trans = conn.BeginTransaction ();
- }catch (Exception e) {
- Assert.Fail ("#7 Transaction can be opened after a rollback/commit");
- }finally {
+ } finally {
trans.Rollback ();
}
}
[Test]
- public void ConnectionStringPropertyTest ()
+ public void ConnectionString ()
{
- conn = new SqlConnection (connectionString) ;
- // Test Repeated Keyoword ..Should take the latest value
- conn.ConnectionString = conn.ConnectionString + ";server=RepeatedServer;" ;
- Assert.AreEqual ("RepeatedServer", ((SqlConnection)conn).DataSource,
- "#1 if keyword is repeated, the latest value should be taken");
+ conn = new SqlConnection (connectionString);
+ // Test Repeated Keyoword should take the latest value
+ conn.ConnectionString = conn.ConnectionString + ";server=RepeatedServer;";
+ Assert.AreEqual ("RepeatedServer", ((SqlConnection)conn).DataSource, "#A1");
conn.ConnectionString += ";database=gen;Initial Catalog=gen1";
- Assert.AreEqual ("gen1", conn.Database,
- "#2 database and initial catalog are synonyms .. ");
+ Assert.AreEqual ("gen1", conn.Database, "#A2");
- // Test if properties are set correctly
+ // Test if properties are set correctly
string str = "server=localhost1;database=db;user id=user;";
str += "password=pwd;Workstation ID=workstation;Packet Size=512;";
str += "Connect Timeout=10";
conn.ConnectionString = str;
- Assert.AreEqual ("localhost1", conn.DataSource,
- "#3 DataSource name should be same as passed");
- Assert.AreEqual ("db", conn.Database,
- "#4 Database name shud be same as passed");
- Assert.AreEqual (ConnectionState.Closed, conn.State,
- "#5 Connection shud be in closed state");
- Assert.AreEqual ("workstation", conn.WorkstationId,
- "#6 Workstation Id shud be same as passed");
- Assert.AreEqual (512, conn.PacketSize,
- "#7 Packetsize shud be same as passed");
- Assert.AreEqual (10, conn.ConnectionTimeout,
- "#8 ConnectionTimeout shud be same as passed");
+ Assert.AreEqual ("localhost1", conn.DataSource, "#B1");
+ Assert.AreEqual ("db", conn.Database, "#B2");
+ Assert.AreEqual (ConnectionState.Closed, conn.State, "#B3");
+ Assert.AreEqual ("workstation", conn.WorkstationId, "#B4");
+ Assert.AreEqual (512, conn.PacketSize, "#B5");
+ Assert.AreEqual (10, conn.ConnectionTimeout, "#B6");
- // Test if any leftover values exist from previous invocation.
+ // Test if any leftover values exist from previous invocation
conn.ConnectionString = connectionString;
- conn.ConnectionString = "";
- Assert.AreEqual ("", conn.DataSource,
- "#9 Datasource shud be reset to Default : Empty");
- Assert.AreEqual ("", conn.Database,
- "#10 Database shud reset to Default : Empty");
- Assert.AreEqual (8192, conn.PacketSize,
- "#11 Packetsize shud be reset to Default : 8192");
- Assert.AreEqual (15, conn.ConnectionTimeout,
- "#12 ConnectionTimeour shud be reset to Default : 15");
- Assert.AreEqual (Dns.GetHostName ().ToUpper (), conn.WorkstationId.ToUpper (),
- "#13 WorkstationId shud be reset to Default : Hostname");
-
- // Test Argument Exception is thrown for Invalid Connection Strings
- foreach (string connString in invalidConnectionStrings) {
- try {
- conn.ConnectionString = connString;
- Assert.Fail (
- "#14 Exception should be thrown");
- }catch (AssertionException e){
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof (ArgumentException), e.GetType(),
- "#15 Incorrect Exception" + e.StackTrace);
- }
- }
+ conn.ConnectionString = string.Empty;
+ Assert.AreEqual (string.Empty, conn.DataSource, "#C1");
+ Assert.AreEqual ("", conn.Database, "#C2");
+ Assert.AreEqual (8000, conn.PacketSize, "#C3");
+ Assert.AreEqual (15, conn.ConnectionTimeout, "#C4");
+ Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#C5");
+ }
- // Test if ConnectionString is read-only when Connection is OPEN
+ [Test]
+ public void ConnectionString_Connection_Open ()
+ {
+ conn = new SqlConnection (connectionString);
conn.ConnectionString = connectionString;
- conn.Open() ;
+ conn.Open ();
try {
- Assert.AreEqual (conn.State, ConnectionState.Open,
- "#16 Connection shud be open");
- conn.ConnectionString = "server=localhost;database=tmp;" ;
- Assert.Fail (
- "#17 ConnectionString should Read-Only when Connection is Open");
- }catch (AssertionException e){
- throw e;
- }catch (Exception e) {
- Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
- "#18 Incorrect Exception" + e.StackTrace);
+ conn.ConnectionString = "server=localhost;database=tmp;";
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // Not allowed to change the 'ConnectionString'
+ // property. The connection's current state is open
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ } finally {
+ conn.Close ();
}
- conn.Close ();
}
[Test]
public void ServerVersionTest ()
- {
+ {
conn = new SqlConnection (connectionString);
// Test InvalidOperation Exception is thrown if Connection is CLOSED
- try{
+ try {
string s = conn.ServerVersion;
- Assert.Fail (
- "#1 InvalidOperation Exception Must be thrown if conn is closed");
- }catch (AssertionException e){
- throw e;
- }catch (Exception e){
- Assert.AreEqual(typeof (InvalidOperationException), e.GetType (),
- "#2 Incorrect Exception" + e.StackTrace);
+ Assert.Fail ("#A1:" + s);
+ } catch (InvalidOperationException ex) {
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
}
// Test if Release Version is as per specification.
conn.Open ();
- String[] version = conn.ServerVersion.Split ('.') ;
+ String [] version = conn.ServerVersion.Split ('.');
Assert.AreEqual (2, version[0].Length,
- "#2 The Major release shud be exactly 2 characters");
+ "#B1 The Major release shud be exactly 2 characters");
Assert.AreEqual (2, version[1].Length,
- "#3 The Minor release shud be exactly 2 characters");
+ "#B2 The Minor release shud be exactly 2 characters");
Assert.AreEqual (4, version[2].Length,
- "#4 The Release version should be exactly 4 digits");
+ "#B3 The Release version should be exactly 4 digits");
}
[Test]
- public void DatabasePropertyTest ()
+ public void Database ()
{
+ if (ConnectionManager.Instance.Sql.IsAzure)
+ Assert.Ignore("SQL Azure doesn't support 'use [db]'");
+
conn = new SqlConnection (connectionString);
- string database = conn.Database ;
+ string database = conn.Database;
+
+ SqlCommand cmd;
// Test if database property is updated when a query changes database
conn.Open ();
- SqlCommand cmd = new SqlCommand ("use [mono-test]" , conn);
+ cmd = new SqlCommand ("use [master]" , conn);
cmd.ExecuteNonQuery ();
- Assert.AreEqual ("mono-test", conn.Database,
- "#1 DATABASE name shud change if query changes the db");
+ Assert.AreEqual ("master", conn.Database, "#1");
+
+ // ensure we're really in the expected database
+ if (ClientVersion == 7)
+ cmd.CommandText = "SELECT name FROM sysdatabases WHERE name = 'master'";
+ else
+ cmd.CommandText = "SELECT name FROM sys.databases WHERE name = 'master'";
+ using (SqlDataReader dr = cmd.ExecuteReader ()) {
+ Assert.IsTrue (dr.Read (), "#2");
+ }
+
conn.Close ();
- Assert.AreEqual (database, conn.Database,
- "#2 Shud be back to default value");
+ Assert.AreEqual (database, conn.Database, "#3");
// Test if the database property is reset on re-opening the connection
conn.ConnectionString = connectionString;
- conn.Open ();
- Assert.AreEqual (database, conn.Database,
- "#3 Shud be back to original value");
+ conn.Open ();
+ Assert.AreEqual (database, conn.Database, "#4");
+
+ // ensure we're really in the expected database
+ cmd.CommandText = "SELECT fname FROM employee WHERE id = 2";
+ using (SqlDataReader dr = cmd.ExecuteReader ()) {
+ Assert.IsTrue (dr.Read (), "#5");
+ Assert.AreEqual ("ramesh", dr.GetValue (0), "#6");
+ }
+
conn.Close ();
}
+ [Test] // bug #412571
+ public void Dispose ()
+ {
+ StateChangeEventArgs stateChangeArgs;
+ EventArgs disposedArgs;
+
+ conn = new SqlConnection (connectionString + ";Connection Timeout=30;Packet Size=512;Workstation Id=Desktop");
+ conn.Disposed += new EventHandler (Connection_Disposed);
+ conn.Open ();
+ conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
+ Assert.AreEqual (0, events.Count, "#A1");
+ conn.Dispose ();
+ Assert.AreEqual (string.Empty, conn.ConnectionString, "#A2");
+ Assert.AreEqual (15, conn.ConnectionTimeout, "#A3");
+ Assert.AreEqual (string.Empty, conn.Database, "#A4");
+ Assert.AreEqual (string.Empty, conn.DataSource, "#A5");
+ Assert.AreEqual (8000, conn.PacketSize, "#A6");
+ Assert.AreEqual (ConnectionState.Closed, conn.State, "#A7");
+ Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#A8");
+ Assert.AreEqual (2, events.Count, "#A9");
+
+ stateChangeArgs = events [0] as StateChangeEventArgs;
+ Assert.IsNotNull (stateChangeArgs, "#B1");
+ Assert.AreEqual (typeof (StateChangeEventArgs), stateChangeArgs.GetType (), "#B2");
+ Assert.AreEqual (ConnectionState.Open, stateChangeArgs.OriginalState, "#B3");
+ Assert.AreEqual (ConnectionState.Closed, stateChangeArgs.CurrentState, "B4");
+
+ disposedArgs = events [1] as EventArgs;
+ Assert.IsNotNull (disposedArgs, "#C1");
+ Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#C2");
+
+ conn.Dispose ();
+
+ Assert.AreEqual (ConnectionState.Closed, conn.State, "#D1");
+ Assert.AreEqual (3, events.Count, "#D2");
+
+ disposedArgs = events [2] as EventArgs;
+ Assert.IsNotNull (disposedArgs, "#E1");
+ Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#E2");
+ }
+
+ void Connection_StateChange (object sender , StateChangeEventArgs e)
+ {
+ events.Add (e);
+ }
+
+ void Connection_Disposed (object sender , EventArgs e)
+ {
+ events.Add (e);
+ }
+
[Test]
- public void StateChangeEventTest ()
+ public void FireInfoMessageEventOnUserErrorsTest ()
{
- conn = new SqlConnection (connectionString);
- conn.StateChange += new StateChangeEventHandler (
- StateChangeHandlerTest1);
- using (conn) {
- conn.Open ();
- }
- Assert.AreEqual (2, stateChangeEventCount,
- "#1 The handler shud be called twice");
- stateChangeEventCount =0 ;
- conn.StateChange -= new StateChangeEventHandler (
- StateChangeHandlerTest1);
- // NOTE : Need to check the behavior if an exception is raised
- // in a handler
+ conn = new SqlConnection ();
+ Assert.AreEqual(false, conn.FireInfoMessageEventOnUserErrors, "#1 The default value should be false");
+ conn.FireInfoMessageEventOnUserErrors = true;
+ Assert.AreEqual(true, conn.FireInfoMessageEventOnUserErrors, "#1 The value should be true after setting the property to true");
}
[Test]
- public void DisposedEventTest ()
+ public void StatisticsEnabledTest ()
{
- conn = new SqlConnection (connectionString);
- conn.Disposed += new EventHandler (DisposedEventHandlerTest1);
- conn.Dispose ();
- Assert.AreEqual (1, disposedEventCount,
- "#1 Disposed eventhandler shud be called");
+ conn = new SqlConnection ();
+ Assert.AreEqual(false, conn.StatisticsEnabled, "#1 The default value should be false");
+ conn.StatisticsEnabled = true;
+ Assert.AreEqual(true, conn.StatisticsEnabled, "#1 The value should be true after setting the property to true");
}
- void StateChangeHandlerTest1 (object sender , StateChangeEventArgs e)
+ [Test]
+ [Category("NotWorking")]
+ public void ChangePasswordTest ()
{
- Assert.IsTrue ((e.CurrentState != e.OriginalState),
- "#1 Current and Original state shud be different");
- Assert.AreEqual (e.CurrentState, conn.State,
- "The conn state and the arg received in event shud be same");
- stateChangeEventCount++ ;
+ string tmpPassword = "modifiedbymonosqlclient";
+ SqlConnection.ChangePassword (connectionString, tmpPassword);
+ SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder (connectionString);
+ string oldPassword = connBuilder.Password;
+ connBuilder.Password = tmpPassword;
+ SqlConnection.ChangePassword (connBuilder.ConnectionString, oldPassword); // Modify to the original password
}
- void DisposedEventHandlerTest1 (object sender , EventArgs e)
+ static int GetConnectionCount (SqlConnection conn)
{
- disposedEventCount++;
+ Thread.Sleep (200);
+
+ SqlCommand cmd = conn.CreateCommand ();
+ cmd.CommandText = "select count(*) from master..sysprocesses where db_name(dbid) = @dbname";
+ cmd.Parameters.Add (new SqlParameter ("@dbname", conn.Database));
+ int connection_count = (int) cmd.ExecuteScalar ();
+ cmd.Dispose ();
+
+ return connection_count;
+ }
+
+ int ClientVersion {
+ get {
+ return (engine.ClientVersion);
+ }
}
}
- #if NET_2_0
+
[TestFixture]
[Category ("sqlserver")]
public class GetSchemaTest
{
SqlConnection conn = null;
- String connectionString = ConnectionManager.Singleton.ConnectionString;
+ String connectionString = ConnectionManager.Instance.Sql.ConnectionString;
[SetUp]
- public void Setup()
+ public void SetUp()
{
conn = new SqlConnection(connectionString);
conn.Open();
}
+
[TearDown]
public void TearDown()
{
- conn.Close();
+ conn?.Close();
}
+
[Test]
public void GetSchemaTest1()
{
+ if (ConnectionManager.Instance.Sql.IsAzure)
+ Assert.Ignore("SQL Azure - Not supported'");
+
bool flag = false;
DataTable tab1 = conn.GetSchema("databases");
foreach (DataRow row in tab1.Rows)
{
foreach (DataColumn col in tab1.Columns)
{
- if (col.ColumnName.ToString() == "database_name" && row[col].ToString() == "monotest")
+ if (col.ColumnName.ToString() == "database_name" && row[col].ToString() == ConnectionManager.Instance.DatabaseName)
{
flag = true;
break;
}
Assert.AreEqual(true, flag, "#GS1 failed");
}
+
[Test]
[ExpectedException(typeof(ArgumentException))]
public void GetSchemaTest2()
{
conn.GetSchema(null);
}
+
[Test]
- public void GetSchemaTest3()
+ public void GetSchemaTest3 ()
{
+ Assert.Ignore ("We currently have no foreign keys defined in the test database");
+
bool flag = false;
DataTable tab1 = conn.GetSchema("ForeignKeys");
foreach (DataRow row in tab1.Rows)
}
Assert.AreEqual(true, flag, "#GS3 failed");
}
+
[Test]
public void GetSchemaTest4()
{
}
Assert.AreEqual(true, flag, "#GS4 failed");
}
+
[Test]
public void GetSchemaTest5()
{
}
Assert.AreEqual(true, flag, "#GS5 failed");
}
+
[Test]
public void GetSchemaTest6()
{
}
Assert.AreEqual(true, flag, "#GS6 failed");
}
+
[Test]
public void GetSchemaTest7()
{
}
Assert.AreEqual(true, flag, "#GS7 failed");
}
+
[Test]
public void GetSchemaTest8()
{
}
Assert.AreEqual(true, flag, "#GS8 failed");
}
+
[Test]
public void GetSchemaTest9()
{
+ if (ConnectionManager.Instance.Sql.IsAzure)
+ Assert.Ignore("SQL Azure - Not supported'");
+
bool flag = false;
DataTable tab1 = conn.GetSchema("Columns");
foreach (DataRow row in tab1.Rows)
}
Assert.AreEqual(true, flag, "#GS9 failed");
}
+
+ [Test]
public void GetSchemaTest10()
{
bool flag = false;
}
Assert.AreEqual(true, flag, "#GS10 failed");
}
- public void GetSchemaTest11()
+
+ [Test]
+ public void GetSchemaTest11 ()
{
+ Assert.Ignore ("Incorrect syntax near 'TABLE_SCHEMA'");
+
bool flag = false;
DataTable tab1 = conn.GetSchema("Views");
flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
}
Assert.AreEqual(true, flag, "#GS11 failed");
}
- public void GetSchemaTest12()
+
+ [Test]
+ public void GetSchemaTest12 ()
{
+ Assert.Ignore ("Incorrect syntax near '('");
+
bool flag = false;
DataTable tab1 = conn.GetSchema("ViewColumns");
flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
}
Assert.AreEqual(true, flag, "#GS12 failed");
}
- public void GetSchemaTest13()
+
+ [Test]
+ public void GetSchemaTest13 ()
{
+ Assert.Ignore ("The multi-part identifier \"assportemblies.name\" could not be bound");
+
bool flag = false;
- DataTable tab1 = conn.GetSchema("UserDefineTypes");
+ DataTable tab1 = conn.GetSchema("UserDefinedTypes");
flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
foreach (DataRow row in tab1.Rows)
{
}
Assert.AreEqual(true, flag, "#GS13 failed");
}
+
[Test]
+ [Ignore("TODO: fix restrictions")]
public void GetSchemaTest14()
{
bool flag = false;
string [] restrictions = new string[4];
- restrictions[0] = "monotest";
+ restrictions[0] = ConnectionManager.Instance.DatabaseName;
restrictions[1] = "dbo";
restrictions[2] = null;
restrictions[3] = "BASE TABLE";
}
Assert.AreEqual(true, flag, "#GS14 failed");
}
+
[Test]
+ [Ignore("TODO: fix restrictions")]
public void GetSchemaTest15()
{
bool flag = false;
string [] restrictions = new string[4];
- restrictions[0] = "monotest";
+ restrictions[0] = ConnectionManager.Instance.DatabaseName;
restrictions[1] = null;
restrictions[2] = "binary_family";
restrictions[3] = null;
}
Assert.AreEqual(true, flag, "#GS15 failed");
}
+
[Test]
+ [Ignore("TODO: fix restrictions")]
public void GetSchemaTest16()
{
bool flag = false;
string [] restrictions = new string[4];
- restrictions[0] = "monotest";
+ restrictions[0] = ConnectionManager.Instance.DatabaseName;
restrictions[1] = null;
restrictions[2] = "sp_get_age";
restrictions[3] = null;
}
Assert.AreEqual(true, flag, "#GS16 failed");
}
+
[Test]
public void GetSchemaTest17()
{
}
Assert.AreEqual(true, flag, "#GS17 failed");
}
+
[Test]
public void GetSchemaTest18()
{
}
Assert.AreEqual(true, flag, "#GS18 failed");
}
+
[Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetSchemaTest19()
+ [ExpectedException (typeof (ArgumentException))]
+ public void GetSchemaTest19 ()
{
String [] restrictions = new String[1];
- DataTable tab1 = conn.GetSchema("RESTRICTIONS", restrictions);
+ conn.GetSchema("RESTRICTIONS", restrictions);
}
+
[Test]
- public void GetSchemaTest20()
+ public void GetSchemaTest20 ()
{
bool flag = false;
DataTable tab1 = conn.GetSchema("DataTypes");
}
Assert.AreEqual(true, flag, "#GS20 failed");
}
+
[Test]
public void GetSchemaTest21()
{
}
Assert.AreEqual(true, flag, "#GS22 failed");
}
+
[Test]
public void GetSchemaTest23()
{
}
Assert.AreEqual(false, flag, "#GS23 failed");
}
+
[Test]
public void GetSchemaTest24()
{
bool flag = false;
string [] restrictions = new string[4];
- restrictions[0] = "monotest";
+ restrictions[0] = ConnectionManager.Instance.DatabaseName;
restrictions[1] = null;
restrictions[2] = "sp_get_age";
restrictions[3] = null;
}
Assert.AreEqual(false, flag, "#GS24 failed");
}
+
[Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetSchemaTest25()
+ [ExpectedException (typeof (ArgumentException))]
+ public void GetSchemaTest25 ()
{
- String [] restrictions = new String[1];
- DataTable tab1 = conn.GetSchema("Mono", restrictions);
+ String [] restrictions = new String [1];
+ conn.GetSchema ("Mono", restrictions);
}
}
- #endif
}