[System.Data] Integration tests (#4538)
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlDataAdapterTest.cs
index 2724b6fc11fff5a92af3e1442d61af3b6af5083d..0c109b29b9a892502ab77584379e193893016f7c 100644 (file)
@@ -33,34 +33,213 @@ using System;
 using System.Data;
 using System.Data.Common;
 using System.Data.SqlClient;
+using System.Configuration;
 
 using NUnit.Framework;
 
-namespace MonoTests.System.Data.SqlClient
+namespace MonoTests.System.Data.Connected.SqlClient
 {
-
        [TestFixture]
        [Category ("sqlserver")]
        public class SqlDataAdapterTest
        {
-               SqlDataAdapter adapter =null; 
-               DataSet data = null ;
-               string  connectionString = ConnectionManager.Singleton.ConnectionString;
-               SqlConnection conn = null; 
+               SqlDataAdapter adapter;
+               SqlDataReader dr;
+               DataSet data;
+               string connectionString = ConnectionManager.Instance.Sql.ConnectionString;
+               SqlConnection conn;
+               EngineConfig engine;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       engine = ConnectionManager.Instance.Sql.EngineConfig;
+               }
+
+               [TearDown]
+               public void TearDown ()
+               {
+                       if (adapter != null) {
+                               adapter.Dispose ();
+                               adapter = null;
+                       }
+
+                       if (dr != null) {
+                               dr.Close ();
+                               dr = null;
+                       }
+
+                       if (conn != null) {
+                               conn.Close ();
+                               conn = null;
+                       }
+               }
+
+               [Test]
+               [Category("NotWorking")]
+               public void Update_DeleteRow ()
+               {
+                       conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
+                       conn.Open ();
+
+                       DataTable dt = new DataTable ();
+                       adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
+                       SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
+                       adapter.DeleteCommand = builder.GetDeleteCommand ();
+                       adapter.Fill (dt);
+
+                       DateTime now = DateTime.Now;
+
+                       DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+                               now.Minute, now.Second);
+
+                       DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+                               now.Minute, now.Second);
+                       dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
+
+                       try {
+                               DataRow newRow = dt.NewRow ();
+                               newRow ["id"] = 6002;
+                               newRow ["fname"] = "boston";
+                               newRow ["dob"] = dob;
+                               newRow ["doj"] = doj;
+                               newRow ["email"] = "mono@novell.com";
+                               dt.Rows.Add (newRow);
+                               adapter.Update (dt);
+
+                               foreach (DataRow row in dt.Rows)
+                                       if (((int) row ["id"]) == 6002)
+                                               row.Delete ();
+                               adapter.Update (dt);
+
+                               SqlCommand cmd = conn.CreateCommand ();
+                               cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
+                               dr = cmd.ExecuteReader ();
+                               Assert.IsFalse (dr.Read ());
+                               dr.Close ();
+                       } finally {
+                               DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+                       }
+               }
+
+               [Test]
+               [Category("NotWorking")]
+               public void Update_InsertRow ()
+               {
+                       conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
+                       conn.Open ();
+
+                       DataTable dt = new DataTable ();
+                       adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
+
+                       SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
+                       adapter.InsertCommand = builder.GetInsertCommand ();
+                       adapter.Fill (dt);
+
+                       DateTime now = DateTime.Now;
+
+                       DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+                               now.Minute, now.Second);
+
+                       DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+                               now.Minute, now.Second);
+                       dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
+
+                       try {
+                               DataRow newRow = dt.NewRow ();
+                               newRow ["id"] = 6002;
+                               newRow ["fname"] = "boston";
+                               newRow ["dob"] = dob;
+                               newRow ["doj"] = doj;
+                               newRow ["email"] = "mono@novell.com";
+                               dt.Rows.Add (newRow);
+                               adapter.Update (dt);
+
+                               SqlCommand cmd = conn.CreateCommand ();
+                               cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
+                               dr = cmd.ExecuteReader ();
+                               Assert.IsTrue (dr.Read (), "#A1");
+                               Assert.AreEqual (6002, dr.GetValue (0), "#A2");
+                               Assert.AreEqual ("boston", dr.GetValue (1), "#A3");
+                               Assert.AreEqual (DBNull.Value, dr.GetValue (2), "#A4");
+                               Assert.AreEqual (dob, dr.GetValue (3), "#A5");
+                               Assert.AreEqual (doj, dr.GetValue (4), "#A6");
+                               Assert.AreEqual ("mono@novell.com", dr.GetValue (5), "#A7");
+                               Assert.IsFalse (dr.Read (), "#A8");
+                               dr.Close ();
+                       } finally {
+                               DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+                       }
+               }
 
                [Test]
+               [Category("NotWorking")]
+               public void Update_UpdateRow ()
+               {
+                       conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
+                       conn.Open ();
+
+                       DataTable dt = new DataTable ();
+                       adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
+                       SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
+                       adapter.UpdateCommand = builder.GetUpdateCommand ();
+                       adapter.Fill (dt);
+
+                       DateTime now = DateTime.Now;
+
+                       DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+                               now.Minute, now.Second);
+
+                       DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+                               now.Minute, now.Second);
+                       dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
+
+                       try {
+                               DataRow newRow = dt.NewRow ();
+                               newRow ["id"] = 6002;
+                               newRow ["fname"] = "boston";
+                               newRow ["dob"] = dob;
+                               newRow ["doj"] = doj;
+                               newRow ["email"] = "mono@novell.com";
+                               dt.Rows.Add (newRow);
+                               adapter.Update (dt);
+
+                               foreach (DataRow row in dt.Rows)
+                                       if (((int) row ["id"]) == 6002)
+                                               row ["lname"] = "de Icaza";
+                               adapter.Update (dt);
+
+                               SqlCommand cmd = conn.CreateCommand ();
+                               cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
+                               dr = cmd.ExecuteReader ();
+                               Assert.IsTrue (dr.Read (), "#A1");
+                               Assert.AreEqual (6002, dr.GetValue (0), "#A2");
+                               Assert.AreEqual ("boston", dr.GetValue (1), "#A3");
+                               Assert.AreEqual ("de Icaza", dr.GetValue (2), "#A4");
+                               Assert.AreEqual (dob, dr.GetValue (3), "#A5");
+                               Assert.AreEqual (doj, dr.GetValue (4), "#A6");
+                               Assert.AreEqual ("mono@novell.com", dr.GetValue (5), "#A7");
+                               Assert.IsFalse (dr.Read (), "#A8");
+                               dr.Close ();
+                       } finally {
+                               DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+                       }
+               }
+
                /**
                   The below test will not run everytime, since the region id column is unique
                   so change the regionid if you want the test to pass.
-               **/     
+               **/
+               /*
+               [Test]
                public void UpdateTest () {
                        conn = (SqlConnection) ConnectionManager.Singleton.Connection;
                        try {
                                ConnectionManager.Singleton.OpenConnection ();
                                DataTable dt = new DataTable();
                                SqlDataAdapter da = null;
-                               da = new SqlDataAdapter("Select * from employee;", conn);
-                               SqlCommandBuilder cb = new SqlCommandBuilder (da);
+                               da = new SqlDataAdapter("Select * from employee", conn);
+                               //SqlCommandBuilder cb = new SqlCommandBuilder (da);
                                da.Fill(dt);
                                DataRow dr = dt.NewRow();
                                dr ["id"] = 6002;
@@ -72,9 +251,53 @@ namespace MonoTests.System.Data.SqlClient
                                da.Update(dt);
                        } finally {
                                DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
-                               ConnectionManager.Singleton.CloseConnection ();
+                               ConnectionManager.Singleton.Sql.CloseConnection ();
+                       }
+               }
+
+               private static void OnRowUpdatedTest (object sender, SqlRowUpdatedEventArgs e)
+               {
+                       rowUpdated = true;
+               }
+
+               private static void OnRowUpdatingTest (object sender, SqlRowUpdatingEventArgs e)
+               {
+                       rowUpdating = true;
+               }
+
+               private static bool rowUpdated = false;
+               private static bool rowUpdating = false;
+               [Test]
+               public void RowUpdatedTest () {
+                       conn = (SqlConnection) ConnectionManager.Singleton.Connection;
+                       try {
+                               ConnectionManager.Singleton.OpenConnection ();
+                               DataTable dt = null;
+                               DataSet ds = new DataSet ();
+                               SqlDataAdapter da = null;
+                               da = new SqlDataAdapter("Select * from employee", conn);
+                               //SqlCommandBuilder cb = new SqlCommandBuilder (da);
+                               rowUpdated = false;
+                               rowUpdating = false;
+                               da.RowUpdated += new SqlRowUpdatedEventHandler (OnRowUpdatedTest);
+                               da.RowUpdating += new SqlRowUpdatingEventHandler (OnRowUpdatingTest);
+                               da.Fill (ds);
+                               dt = ds.Tables [0];
+                               dt.Rows[0][0] = 200;
+                               da.UpdateCommand = new SqlCommand ("Update employee set id = @id");
+                               da.Update (dt);
+                               dt.Rows[0][0] = 1;
+                               da.Update (dt);
+                               da.RowUpdated -= new SqlRowUpdatedEventHandler (OnRowUpdatedTest);
+                               da.RowUpdating -= new SqlRowUpdatingEventHandler (OnRowUpdatingTest);
+                               Assert.AreEqual (true, rowUpdated, "RowUpdated");
+                               Assert.AreEqual (true, rowUpdating, "RowUpdating");
+                       } finally {
+                               DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+                               ConnectionManager.Singleton.Sql.CloseConnection ();
                        }
                }
+               */
 
                /**
                   This needs a errortable created as follows 
@@ -84,11 +307,10 @@ namespace MonoTests.System.Data.SqlClient
                   NULL         bbbbbb
                **/
                [Test]
-               public void NullGuidTest() 
+               public void NullGuidTest()
                {
-                       conn = (SqlConnection) ConnectionManager.Singleton.Connection;
+                       conn = ConnectionManager.Instance.Sql.Connection;
                        try {
-                               ConnectionManager.Singleton.OpenConnection ();
                                DBHelper.ExecuteNonQuery (conn, "create table #tmp_guid_table ( " +
                                                          " id uniqueidentifier default newid (), " +
                                                          " name char (10))");
@@ -100,11 +322,10 @@ namespace MonoTests.System.Data.SqlClient
                                Assert.AreEqual (1, ds.Tables.Count, "#1");
                                Assert.AreEqual (DBNull.Value, ds.Tables [0].Rows [1] ["id"], "#2");
                        } finally {
-                               ConnectionManager.Singleton.CloseConnection ();
+                               ConnectionManager.Instance.Sql.CloseConnection ();
                        }
                        // the bug 68804 - is that the fill hangs!
                        Assert.AreEqual("Done","Done");
-                                       
                }
 
                [Test]
@@ -162,6 +383,7 @@ namespace MonoTests.System.Data.SqlClient
                                adapter.SelectCommand.Connection.ConnectionString,
                                "#11  ");
                }
+
                [Test]
                public void Fill_Test_ConnState ()
                {
@@ -192,7 +414,7 @@ namespace MonoTests.System.Data.SqlClient
                        cmd.CommandText = "select id1 from numeric_family";
                        try {
                                adapter.Fill (data);
-                       }catch (Exception e) {
+                       } catch {
                                if (cmd.Connection.State == ConnectionState.Open) {
                                        cmd.Connection.Close ();
                                        Assert.Fail ("# Connection Shud be Closed");
@@ -201,16 +423,17 @@ namespace MonoTests.System.Data.SqlClient
                }
 
                [Test]
+               [Category("NotWorking")]
                public void Fill_Test_Data ()
                {
                        //Check if a table is created for each resultset 
                        String batchQuery = "Select id,type_bit,type_int from numeric_family;";
-                       batchQuery += "Select type_bit,type_bigint from numeric_family";
+                       batchQuery += "Select type_bit from numeric_family";
                        adapter = new SqlDataAdapter (batchQuery, connectionString);
                        data = new DataSet ("test1");
                        adapter.Fill (data);
                        Assert.AreEqual (2, data.Tables.Count,"#1 2 Table shud be created");
-                               
+
                        //Check if Table and Col are named correctly for unnamed columns 
                        string query = "Select 10,20 from numeric_family;" ;
                        query += "Select 10,20 from numeric_family";
@@ -303,7 +526,7 @@ namespace MonoTests.System.Data.SqlClient
 
                        // Test if rows are appended  and not merged 
                        // when primary key is not returned in the result-set
-                       string query = "Select type_int,type_bigint from numeric_family";
+                       string query = "Select type_int from numeric_family";
                        adapter.SelectCommand.CommandText = query;
                        data = new DataSet ("test2");
                        adapter.Fill (data);
@@ -377,7 +600,7 @@ namespace MonoTests.System.Data.SqlClient
                        adapter.SelectCommand.Connection.Close (); 
 
                        adapter.SelectCommand.Connection = null; 
-                       try { 
+                       try {
                                adapter.Fill (data);
                                Assert.Fail ("#9 Exception shud be thrown : Invalid Connection");
                        }catch (AssertionException e){
@@ -388,6 +611,73 @@ namespace MonoTests.System.Data.SqlClient
                        }
                }
 
+               bool FillErrorContinue = false;
+               [Test]
+               public void Fill_Test_FillErrorTest ()
+               {
+                       string query = "select type_int from numeric_family where id=1 or id=4 ";
+
+                       DataSet ds = new DataSet ();
+                       DataTable table = ds.Tables.Add ("test");
+                       table.Columns.Add ("col", typeof (short));
+
+                       adapter = new SqlDataAdapter (query, connectionString);
+                       DataTableMapping mapping = adapter.TableMappings.Add ("numeric_family", "test");
+                       mapping.ColumnMappings.Add ("type_int", "col");
+
+                       try {
+                               adapter.Fill (ds, "numeric_family");
+                               Assert.Fail ("#A1");
+                       } catch (OverflowException) {
+                       } catch (ArgumentException ex) {
+                               // System.OverflowException: Value was either too large or too
+                               // small for an Int16
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                               Assert.IsNotNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNull (ex.ParamName, "#A5");
+
+                               OverflowException inner = ex.InnerException as OverflowException;
+                               Assert.IsNotNull (inner, "#A6");
+                               Assert.AreEqual (typeof (OverflowException), inner.GetType (), "#A7");
+                               Assert.IsNull (inner.InnerException, "#A8");
+                               Assert.IsNotNull (inner.Message, "#A9");
+                       }
+                       Assert.AreEqual (0, ds.Tables [0].Rows.Count, "#A10");
+
+                       adapter.FillError += new FillErrorEventHandler (ErrorHandler);
+                       FillErrorContinue = false;
+                       try {
+                               adapter.Fill (ds, "numeric_family");
+                               Assert.Fail ("#B1");
+                       } catch (OverflowException) {
+                       } catch (ArgumentException ex) {
+                               // System.OverflowException: Value was either too large or too
+                               // small for an Int16
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNotNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+
+                               OverflowException inner = ex.InnerException as OverflowException;
+                               Assert.IsNotNull (inner, "#B6");
+                               Assert.AreEqual (typeof (OverflowException), inner.GetType (), "#B7");
+                               Assert.IsNull (inner.InnerException, "#B8");
+                               Assert.IsNotNull (inner.Message, "#B9");
+                       }
+                       Assert.AreEqual (0, ds.Tables [0].Rows.Count, "#B10");
+
+                       FillErrorContinue = true;
+                       int count = adapter.Fill (ds, "numeric_family");
+                       Assert.AreEqual (1, ds.Tables [0].Rows.Count, "#C1");
+                       Assert.AreEqual (1, count, "#C2");
+               }
+
+               void ErrorHandler (object sender, FillErrorEventArgs args)
+               {
+                       args.Continue = FillErrorContinue;
+               }
+
                [Test]
                public void GetFillParametersTest ()
                {
@@ -409,7 +699,7 @@ namespace MonoTests.System.Data.SqlClient
                [Test]
                public void FillSchemaTest ()
                {
-                       string query = "";      
+                       string query;
 
                        // Test if connection is closed if excepton occurs during fill schema 
                        query = "select * from invalid_table"; 
@@ -417,9 +707,8 @@ namespace MonoTests.System.Data.SqlClient
                        data = new DataSet ("test");
                        try {
                                adapter.FillSchema (data , SchemaType.Source);
-                       }catch (Exception e){
-                               if ( adapter.SelectCommand.Connection.State != ConnectionState.Closed)
-                               {
+                       } catch {
+                               if (adapter.SelectCommand.Connection.State != ConnectionState.Closed) {
                                        Assert.Fail ("#0 Conn shud be closed if exception occurs");
                                        adapter.SelectCommand.Connection.Close();
                                }
@@ -494,11 +783,12 @@ namespace MonoTests.System.Data.SqlClient
                                Console.WriteLine ("Table == {0}",tab.TableName);
                                foreach (DataColumn col in tab.Columns)
                                        Console.WriteLine (" Col = {0} " , col.ColumnName);
-                       }                       
+                       }
                        */
                }
 
                [Test]
+               [Category("NotWorking")]
                public void MissingSchemaActionTest ()
                {
                        adapter = new SqlDataAdapter (
@@ -530,24 +820,19 @@ namespace MonoTests.System.Data.SqlClient
                        try {
                                adapter.Fill (data);
                                Assert.Fail ("#8 Exception shud be thrown: Schema Mismatch");
-                       }catch (AssertionException e) {
-                               throw e;
-                       }catch (Exception e){
-                               Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
-                                       "#9 Incorrect Exception : "+e); 
+                       } catch (InvalidOperationException ex) {
+                               Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(),
+                                       "#9");
                        }
-               
-                       // Test for invalid MissingSchema Value         
+
+                       // Test for invalid MissingSchema Value
                        try {
                                adapter.MissingSchemaAction = (MissingSchemaAction)(-5000);
                                Assert.Fail ("#10 Exception shud be thrown: Invalid Value");
-                       }catch (AssertionException e){
-                               throw e;
-                       }catch (Exception e){
-                               Assert.AreEqual (typeof(ArgumentException), e.GetType(),
-                                       "#11 Incorrect Exception : " +e);
+                       } catch (ArgumentOutOfRangeException ex) {
+                               Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#11");
                        }
-                       
+
                        // Tests if Data is filled correctly if schema is defined 
                        // manually and MissingSchemaAction.Error is set 
                        adapter.MissingSchemaAction = MissingSchemaAction.Error;
@@ -556,16 +841,13 @@ namespace MonoTests.System.Data.SqlClient
                        table.Columns.Add ("id");
                        table.Columns.Add ("type_bit");
                        table.Columns.Add ("type_int");
-                       try {
-                               adapter.Fill (data);
-                               Assert.AreEqual (1, data.Tables.Count, "#12");
-                               Assert.AreEqual (4, data.Tables[0].Rows.Count, "#13");
-                       }catch (Exception e) {
-                               Assert.Fail ("#12 Unexpected Exception : " + e);
-                       }
+                       adapter.Fill (data);
+                       Assert.AreEqual (1, data.Tables.Count, "#12");
+                       Assert.AreEqual (4, data.Tables[0].Rows.Count, "#13");
                }
                
                [Test]
+               [Category("NotWorking")]
                public void MissingMappingActionTest ()
                {
                        adapter = new SqlDataAdapter ("select id,type_bit from numeric_family where id=1",
@@ -590,23 +872,19 @@ namespace MonoTests.System.Data.SqlClient
                        try {
                                adapter.Fill (data);
                                Assert.Fail ("#5 Exception shud be thrown : Mapping is missing");
-                       }catch (AssertionException e){
-                               throw e;
-                       }catch (Exception e) {
-                               Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
-                                       "#6 Incorrect Exception : " + e);
+                       } catch (InvalidOperationException ex) {
+                               Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(),
+                                       "#6");
                        }
 
                        try {
                                adapter.MissingMappingAction = (MissingMappingAction)(-5000);
                                Assert.Fail ("#7 Exception shud be thrown : Invalid Value");
-                       }catch (AssertionException e){
-                               throw e;
-                       }catch (Exception e){
-                               Assert.AreEqual (typeof(ArgumentException), e.GetType(),
-                                       "#8 Incorrect Exception : " +e); 
+                       } catch (ArgumentOutOfRangeException ex) {
+                               Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (),
+                                       "#8");
                        }
-               
+
                        // Test if mapping the column and table names works correctly   
                        adapter.MissingMappingAction = MissingMappingAction.Error;
                        data.Reset ();
@@ -628,12 +906,10 @@ namespace MonoTests.System.Data.SqlClient
                                "#10 Data shud be populated if mapping is correct");
                }
 
-               // Test case for bug #76433 
-               [Test]
+               [Test] // bug #76433
                public void FillSchema_ValuesTest()
                {
-                       SqlConnection conn = new SqlConnection(connectionString);
-                       using (conn) {
+                       using (SqlConnection conn = new SqlConnection(connectionString)) {
                                conn.Open();
                                IDbCommand command = conn.CreateCommand();
 
@@ -647,15 +923,199 @@ namespace MonoTests.System.Data.SqlClient
                                DataSet dataSet = new DataSet();
                                string selectString = "SELECT * FROM #tmp_TestTable";
                                IDbDataAdapter dataAdapter = new SqlDataAdapter (
-                                                                       selectString,conn);
+                                                                       selectString, conn);
                                dataAdapter.FillSchema(dataSet, SchemaType.Mapped);
 
                                Assert.AreEqual (1, dataSet.Tables.Count, "#1");
-
-                               DataColumn col = dataSet.Tables[0].Columns[0]; 
                                Assert.IsFalse (dataSet.Tables[0].Columns[0].AllowDBNull,"#2");
                                Assert.IsTrue (dataSet.Tables[0].Columns[1].AllowDBNull,"#3");
                        }
                }
+
+               [Test]
+               public void Fill_CheckSchema ()
+               {
+                       using (SqlConnection conn = new SqlConnection(connectionString)) {
+                               conn.Open();
+
+                               IDbCommand command = conn.CreateCommand();
+
+                               // Create Temp Table
+                               String cmd = "Create Table #tmp_TestTable (" ;
+                               cmd += "id int primary key,";
+                               cmd += "field int not null)";
+                               command.CommandText = cmd; 
+                               command.ExecuteNonQuery();
+
+                               DataSet dataSet = new DataSet();
+                               string selectString = "SELECT * from #tmp_TestTable";
+                               IDbDataAdapter dataAdapter = new SqlDataAdapter (
+                                                                       selectString,conn);
+                               dataAdapter.Fill (dataSet);
+                               Assert.AreEqual (1, dataSet.Tables.Count, "#A1");
+                               Assert.AreEqual (2, dataSet.Tables [0].Columns.Count, "#A2");
+                               Assert.IsTrue (dataSet.Tables [0].Columns [1].AllowDBNull, "#A3");
+                               Assert.AreEqual (0, dataSet.Tables [0].PrimaryKey.Length, "#A4");
+
+                               dataSet.Reset ();
+                               dataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
+                               dataAdapter.Fill (dataSet);
+                               Assert.AreEqual (1, dataSet.Tables.Count, "#B1");
+                               Assert.AreEqual (2, dataSet.Tables [0].Columns.Count, "#B2");
+                               Assert.IsFalse (dataSet.Tables [0].Columns [1].AllowDBNull, "#B3");
+                               if (ClientVersion == 7)
+                                       Assert.AreEqual (0, dataSet.Tables [0].PrimaryKey.Length, "#B4");
+                               else
+                                       Assert.AreEqual (1, dataSet.Tables [0].PrimaryKey.Length, "#B4");
+                       }
+               }
+
+               [Test]
+               public void FillSchema_CheckSchema ()
+               {
+                       using (SqlConnection conn = new SqlConnection(connectionString)) {
+                               conn.Open();
+
+                               IDbCommand command = conn.CreateCommand();
+
+                               // Create Temp Table
+                               String cmd = "Create Table #tmp_TestTable (" ;
+                               cmd += "id int primary key,";
+                               cmd += "field int not null)";
+                               command.CommandText = cmd; 
+                               command.ExecuteNonQuery();
+
+                               DataSet dataSet = new DataSet();
+                               string selectString = "SELECT * from #tmp_TestTable";
+                               IDbDataAdapter dataAdapter = new SqlDataAdapter (
+                                                                       selectString,conn);
+
+                               dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
+                               Assert.IsFalse (dataSet.Tables[0].Columns[1].AllowDBNull, "#1");
+
+                               dataSet.Reset ();
+                               dataAdapter.MissingSchemaAction = MissingSchemaAction.Add;
+                               dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
+                               Assert.IsFalse (dataSet.Tables[0].Columns[1].AllowDBNull, "#2");
+
+                               dataSet.Reset ();
+                               dataAdapter.MissingSchemaAction = MissingSchemaAction.Ignore;
+                               dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
+                               Assert.AreEqual (0, dataSet.Tables.Count, "#3");
+
+                               dataSet.Reset ();
+                               dataAdapter.MissingSchemaAction = MissingSchemaAction.Error;
+                               try {
+                                       dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
+                                       Assert.Fail ("#4 Error should be thrown");
+                               } catch (InvalidOperationException ex) {
+                                       Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#4");
+                               }
+                       }
+               }
+
+               [Test]
+               [Ignore("TODO: Set SSPI Connection String")]
+               public void CreateViewSSPITest ()
+               {
+                       var conn = ConnectionManager.Instance.Sql.Connection;
+
+                       string sql = "create view MONO_TEST_VIEW as select * from Numeric_family";
+
+                       SqlCommand dbcmd = new SqlCommand( sql, conn );
+                       dbcmd.ExecuteNonQuery();
+
+                       sql = "drop view MONO_TEST_VIEW";
+
+                       dbcmd = new SqlCommand( sql, conn );
+                       dbcmd.ExecuteNonQuery();
+
+                       conn.Close();
+               }
+
+               [Test]
+               public void Fill_RelatedTables ()
+               {
+                       SqlConnection conn = new SqlConnection(connectionString);
+                       using (conn) {
+                               conn.Open();
+                               IDbCommand command = conn.CreateCommand();
+
+                               DataSet dataSet = new DataSet();
+                               string selectString = "SELECT id, type_int from numeric_family where id < 3";
+                               DbDataAdapter dataAdapter = new SqlDataAdapter (selectString,conn);
+
+                               DataTable table2 = dataSet.Tables.Add ("table2");
+                               DataColumn ccol1 = table2.Columns.Add ("id", typeof (int));
+                               DataColumn ccol2 = table2.Columns.Add ("type_int", typeof (int));
+
+                               DataTable table1 = dataSet.Tables.Add ("table1");
+                               DataColumn pcol1 = table1.Columns.Add ("id", typeof (int));
+                               DataColumn pcol2 = table1.Columns.Add ("type_int", typeof (int));
+
+                               table2.Constraints.Add ("fk", pcol1, ccol1);
+                               //table1.Constraints.Add ("fk1", pcol2, ccol2);
+
+                               dataSet.EnforceConstraints = false;
+                               dataAdapter.Fill (dataSet, "table1");
+                               dataAdapter.Fill (dataSet, "table2");
+
+                               //Should not throw an exception
+                               dataSet.EnforceConstraints = true;
+
+                               Assert.AreEqual (2, table1.Rows.Count, "#1");
+                               Assert.AreEqual (2, table2.Rows.Count, "#2");
+                       }
+               }
+
+               [Test]
+               public void UpdateBatchSizeTest ()
+               {
+                       adapter = new SqlDataAdapter();
+                       Assert.AreEqual (1, adapter.UpdateBatchSize, "#1 The default value should be 1");
+                       adapter.UpdateBatchSize = 3;
+                       Assert.AreEqual (3, adapter.UpdateBatchSize, "#2 The value should be 3 after setting the property UpdateBatchSize to 3");
+               }
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void UpdateBatchSizeArgumentOutOfRangeTest ()
+               {
+                       adapter = new SqlDataAdapter();
+                       adapter.UpdateBatchSize = -2;
+               }
+
+               int ClientVersion {
+                       get {
+                               return (engine.ClientVersion);
+                       }
+               }
+       }
+
+       [TestFixture]
+       [Category ("sqlserver")]
+       public class SqlDataAdapterInheritTest : DbDataAdapter
+       {
+               SqlConnection conn = null;
+
+               [Test]
+               public void FillDataAdapterTest ()
+               {
+                       conn = ConnectionManager.Instance.Sql.Connection;
+                       try
+                       {
+                               DataTable dt = new DataTable();
+                               SqlCommand command = new SqlCommand ();
+                               command.CommandText = "Select * from employee;";
+                               command.Connection = conn;
+                               SelectCommand = command;
+                               Fill (dt, command.ExecuteReader ());
+                               Assert.AreEqual (4, dt.Rows.Count, "#1");
+                               Assert.AreEqual (6, dt.Columns.Count, "#2");
+                       } finally {
+                               DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+                               ConnectionManager.Instance.Sql.CloseConnection ();
+                       }
+               }
        }
 }