Merge pull request #4503 from BrzVlad/fix-appdomain-unload
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlDataAdapterTest.cs
1 //
2 // SqlDataAdapterTest.cs - NUnit Test Cases for testing the
3 //                          SqlDataAdapter class
4 // Author:
5 //      Umadevi S (sumadevi@novell.com)
6 //      Sureshkumar T (tsureshkumar@novell.com)
7 //      Senganal T (tsenganal@novell.com)
8 //
9 // Copyright (c) 2004 Novell Inc., and the individuals listed
10 // on the ChangeLog entries.
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Data;
34 using System.Data.Common;
35 using System.Data.SqlClient;
36 using System.Configuration;
37
38 using NUnit.Framework;
39
40 namespace MonoTests.System.Data.Connected.SqlClient
41 {
42         [TestFixture]
43         [Category ("sqlserver")]
44         public class SqlDataAdapterTest
45         {
46                 SqlDataAdapter adapter;
47                 SqlDataReader dr;
48                 DataSet data;
49                 string connectionString = ConnectionManager.Instance.Sql.ConnectionString;
50                 SqlConnection conn;
51                 EngineConfig engine;
52
53                 [SetUp]
54                 public void SetUp ()
55                 {
56                         engine = ConnectionManager.Instance.Sql.EngineConfig;
57                 }
58
59                 [TearDown]
60                 public void TearDown ()
61                 {
62                         if (adapter != null) {
63                                 adapter.Dispose ();
64                                 adapter = null;
65                         }
66
67                         if (dr != null) {
68                                 dr.Close ();
69                                 dr = null;
70                         }
71
72                         if (conn != null) {
73                                 conn.Close ();
74                                 conn = null;
75                         }
76                 }
77
78                 [Test]
79                 [Category("NotWorking")]
80                 public void Update_DeleteRow ()
81                 {
82                         conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
83                         conn.Open ();
84
85                         DataTable dt = new DataTable ();
86                         adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
87                         SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
88                         adapter.DeleteCommand = builder.GetDeleteCommand ();
89                         adapter.Fill (dt);
90
91                         DateTime now = DateTime.Now;
92
93                         DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
94                                 now.Minute, now.Second);
95
96                         DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
97                                 now.Minute, now.Second);
98                         dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
99
100                         try {
101                                 DataRow newRow = dt.NewRow ();
102                                 newRow ["id"] = 6002;
103                                 newRow ["fname"] = "boston";
104                                 newRow ["dob"] = dob;
105                                 newRow ["doj"] = doj;
106                                 newRow ["email"] = "mono@novell.com";
107                                 dt.Rows.Add (newRow);
108                                 adapter.Update (dt);
109
110                                 foreach (DataRow row in dt.Rows)
111                                         if (((int) row ["id"]) == 6002)
112                                                 row.Delete ();
113                                 adapter.Update (dt);
114
115                                 SqlCommand cmd = conn.CreateCommand ();
116                                 cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
117                                 dr = cmd.ExecuteReader ();
118                                 Assert.IsFalse (dr.Read ());
119                                 dr.Close ();
120                         } finally {
121                                 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
122                         }
123                 }
124
125                 [Test]
126                 [Category("NotWorking")]
127                 public void Update_InsertRow ()
128                 {
129                         conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
130                         conn.Open ();
131
132                         DataTable dt = new DataTable ();
133                         adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
134
135                         SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
136                         adapter.InsertCommand = builder.GetInsertCommand ();
137                         adapter.Fill (dt);
138
139                         DateTime now = DateTime.Now;
140
141                         DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
142                                 now.Minute, now.Second);
143
144                         DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
145                                 now.Minute, now.Second);
146                         dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
147
148                         try {
149                                 DataRow newRow = dt.NewRow ();
150                                 newRow ["id"] = 6002;
151                                 newRow ["fname"] = "boston";
152                                 newRow ["dob"] = dob;
153                                 newRow ["doj"] = doj;
154                                 newRow ["email"] = "mono@novell.com";
155                                 dt.Rows.Add (newRow);
156                                 adapter.Update (dt);
157
158                                 SqlCommand cmd = conn.CreateCommand ();
159                                 cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
160                                 dr = cmd.ExecuteReader ();
161                                 Assert.IsTrue (dr.Read (), "#A1");
162                                 Assert.AreEqual (6002, dr.GetValue (0), "#A2");
163                                 Assert.AreEqual ("boston", dr.GetValue (1), "#A3");
164                                 Assert.AreEqual (DBNull.Value, dr.GetValue (2), "#A4");
165                                 Assert.AreEqual (dob, dr.GetValue (3), "#A5");
166                                 Assert.AreEqual (doj, dr.GetValue (4), "#A6");
167                                 Assert.AreEqual ("mono@novell.com", dr.GetValue (5), "#A7");
168                                 Assert.IsFalse (dr.Read (), "#A8");
169                                 dr.Close ();
170                         } finally {
171                                 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
172                         }
173                 }
174
175                 [Test]
176                 [Category("NotWorking")]
177                 public void Update_UpdateRow ()
178                 {
179                         conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
180                         conn.Open ();
181
182                         DataTable dt = new DataTable ();
183                         adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
184                         SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
185                         adapter.UpdateCommand = builder.GetUpdateCommand ();
186                         adapter.Fill (dt);
187
188                         DateTime now = DateTime.Now;
189
190                         DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
191                                 now.Minute, now.Second);
192
193                         DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
194                                 now.Minute, now.Second);
195                         dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
196
197                         try {
198                                 DataRow newRow = dt.NewRow ();
199                                 newRow ["id"] = 6002;
200                                 newRow ["fname"] = "boston";
201                                 newRow ["dob"] = dob;
202                                 newRow ["doj"] = doj;
203                                 newRow ["email"] = "mono@novell.com";
204                                 dt.Rows.Add (newRow);
205                                 adapter.Update (dt);
206
207                                 foreach (DataRow row in dt.Rows)
208                                         if (((int) row ["id"]) == 6002)
209                                                 row ["lname"] = "de Icaza";
210                                 adapter.Update (dt);
211
212                                 SqlCommand cmd = conn.CreateCommand ();
213                                 cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
214                                 dr = cmd.ExecuteReader ();
215                                 Assert.IsTrue (dr.Read (), "#A1");
216                                 Assert.AreEqual (6002, dr.GetValue (0), "#A2");
217                                 Assert.AreEqual ("boston", dr.GetValue (1), "#A3");
218                                 Assert.AreEqual ("de Icaza", dr.GetValue (2), "#A4");
219                                 Assert.AreEqual (dob, dr.GetValue (3), "#A5");
220                                 Assert.AreEqual (doj, dr.GetValue (4), "#A6");
221                                 Assert.AreEqual ("mono@novell.com", dr.GetValue (5), "#A7");
222                                 Assert.IsFalse (dr.Read (), "#A8");
223                                 dr.Close ();
224                         } finally {
225                                 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
226                         }
227                 }
228
229                 /**
230                    The below test will not run everytime, since the region id column is unique
231                    so change the regionid if you want the test to pass.
232                 **/
233                 /*
234                 [Test]
235                 public void UpdateTest () {
236                         conn = (SqlConnection) ConnectionManager.Singleton.Connection;
237                         try {
238                                 ConnectionManager.Singleton.OpenConnection ();
239                                 DataTable dt = new DataTable();
240                                 SqlDataAdapter da = null;
241                                 da = new SqlDataAdapter("Select * from employee", conn);
242                                 //SqlCommandBuilder cb = new SqlCommandBuilder (da);
243                                 da.Fill(dt);
244                                 DataRow dr = dt.NewRow();
245                                 dr ["id"] = 6002;
246                                 dr ["fname"] = "boston";
247                                 dr ["dob"] = DateTime.Now.Subtract (new TimeSpan (20*365, 0, 0, 0));
248                                 dr ["doj"] = DateTime.Now;
249                                 dt.Rows.Add(dr);
250
251                                 da.Update(dt);
252                         } finally {
253                                 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
254                                 ConnectionManager.Singleton.Sql.CloseConnection ();
255                         }
256                 }
257
258                 private static void OnRowUpdatedTest (object sender, SqlRowUpdatedEventArgs e)
259                 {
260                         rowUpdated = true;
261                 }
262
263                 private static void OnRowUpdatingTest (object sender, SqlRowUpdatingEventArgs e)
264                 {
265                         rowUpdating = true;
266                 }
267
268                 private static bool rowUpdated = false;
269                 private static bool rowUpdating = false;
270                 [Test]
271                 public void RowUpdatedTest () {
272                         conn = (SqlConnection) ConnectionManager.Singleton.Connection;
273                         try {
274                                 ConnectionManager.Singleton.OpenConnection ();
275                                 DataTable dt = null;
276                                 DataSet ds = new DataSet ();
277                                 SqlDataAdapter da = null;
278                                 da = new SqlDataAdapter("Select * from employee", conn);
279                                 //SqlCommandBuilder cb = new SqlCommandBuilder (da);
280                                 rowUpdated = false;
281                                 rowUpdating = false;
282                                 da.RowUpdated += new SqlRowUpdatedEventHandler (OnRowUpdatedTest);
283                                 da.RowUpdating += new SqlRowUpdatingEventHandler (OnRowUpdatingTest);
284                                 da.Fill (ds);
285                                 dt = ds.Tables [0];
286                                 dt.Rows[0][0] = 200;
287                                 da.UpdateCommand = new SqlCommand ("Update employee set id = @id");
288                                 da.Update (dt);
289                                 dt.Rows[0][0] = 1;
290                                 da.Update (dt);
291                                 da.RowUpdated -= new SqlRowUpdatedEventHandler (OnRowUpdatedTest);
292                                 da.RowUpdating -= new SqlRowUpdatingEventHandler (OnRowUpdatingTest);
293                                 Assert.AreEqual (true, rowUpdated, "RowUpdated");
294                                 Assert.AreEqual (true, rowUpdating, "RowUpdating");
295                         } finally {
296                                 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
297                                 ConnectionManager.Singleton.Sql.CloseConnection ();
298                         }
299                 }
300                 */
301
302                 /**
303                    This needs a errortable created as follows 
304                    id uniqueidentifier,name char(10) , with values
305                    Guid         name
306                    {A12...}     NULL
307                    NULL         bbbbbb
308                 **/
309                 [Test]
310                 public void NullGuidTest()
311                 {
312                         conn = ConnectionManager.Instance.Sql.Connection;
313                         try {
314                                 DBHelper.ExecuteNonQuery (conn, "create table #tmp_guid_table ( " +
315                                                           " id uniqueidentifier default newid (), " +
316                                                           " name char (10))");
317                                 DBHelper.ExecuteNonQuery (conn, "insert into #tmp_guid_table (name) values (null)");
318                                 DBHelper.ExecuteNonQuery (conn, "insert into #tmp_guid_table (id, name) values (null, 'bbbb')");
319                                 SqlDataAdapter da = new SqlDataAdapter("select * from #tmp_guid_table", conn);
320                                 DataSet ds = new DataSet();
321                                 da.Fill(ds);
322                                 Assert.AreEqual (1, ds.Tables.Count, "#1");
323                                 Assert.AreEqual (DBNull.Value, ds.Tables [0].Rows [1] ["id"], "#2");
324                         } finally {
325                                 ConnectionManager.Instance.Sql.CloseConnection ();
326                         }
327                         // the bug 68804 - is that the fill hangs!
328                         Assert.AreEqual("Done","Done");
329                 }
330
331                 [Test]
332                 public void DefaultConstructorTest ()
333                 {
334                         adapter = new SqlDataAdapter ();
335                         Assert.AreEqual (MissingMappingAction.Passthrough,
336                                 adapter.MissingMappingAction,
337                                 "#1 Missing Mapping acttion default to Passthrough");
338                         Assert.AreEqual (MissingSchemaAction.Add,
339                                 adapter.MissingSchemaAction,
340                                 "#2 Missing Schme action default to Add");
341                 }
342
343                 [Test]
344                 public void OverloadedConstructorsTest ()
345                 {
346                         SqlCommand selCmd = new SqlCommand ("Select * from numeric_family");
347                         adapter = new SqlDataAdapter (selCmd);
348                         Assert.AreEqual (MissingMappingAction.Passthrough,
349                                 adapter.MissingMappingAction,
350                                 "#1 Missing Mapping acttion default to Passthrough");
351                         Assert.AreEqual (MissingSchemaAction.Add,
352                                 adapter.MissingSchemaAction,
353                                 "#2 Missing Schme action default to Add");
354                         Assert.AreSame (selCmd, adapter.SelectCommand,
355                                 "#3 Select Command shud be a ref to the arg passed");
356                         
357                         conn = new SqlConnection (connectionString);
358                         String selStr = "Select * from numeric_family";
359                         adapter = new SqlDataAdapter (selStr, conn);
360                         Assert.AreEqual (MissingMappingAction.Passthrough,
361                                 adapter.MissingMappingAction,
362                                 "#4 Missing Mapping acttion default to Passthrough");
363                         Assert.AreEqual (MissingSchemaAction.Add,
364                                 adapter.MissingSchemaAction,
365                                 "#5 Missing Schme action default to Add");
366                         Assert.AreSame (selStr, adapter.SelectCommand.CommandText,
367                                 "#6 Select Command shud be a ref to the arg passed");
368                         Assert.AreSame (conn, adapter.SelectCommand.Connection,
369                                 "#7 cmd.connection shud be t ref to connection obj");
370
371                         selStr = "Select * from numeric_family";
372                         adapter = new SqlDataAdapter (selStr, connectionString);
373                         Assert.AreEqual (MissingMappingAction.Passthrough,
374                                 adapter.MissingMappingAction,
375                                 "#8 Missing Mapping action shud default to Passthrough");
376                         Assert.AreEqual (MissingSchemaAction.Add,
377                                 adapter.MissingSchemaAction,
378                                 "#9 Missing Schema action shud default to Add");
379                         Assert.AreSame (selStr,
380                                 adapter.SelectCommand.CommandText,
381                                 "#10");
382                         Assert.AreEqual (connectionString,
383                                 adapter.SelectCommand.Connection.ConnectionString,
384                                 "#11  ");
385                 }
386
387                 [Test]
388                 public void Fill_Test_ConnState ()
389                 {
390                         //Check if Connection State is maintained correctly .. 
391                         data = new DataSet ("test1");
392                         adapter = new SqlDataAdapter ("select id from numeric_family where id=1",
393                                          connectionString);
394                         SqlCommand cmd = adapter.SelectCommand ; 
395
396                         Assert.AreEqual (ConnectionState.Closed,
397                                 cmd.Connection.State, "#1 Connection shud be in closed state");
398                         adapter.Fill (data);
399                         Assert.AreEqual (1, data.Tables.Count, "#2 One table shud be populated");
400                         Assert.AreEqual (ConnectionState.Closed, cmd.Connection.State,
401                                 "#3 Connection shud be closed state");
402
403                         data = new DataSet ("test2");
404                         cmd.Connection.Open ();
405                         Assert.AreEqual (ConnectionState.Open, cmd.Connection.State,
406                                 "#3 Connection shud be open");
407                         adapter.Fill (data);
408                         Assert.AreEqual (1, data.Tables.Count, "#4 One table shud be populated");
409                         Assert.AreEqual (ConnectionState.Open, cmd.Connection.State,
410                                 "#5 Connection shud be open");
411                         cmd.Connection.Close ();
412  
413                         // Test if connection is closed when exception occurs
414                         cmd.CommandText = "select id1 from numeric_family";
415                         try {
416                                 adapter.Fill (data);
417                         } catch {
418                                 if (cmd.Connection.State == ConnectionState.Open) {
419                                         cmd.Connection.Close ();
420                                         Assert.Fail ("# Connection Shud be Closed");
421                                 }
422                         }
423                 }
424
425                 [Test]
426                 [Category("NotWorking")]
427                 public void Fill_Test_Data ()
428                 {
429                         //Check if a table is created for each resultset 
430                         String batchQuery = "Select id,type_bit,type_int from numeric_family;";
431                         batchQuery += "Select type_bit from numeric_family";
432                         adapter = new SqlDataAdapter (batchQuery, connectionString);
433                         data = new DataSet ("test1");
434                         adapter.Fill (data);
435                         Assert.AreEqual (2, data.Tables.Count,"#1 2 Table shud be created");
436
437                         //Check if Table and Col are named correctly for unnamed columns 
438                         string query = "Select 10,20 from numeric_family;" ;
439                         query += "Select 10,20 from numeric_family";
440                         adapter = new SqlDataAdapter (query, connectionString);
441                         data = new DataSet ("test2");
442                         adapter.Fill (data);
443                         Assert.AreEqual (2, data.Tables.Count,
444                                 "#2 2 Tables shud be created");
445                         Assert.AreEqual ("Table", data.Tables[0].TableName, "#3");
446                         Assert.AreEqual ("Table1", data.Tables[1].TableName, "#4");
447                         Assert.AreEqual ("Column1", data.Tables[0].Columns[0].ColumnName, "#5");
448                         Assert.AreEqual ("Column2", data.Tables[0].Columns[1].ColumnName, "#6");
449                         Assert.AreEqual ("Column1", data.Tables[1].Columns[0].ColumnName, "#7");
450                         Assert.AreEqual ("Column2", data.Tables[1].Columns[1].ColumnName, "#8");
451
452                         //Check if dup columns are named correctly
453                         query = "select A.id ,B.id , C.id from numeric_family A, ";
454                         query += "numeric_family B , numeric_family C";
455                         adapter = new SqlDataAdapter (query, connectionString);
456                         data = new DataSet ("test3");
457                         adapter.Fill (data);
458
459                         // NOTE msdotnet contradicts documented behavior
460                         // as per documentation the column names should be 
461                         // id1,id2,id3 .. but msdotnet returns id,id1,id2
462                         Assert.AreEqual ("id", data.Tables[0].Columns[0].ColumnName,
463                                 "#9 if colname is duplicated ,shud be col,col1,col2 etc");
464                         Assert.AreEqual ("id1", data.Tables[0].Columns[1].ColumnName,
465                                 "#10 if colname is duplicated ,shud be col,col1,col2 etc");
466                         Assert.AreEqual ("id2", data.Tables[0].Columns[2].ColumnName,
467                                 "#11 if colname is duplicated ,shud be col,col1,col2 etc");
468
469                         // Test if tables are created and named accordingly ,
470                         // but only for those queries returning result sets
471                         query = "update numeric_family set id=100 where id=50;";
472                         query += "select * from numeric_family";
473                         adapter = new SqlDataAdapter (query, connectionString); 
474                         data = new DataSet ("test4");
475                         adapter.Fill (data);
476                         Assert.AreEqual (1 ,data.Tables.Count,
477                                 "#12 Tables shud be named only for queries returning a resultset");
478                         Assert.AreEqual ("Table", data.Tables[0].TableName,
479                                 "#13 The first resutlset shud have 'Table' as its name");
480
481                         // Test behavior with an outerjoin
482                         query = "select A.id,B.type_bit from numeric_family A LEFT OUTER JOIN "; 
483                         query += "numeric_family B on A.id = B.type_bit"; 
484                         adapter = new SqlDataAdapter (query, connectionString);
485                         data = new DataSet ("test5");
486                         adapter.Fill (data);
487                         Assert.AreEqual (0, data.Tables[0].PrimaryKey.Length,
488                                 "#14 Primary Key shudnt be set if an outer join is performed");
489                         Assert.AreEqual (0, data.Tables[0].Constraints.Count,
490                                 "#15 Constraints shudnt be set if an outer join is performed");
491                         adapter = new SqlDataAdapter ("select id from numeric_family",
492                                         connectionString);
493                         data = new DataSet ("test6");
494                         adapter.Fill (data, 1, 1, "numeric_family");
495                         Assert.AreEqual (1, data.Tables[0].Rows.Count, "#16"); 
496                         Assert.AreEqual (2, data.Tables[0].Rows[0][0], "#17");
497
498                         // only one test for DataTable.. DataSet tests covers others  
499                         adapter = new SqlDataAdapter ("select id from numeric_family",
500                                         connectionString);
501                         DataTable table = new DataTable ("table1");
502                         adapter.Fill (table);
503                         Assert.AreEqual (4, table.Rows.Count , "#18");
504                 }
505                 
506                 [Test]
507                 public void Fill_Test_PriKey ()
508                 {             
509                         // Test if Primary Key & Constraints Collection is correct 
510                         adapter = new SqlDataAdapter ("select id,type_bit from numeric_family", 
511                                         connectionString);
512                         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
513                         data = new DataSet ("test1");
514                         adapter.Fill (data);
515                         Assert.AreEqual (1, data.Tables[0].PrimaryKey.Length,
516                                 "#1 Primary Key shud be set");
517                         Assert.AreEqual (1, data.Tables[0].Constraints.Count,
518                                 "#2 Constraints shud be set");
519                         Assert.AreEqual (4, data.Tables[0].Rows.Count,
520                                 "#3 No Of Rows shud be 4");
521                 
522                         // Test if data is correctly merged 
523                         adapter.Fill (data);
524                         Assert.AreEqual (4, data.Tables[0].Rows.Count,
525                                 "#4 No of Row shud still be 4");
526
527                         // Test if rows are appended  and not merged 
528                         // when primary key is not returned in the result-set
529                         string query = "Select type_int from numeric_family";
530                         adapter.SelectCommand.CommandText = query;
531                         data = new DataSet ("test2");
532                         adapter.Fill (data);
533                         Assert.AreEqual (4, data.Tables[0].Rows.Count,
534                                 "#5 No of Rows shud be 4");
535                         adapter.Fill (data);
536                         Assert.AreEqual (8, data.Tables[0].Rows.Count,
537                                 "#6 No of Rows shud double now");
538                 }
539         
540                 [Test]
541                 public void Fill_Test_Exceptions ()
542                 {
543                         adapter = new SqlDataAdapter ("select * from numeric_family",
544                                         connectionString);
545                         data = new DataSet ("test1");
546                         try {
547                                 adapter.Fill (data, -1, 0, "numeric_family");
548                                 Assert.Fail ("#1 Exception shud be thrown:Incorrect Arguments"); 
549                         }catch (AssertionException e){
550                                 throw e;
551                         }catch (Exception e){
552                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(),
553                                         "#2 Incorrect Exception : "  + e);
554                         }
555
556                         // conn is not closed due to a bug..
557                         // can be removed later 
558                         adapter.SelectCommand.Connection.Close (); 
559
560                         try {
561                                 adapter.Fill (data , 0 , -1 , "numeric_family");
562                                 Assert.Fail ("#3 Exception shud be thrown:Incorrect Arguments"); 
563                         }catch (AssertionException e){
564                                 throw e;
565                         }catch (Exception e){
566                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(),
567                                         "#4 Incorrect Exception : "  + e);
568                         }
569                         // conn is curr not closed.. can be removed later 
570                         adapter.SelectCommand.Connection.Close ();  
571
572                         /*
573                         // NOTE msdotnet contradicts documented behavior
574                         // InvalidOperationException is expected if table is not valid  
575                         try {
576                                 adapter.Fill (data , 0 , 0 , "invalid_talbe_name");
577                         }catch (InvalidOperationException e) {
578                                 ex= e;
579                         }catch (Exception e){
580                                 Assert.Fail ("#5 Exception shud be thrown : incorrect arugments ");
581                         }
582                         Assert.IsNotNull (ex , "#6 Exception shud be thrown : incorrect args ");
583                         adapter.SelectCommand.Connection.Close (); // tmp .. can be removed once the bug if fixed
584                         ex=null;
585                         */
586
587                         try {
588                                 adapter.Fill ( null , 0 , 0 , "numeric_family");
589                                 Assert.Fail ( "#7 Exception shud be thrown : Invalid Dataset");
590                         }catch (AssertionException e){
591                                 throw e ;
592                         }catch (ArgumentNullException) {
593                        
594                         }catch (Exception e) {
595                                 Assert.AreEqual (typeof(SystemException), e.GetType(),
596                                         "#8 Incorrect Exception : " + e);
597                         }
598                         // conn is currently not being closed.. 
599                         //need to be removed once behavior is fixed 
600                         adapter.SelectCommand.Connection.Close (); 
601
602                         adapter.SelectCommand.Connection = null; 
603                         try {
604                                 adapter.Fill (data);
605                                 Assert.Fail ("#9 Exception shud be thrown : Invalid Connection");
606                         }catch (AssertionException e){
607                                 throw e;
608                         }catch (Exception e){
609                                 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
610                                         "#10 Incorrect Exception : " + e);
611                         }
612                 }
613
614                 bool FillErrorContinue = false;
615                 [Test]
616                 public void Fill_Test_FillErrorTest ()
617                 {
618                         string query = "select type_int from numeric_family where id=1 or id=4 ";
619
620                         DataSet ds = new DataSet ();
621                         DataTable table = ds.Tables.Add ("test");
622                         table.Columns.Add ("col", typeof (short));
623
624                         adapter = new SqlDataAdapter (query, connectionString);
625                         DataTableMapping mapping = adapter.TableMappings.Add ("numeric_family", "test");
626                         mapping.ColumnMappings.Add ("type_int", "col");
627
628                         try {
629                                 adapter.Fill (ds, "numeric_family");
630                                 Assert.Fail ("#A1");
631                         } catch (OverflowException) {
632                         } catch (ArgumentException ex) {
633                                 // System.OverflowException: Value was either too large or too
634                                 // small for an Int16
635                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
636                                 Assert.IsNotNull (ex.InnerException, "#A3");
637                                 Assert.IsNotNull (ex.Message, "#A4");
638                                 Assert.IsNull (ex.ParamName, "#A5");
639
640                                 OverflowException inner = ex.InnerException as OverflowException;
641                                 Assert.IsNotNull (inner, "#A6");
642                                 Assert.AreEqual (typeof (OverflowException), inner.GetType (), "#A7");
643                                 Assert.IsNull (inner.InnerException, "#A8");
644                                 Assert.IsNotNull (inner.Message, "#A9");
645                         }
646                         Assert.AreEqual (0, ds.Tables [0].Rows.Count, "#A10");
647
648                         adapter.FillError += new FillErrorEventHandler (ErrorHandler);
649                         FillErrorContinue = false;
650                         try {
651                                 adapter.Fill (ds, "numeric_family");
652                                 Assert.Fail ("#B1");
653                         } catch (OverflowException) {
654                         } catch (ArgumentException ex) {
655                                 // System.OverflowException: Value was either too large or too
656                                 // small for an Int16
657                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
658                                 Assert.IsNotNull (ex.InnerException, "#B3");
659                                 Assert.IsNotNull (ex.Message, "#B4");
660                                 Assert.IsNull (ex.ParamName, "#B5");
661
662                                 OverflowException inner = ex.InnerException as OverflowException;
663                                 Assert.IsNotNull (inner, "#B6");
664                                 Assert.AreEqual (typeof (OverflowException), inner.GetType (), "#B7");
665                                 Assert.IsNull (inner.InnerException, "#B8");
666                                 Assert.IsNotNull (inner.Message, "#B9");
667                         }
668                         Assert.AreEqual (0, ds.Tables [0].Rows.Count, "#B10");
669
670                         FillErrorContinue = true;
671                         int count = adapter.Fill (ds, "numeric_family");
672                         Assert.AreEqual (1, ds.Tables [0].Rows.Count, "#C1");
673                         Assert.AreEqual (1, count, "#C2");
674                 }
675
676                 void ErrorHandler (object sender, FillErrorEventArgs args)
677                 {
678                         args.Continue = FillErrorContinue;
679                 }
680
681                 [Test]
682                 public void GetFillParametersTest ()
683                 {
684                         string query = "select id, type_bit from numeric_family where id > @param1";
685                         adapter = new SqlDataAdapter (query, connectionString);
686                         IDataParameter[] param = adapter.GetFillParameters ();
687                         Assert.AreEqual (0, param.Length, "#1 size shud be 0");
688                         
689                         SqlParameter param1 = new SqlParameter ();
690                         param1.ParameterName = "@param1";
691                         param1.Value = 2;
692                         adapter.SelectCommand.Parameters.Add (param1);
693                 
694                         param = adapter.GetFillParameters ();
695                         Assert.AreEqual (1, param.Length, "#2 count shud be 1");
696                         Assert.AreEqual (param1, param[0], "#3 Params shud be equal");
697                 }
698                 
699                 [Test]
700                 public void FillSchemaTest ()
701                 {
702                         string query;
703
704                         // Test if connection is closed if excepton occurs during fill schema 
705                         query = "select * from invalid_table"; 
706                         adapter = new SqlDataAdapter (query, connectionString);
707                         data = new DataSet ("test");
708                         try {
709                                 adapter.FillSchema (data , SchemaType.Source);
710                         } catch {
711                                 if (adapter.SelectCommand.Connection.State != ConnectionState.Closed) {
712                                         Assert.Fail ("#0 Conn shud be closed if exception occurs");
713                                         adapter.SelectCommand.Connection.Close();
714                                 }
715                         }
716                 
717                         // Test Primary Key is set (since primary key column returned)  
718                         query = "select id, type_int from numeric_family where id=1";   
719                         adapter = new SqlDataAdapter (query, connectionString);
720                         data = new DataSet ("test1");
721                         adapter.FillSchema (data , SchemaType.Source);
722
723                         Assert.AreEqual (1, data.Tables[0].PrimaryKey.Length,
724                                 "#1 Primary Key property must be set");
725         
726                         // Test Primary Key is not set (since primary key column is returned)   
727                         query = "select type_bit, type_int from numeric_family where id=1";     
728                         adapter = new SqlDataAdapter (query, connectionString);
729                         data = new DataSet ("test2");
730                         adapter.FillSchema (data, SchemaType.Source);
731                         Assert.AreEqual (0, data.Tables[0].PrimaryKey.Length,
732                                 "#2 Primary Key property should not be set");
733
734                         // Test multiple tables are created for a batch query
735                         query = "Select id ,type_bit from numeric_family;" ;
736                         query += "Select id,type_bit,type_int from numeric_family;"; 
737                         data = new DataSet ("test3");
738                         adapter = new SqlDataAdapter (query, connectionString);
739                         adapter.FillSchema (data , SchemaType.Source);
740                         Assert.AreEqual (2 , data.Tables.Count , "#3 A table shud be created for each Result Set");
741                         Assert.AreEqual (2 , data.Tables[0].Columns.Count , "#4 should have 2 columns");
742                         Assert.AreEqual (3 , data.Tables[1].Columns.Count , "#5 Should have 3 columns");
743
744                         // Test if table names and column names  are filled correctly
745                         query = "select 10,20 from numeric_family;" ;
746                         query += "select 10,20 from numeric_family;";
747                         adapter = new SqlDataAdapter (query, connectionString);
748                         data = new DataSet ("test4");
749                         try {
750                                 adapter.FillSchema (data , SchemaType.Source);
751                         }catch (Exception e){
752                                 Assert.Fail ("#3 Unexpected Exception : " + e); 
753                         }
754                         Assert.AreEqual ( "Table", data.Tables[0].TableName);
755                         Assert.AreEqual ( "Table1", data.Tables[1].TableName);
756                         Assert.AreEqual ( "Column1", data.Tables[0].Columns[0].ColumnName,
757                                 "#6 Unnamed col shud be named as 'ColumnN'");
758                         Assert.AreEqual ( "Column2", data.Tables[0].Columns[1].ColumnName,
759                                 "#7 Unnamed col shud be named as 'ColumnN'");
760                         Assert.AreEqual ( "Column1", data.Tables[1].Columns[0].ColumnName,
761                                 "#8 Unnamed col shud be named as 'ColumnN'");
762                         Assert.AreEqual ( "Column2", data.Tables[1].Columns[1].ColumnName,
763                                 "#9 Unnamed col shud be named as 'ColumnN'");
764                         Assert.AreEqual (ConnectionState.Closed, adapter.SelectCommand.Connection.State,
765                                 "#10 Connection shud be closed");
766                         
767                         // Test if mapping works correctly  
768                         // doesent work in both mono and msdotnet
769                         // gotto check if something is wrong 
770                         /*
771                         query = "select id,type_bit from numeric_family";  
772                         adapter = new SqlDataAdapter (query, connectionString);
773                         data = new DataSet ("test");
774                         DataTable table = data.Tables.Add ("numeric_family_1");
775                         table.Columns.Add ("id");
776                         table.Columns.Add ("type_bit");
777                         DataTableMapping map = adapter.TableMappings.Add("numeric_family_1",
778                                                         "numeric_family");
779                         map.ColumnMappings.Add ("id", "id_1");
780                         map.ColumnMappings.Add ("type_bit", "type_bit_1");
781                         adapter.FillSchema (data, SchemaType.Source, "numeric_family");
782                         foreach (DataTable tab in data.Tables){
783                                 Console.WriteLine ("Table == {0}",tab.TableName);
784                                 foreach (DataColumn col in tab.Columns)
785                                         Console.WriteLine (" Col = {0} " , col.ColumnName);
786                         }
787                         */
788                 }
789
790                 [Test]
791                 [Category("NotWorking")]
792                 public void MissingSchemaActionTest ()
793                 {
794                         adapter = new SqlDataAdapter (
795                                         "select id,type_bit,type_int from numeric_family where id<=4",
796                                          connectionString);
797                         data = new DataSet ();
798                         Assert.AreEqual (MissingSchemaAction.Add, adapter.MissingSchemaAction,
799                                          "#1 Default Value");
800
801                         adapter.Fill (data);
802                         Assert.AreEqual (1, data.Tables.Count , "#1 One table shud be populated");
803                         Assert.AreEqual (3, data.Tables[0].Columns.Count, "#2 Missing cols are added");
804                         Assert.AreEqual (0, data.Tables[0].PrimaryKey.Length, "#3 Default Value");
805
806                         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
807                         data.Reset();
808                         adapter.Fill (data);
809                         Assert.AreEqual (3, data.Tables[0].Columns.Count,
810                                 "#4 Missing cols are added");
811                         Assert.AreEqual (1, data.Tables[0].PrimaryKey.Length, "#5 Default Value");
812
813                         adapter.MissingSchemaAction = MissingSchemaAction.Ignore ;
814                         data.Reset ();
815                         adapter.Fill (data);
816                         Assert.AreEqual (0, data.Tables.Count, "#6 Data shud be ignored");
817                         
818                         adapter.MissingSchemaAction = MissingSchemaAction.Error ; 
819                         data.Reset();
820                         try {
821                                 adapter.Fill (data);
822                                 Assert.Fail ("#8 Exception shud be thrown: Schema Mismatch");
823                         } catch (InvalidOperationException ex) {
824                                 Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(),
825                                         "#9");
826                         }
827
828                         // Test for invalid MissingSchema Value
829                         try {
830                                 adapter.MissingSchemaAction = (MissingSchemaAction)(-5000);
831                                 Assert.Fail ("#10 Exception shud be thrown: Invalid Value");
832                         } catch (ArgumentOutOfRangeException ex) {
833                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#11");
834                         }
835
836                         // Tests if Data is filled correctly if schema is defined 
837                         // manually and MissingSchemaAction.Error is set 
838                         adapter.MissingSchemaAction = MissingSchemaAction.Error;
839                         data.Reset();
840                         DataTable table = data.Tables.Add ("Table");
841                         table.Columns.Add ("id");
842                         table.Columns.Add ("type_bit");
843                         table.Columns.Add ("type_int");
844                         adapter.Fill (data);
845                         Assert.AreEqual (1, data.Tables.Count, "#12");
846                         Assert.AreEqual (4, data.Tables[0].Rows.Count, "#13");
847                 }
848                 
849                 [Test]
850                 [Category("NotWorking")]
851                 public void MissingMappingActionTest ()
852                 {
853                         adapter = new SqlDataAdapter ("select id,type_bit from numeric_family where id=1",
854                                         connectionString);
855                         data = new DataSet ();
856                         Assert.AreEqual (adapter.MissingMappingAction,
857                                 MissingMappingAction.Passthrough,
858                                 "#1 Default Value");
859                         adapter.Fill(data);
860                         Assert.AreEqual (1, data.Tables.Count,
861                                 "#2 One Table shud be created");
862                         Assert.AreEqual (2, data.Tables[0].Columns.Count,
863                                 "#3 Two Cols shud be created");
864
865                         adapter.MissingMappingAction = MissingMappingAction.Ignore;
866                         data.Reset ();
867                         adapter.Fill (data);
868                         Assert.AreEqual (0, data.Tables.Count, "#4 No table shud be created");
869                         
870                         adapter.MissingMappingAction = MissingMappingAction.Error;
871                         data.Reset ();
872                         try {
873                                 adapter.Fill (data);
874                                 Assert.Fail ("#5 Exception shud be thrown : Mapping is missing");
875                         } catch (InvalidOperationException ex) {
876                                 Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(),
877                                         "#6");
878                         }
879
880                         try {
881                                 adapter.MissingMappingAction = (MissingMappingAction)(-5000);
882                                 Assert.Fail ("#7 Exception shud be thrown : Invalid Value");
883                         } catch (ArgumentOutOfRangeException ex) {
884                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (),
885                                         "#8");
886                         }
887
888                         // Test if mapping the column and table names works correctly   
889                         adapter.MissingMappingAction = MissingMappingAction.Error;
890                         data.Reset ();
891                         DataTable table = data.Tables.Add ("numeric_family_1");
892                         table.Columns.Add ("id_1");
893                         table.Columns.Add ("type_bit_1");
894                         table.Columns.Add ("type_int_1");
895                         DataTableMapping tableMap = adapter.TableMappings.Add ("numeric_family",
896                                                          "numeric_family_1");
897                         tableMap.ColumnMappings.Add ("id", "id_1");
898                         tableMap.ColumnMappings.Add ("type_bit", "type_bit_1");
899                         tableMap.ColumnMappings.Add ("type_int", "type_int_1");
900                         adapter.Fill (data,"numeric_family");
901                         Assert.AreEqual (1, data.Tables.Count ,
902                                 "#8 The DataTable shud be correctly mapped");
903                         Assert.AreEqual (3, data.Tables[0].Columns.Count,
904                                 "#9 The DataColumns shud be corectly mapped");
905                         Assert.AreEqual (1, data.Tables[0].Rows.Count,
906                                 "#10 Data shud be populated if mapping is correct");
907                 }
908
909                 [Test] // bug #76433
910                 public void FillSchema_ValuesTest()
911                 {
912                         using (SqlConnection conn = new SqlConnection(connectionString)) {
913                                 conn.Open();
914                                 IDbCommand command = conn.CreateCommand();
915
916                                 // Create Temp Table
917                                 String cmd = "Create Table #tmp_TestTable (" ;
918                                 cmd += "Field1 DECIMAL (10) NOT NULL,";
919                                 cmd += "Field2 DECIMAL(19))";
920                                 command.CommandText = cmd; 
921                                 command.ExecuteNonQuery();
922
923                                 DataSet dataSet = new DataSet();
924                                 string selectString = "SELECT * FROM #tmp_TestTable";
925                                 IDbDataAdapter dataAdapter = new SqlDataAdapter (
926                                                                         selectString, conn);
927                                 dataAdapter.FillSchema(dataSet, SchemaType.Mapped);
928
929                                 Assert.AreEqual (1, dataSet.Tables.Count, "#1");
930                                 Assert.IsFalse (dataSet.Tables[0].Columns[0].AllowDBNull,"#2");
931                                 Assert.IsTrue (dataSet.Tables[0].Columns[1].AllowDBNull,"#3");
932                         }
933                 }
934
935                 [Test]
936                 public void Fill_CheckSchema ()
937                 {
938                         using (SqlConnection conn = new SqlConnection(connectionString)) {
939                                 conn.Open();
940
941                                 IDbCommand command = conn.CreateCommand();
942
943                                 // Create Temp Table
944                                 String cmd = "Create Table #tmp_TestTable (" ;
945                                 cmd += "id int primary key,";
946                                 cmd += "field int not null)";
947                                 command.CommandText = cmd; 
948                                 command.ExecuteNonQuery();
949
950                                 DataSet dataSet = new DataSet();
951                                 string selectString = "SELECT * from #tmp_TestTable";
952                                 IDbDataAdapter dataAdapter = new SqlDataAdapter (
953                                                                         selectString,conn);
954                                 dataAdapter.Fill (dataSet);
955                                 Assert.AreEqual (1, dataSet.Tables.Count, "#A1");
956                                 Assert.AreEqual (2, dataSet.Tables [0].Columns.Count, "#A2");
957                                 Assert.IsTrue (dataSet.Tables [0].Columns [1].AllowDBNull, "#A3");
958                                 Assert.AreEqual (0, dataSet.Tables [0].PrimaryKey.Length, "#A4");
959
960                                 dataSet.Reset ();
961                                 dataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
962                                 dataAdapter.Fill (dataSet);
963                                 Assert.AreEqual (1, dataSet.Tables.Count, "#B1");
964                                 Assert.AreEqual (2, dataSet.Tables [0].Columns.Count, "#B2");
965                                 Assert.IsFalse (dataSet.Tables [0].Columns [1].AllowDBNull, "#B3");
966                                 if (ClientVersion == 7)
967                                         Assert.AreEqual (0, dataSet.Tables [0].PrimaryKey.Length, "#B4");
968                                 else
969                                         Assert.AreEqual (1, dataSet.Tables [0].PrimaryKey.Length, "#B4");
970                         }
971                 }
972
973                 [Test]
974                 public void FillSchema_CheckSchema ()
975                 {
976                         using (SqlConnection conn = new SqlConnection(connectionString)) {
977                                 conn.Open();
978
979                                 IDbCommand command = conn.CreateCommand();
980
981                                 // Create Temp Table
982                                 String cmd = "Create Table #tmp_TestTable (" ;
983                                 cmd += "id int primary key,";
984                                 cmd += "field int not null)";
985                                 command.CommandText = cmd; 
986                                 command.ExecuteNonQuery();
987
988                                 DataSet dataSet = new DataSet();
989                                 string selectString = "SELECT * from #tmp_TestTable";
990                                 IDbDataAdapter dataAdapter = new SqlDataAdapter (
991                                                                         selectString,conn);
992
993                                 dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
994                                 Assert.IsFalse (dataSet.Tables[0].Columns[1].AllowDBNull, "#1");
995
996                                 dataSet.Reset ();
997                                 dataAdapter.MissingSchemaAction = MissingSchemaAction.Add;
998                                 dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
999                                 Assert.IsFalse (dataSet.Tables[0].Columns[1].AllowDBNull, "#2");
1000
1001                                 dataSet.Reset ();
1002                                 dataAdapter.MissingSchemaAction = MissingSchemaAction.Ignore;
1003                                 dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
1004                                 Assert.AreEqual (0, dataSet.Tables.Count, "#3");
1005
1006                                 dataSet.Reset ();
1007                                 dataAdapter.MissingSchemaAction = MissingSchemaAction.Error;
1008                                 try {
1009                                         dataAdapter.FillSchema (dataSet, SchemaType.Mapped);
1010                                         Assert.Fail ("#4 Error should be thrown");
1011                                 } catch (InvalidOperationException ex) {
1012                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#4");
1013                                 }
1014                         }
1015                 }
1016
1017                 [Test]
1018                 [Ignore("TODO: Set SSPI Connection String")]
1019                 public void CreateViewSSPITest ()
1020                 {
1021                         var conn = ConnectionManager.Instance.Sql.Connection;
1022
1023                         string sql = "create view MONO_TEST_VIEW as select * from Numeric_family";
1024
1025                         SqlCommand dbcmd = new SqlCommand( sql, conn );
1026                         dbcmd.ExecuteNonQuery();
1027
1028                         sql = "drop view MONO_TEST_VIEW";
1029
1030                         dbcmd = new SqlCommand( sql, conn );
1031                         dbcmd.ExecuteNonQuery();
1032
1033                         conn.Close();
1034                 }
1035
1036                 [Test]
1037                 public void Fill_RelatedTables ()
1038                 {
1039                         SqlConnection conn = new SqlConnection(connectionString);
1040                         using (conn) {
1041                                 conn.Open();
1042                                 IDbCommand command = conn.CreateCommand();
1043
1044                                 DataSet dataSet = new DataSet();
1045                                 string selectString = "SELECT id, type_int from numeric_family where id < 3";
1046                                 DbDataAdapter dataAdapter = new SqlDataAdapter (selectString,conn);
1047
1048                                 DataTable table2 = dataSet.Tables.Add ("table2");
1049                                 DataColumn ccol1 = table2.Columns.Add ("id", typeof (int));
1050                                 DataColumn ccol2 = table2.Columns.Add ("type_int", typeof (int));
1051
1052                                 DataTable table1 = dataSet.Tables.Add ("table1");
1053                                 DataColumn pcol1 = table1.Columns.Add ("id", typeof (int));
1054                                 DataColumn pcol2 = table1.Columns.Add ("type_int", typeof (int));
1055
1056                                 table2.Constraints.Add ("fk", pcol1, ccol1);
1057                                 //table1.Constraints.Add ("fk1", pcol2, ccol2);
1058
1059                                 dataSet.EnforceConstraints = false;
1060                                 dataAdapter.Fill (dataSet, "table1");
1061                                 dataAdapter.Fill (dataSet, "table2");
1062
1063                                 //Should not throw an exception
1064                                 dataSet.EnforceConstraints = true;
1065
1066                                 Assert.AreEqual (2, table1.Rows.Count, "#1");
1067                                 Assert.AreEqual (2, table2.Rows.Count, "#2");
1068                         }
1069                 }
1070
1071                 [Test]
1072                 public void UpdateBatchSizeTest ()
1073                 {
1074                         adapter = new SqlDataAdapter();
1075                         Assert.AreEqual (1, adapter.UpdateBatchSize, "#1 The default value should be 1");
1076                         adapter.UpdateBatchSize = 3;
1077                         Assert.AreEqual (3, adapter.UpdateBatchSize, "#2 The value should be 3 after setting the property UpdateBatchSize to 3");
1078                 }
1079                 
1080                 [Test]
1081                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
1082                 public void UpdateBatchSizeArgumentOutOfRangeTest ()
1083                 {
1084                         adapter = new SqlDataAdapter();
1085                         adapter.UpdateBatchSize = -2;
1086                 }
1087
1088                 int ClientVersion {
1089                         get {
1090                                 return (engine.ClientVersion);
1091                         }
1092                 }
1093         }
1094
1095         [TestFixture]
1096         [Category ("sqlserver")]
1097         public class SqlDataAdapterInheritTest : DbDataAdapter
1098         {
1099                 SqlConnection conn = null;
1100
1101                 [Test]
1102                 public void FillDataAdapterTest ()
1103                 {
1104                         conn = ConnectionManager.Instance.Sql.Connection;
1105                         try
1106                         {
1107                                 DataTable dt = new DataTable();
1108                                 SqlCommand command = new SqlCommand ();
1109                                 command.CommandText = "Select * from employee;";
1110                                 command.Connection = conn;
1111                                 SelectCommand = command;
1112                                 Fill (dt, command.ExecuteReader ());
1113                                 Assert.AreEqual (4, dt.Rows.Count, "#1");
1114                                 Assert.AreEqual (6, dt.Columns.Count, "#2");
1115                         } finally {
1116                                 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1117                                 ConnectionManager.Instance.Sql.CloseConnection ();
1118                         }
1119                 }
1120         }
1121 }