New test.
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlConnectionTest.cs
1 //
2 // SqlDataAdapterTest.cs - NUnit Test Cases for testing the
3 //                          SqlDataAdapter class
4 // Author:
5 //      Senganal T (tsenganal@novell.com)
6 //
7 // Copyright (c) 2004 Novell Inc., and the individuals listed
8 // on the ChangeLog entries.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Data;
32 using System.Data.SqlClient;
33 using System.Net;
34 using NUnit.Framework;
35 using System.Collections;
36
37 namespace MonoTests.System.Data
38 {
39         [TestFixture]
40         [Category ("sqlserver")]
41         public class SqlConnectionTest
42         {
43                 SqlConnection conn = null ; 
44                 String connectionString = ConnectionManager.Singleton.ConnectionString;
45
46                 ArrayList invalidConnectionStrings = null;
47                 int stateChangeEventCount = 0;
48                 int disposedEventCount = 0;
49                 int infoMessageEventCount = 0;
50
51                 void populateTestData () 
52                 {
53                         invalidConnectionStrings = new ArrayList ();
54                         // shud be got from  a config file .. 
55                         //list of invalid and valid conn strings; 
56                         invalidConnectionStrings.Add ("InvalidConnectionString");
57                         invalidConnectionStrings.Add ("invalidKeyword=10");
58                         invalidConnectionStrings.Add ("Packet Size=511");
59                         invalidConnectionStrings.Add ("Packet Size=32768");
60                         invalidConnectionStrings.Add ("Connect Timeout=-1");                    
61                         invalidConnectionStrings.Add ("Max Pool Size=-1");
62                         invalidConnectionStrings.Add ("Min Pool Size=-1");                              
63                 }
64
65                 [SetUp]
66                 public void SetUp ()
67                 {
68                 }
69
70                 [TearDown]
71                 public void TearDown ()
72                 {
73                         if (conn != null)
74                                 conn.Dispose ();
75                 }
76
77                 [Test]
78                 public void DefaultConstructorTest ()
79                 {
80                         SqlConnection conn = new SqlConnection ();  
81                         Assert.AreEqual ("", conn.ConnectionString, 
82                                         "#1 Default Connection String should be empty");
83                         Assert.AreEqual (15, conn.ConnectionTimeout, 
84                                         "#2 Default ConnectionTimeout should be 15" ); 
85                         Assert.AreEqual ("", conn.Database, 
86                                         "#3 Default Database should be empty");
87                         Assert.AreEqual ("", conn.DataSource,
88                                         "#4 Default DataSource should be empty");
89                         Assert.AreEqual (8192, conn.PacketSize,"#5 Default Packet Size is 8192");
90                         Assert.AreEqual (Dns.GetHostName().ToUpper (), conn.WorkstationId.ToUpper (), 
91                                         "#6 Default Workstationid shud be hostname");
92                         Assert.AreEqual (ConnectionState.Closed, conn.State, 
93                                         "#7 Connection State shud be closed by default");
94                 }
95
96                 [Test]
97                 public void OverloadedConstructorTest ()
98                 {
99                         // Test Exceptions are thrown for Invalid Connection Strings
100                         int count=0 ;
101                         populateTestData ();
102                         foreach (String invalidConnString in invalidConnectionStrings) {
103                                 count++;
104                                 try {
105                                         conn = new SqlConnection ((string)invalidConnString);
106                                         Assert.Fail ("#1 Exception must be thrown");
107                                 }catch (AssertionException e) {
108                                         throw e; 
109                                 }catch (Exception e) {
110                                         Assert.AreEqual (typeof(ArgumentException), e.GetType(), 
111                                                 "Incorrect Exception" + e.StackTrace);
112                                 }
113                         }
114
115                         //check synonyms..
116                         //do i need to check for all the synonyms.. 
117                         conn = new SqlConnection (
118                                         "Timeout=10;Connect Timeout=20;Connection Timeout=30");
119                         Assert.AreEqual (30, conn.ConnectionTimeout,
120                                 "## The last set value shud be taken");
121                         conn = new SqlConnection (
122                                         "Connect Timeout=100;Connection Timeout=200;Timeout=300");
123                         Assert.AreEqual (300, conn.ConnectionTimeout,
124                                 "## The last set value shud be taken");
125                         conn = new SqlConnection (
126                                         "Connection Timeout=1000;Timeout=2000;Connect Timeout=3000");
127                         Assert.AreEqual (3000, conn.ConnectionTimeout,
128                                 "## The last set value shud be taken");
129
130                         // Test if properties are set correctly
131                         
132                         //'==' doesent work correctly in both msdotnet and mono
133                         /*
134                         conn = new SqlConnection ("server=local==host;database=tmp;");
135                         Assert.AreEqual ("local==host", conn.DataSource, 
136                                 "# Datasource name is set incorrectly");
137                         */
138                         string connStr = "Server='loca\"lhost';Database='''Db'; packet Size=\"512\";";
139                         connStr += "connect Timeout=20;Workstation Id=\"'\"\"desktop\";";
140                         conn = new SqlConnection (connStr);
141                         Assert.AreEqual (connStr , conn.ConnectionString , "#1");
142                         Assert.AreEqual ("loca\"lhost" , conn.DataSource , "#2");
143                         Assert.AreEqual ("'Db" , conn.Database , "#3");
144                         Assert.AreEqual (512 , conn.PacketSize , "#4");
145                         Assert.AreEqual (20 , conn.ConnectionTimeout , "#5");
146                         Assert.AreEqual ("'\"desktop" , conn.WorkstationId , "#6");
147                         Assert.AreEqual (ConnectionState.Closed , conn.State , "#7");
148                 }
149
150                 [Test]
151                 public void OpenTest ()
152                 {
153                         conn = new SqlConnection (connectionString);
154                         ArrayList validIncorrectConnStrings = new ArrayList();
155                         string validConnString = connectionString;
156
157                         validIncorrectConnStrings.Add (
158                                         validConnString+"user id=invalidLogin");
159                         validIncorrectConnStrings.Add (
160                                         validConnString+"database=invalidDB");
161                         validIncorrectConnStrings.Add (
162                                         validConnString+";password=invalidPassword");
163                         validIncorrectConnStrings.Add (
164                                         validConnString+";server=invalidServerName");
165
166                         int count=0;
167                         foreach (string connString in validIncorrectConnStrings) {
168                                 count++;
169                                 try {
170                                         conn.ConnectionString = connString;
171                                         conn.Open();
172                                         Assert.Fail (String.Format (
173                                                         "#1_{0} Incorrect Connection String",count));                           
174                                                 
175                                 }catch (AssertionException e) {
176                                         throw e;
177                                 }catch (Exception e) {
178                                         Assert.AreEqual (typeof (SqlException), e.GetType (),
179                                                 "#2 Incorrect Exception" + e.StackTrace);
180                                 }
181                         }
182                         
183                         // Test connection is Opened for a valid Connection String
184                         conn.ConnectionString = connectionString; 
185                         conn.Open ();
186                         Assert.AreEqual (ConnectionState.Open, conn.State,
187                                 "#3 Connection State Should be OPEN");
188
189                         // Test Exception is thrown on opening an OPEN Connection 
190                         try {
191                                 conn.Open ();
192                                 Assert.AreEqual (typeof (InvalidOperationException), null,
193                                         "#1 Connection is Already Open");
194                         }catch (AssertionException e) {
195                                 throw e;
196                         }catch (Exception e) {
197                                 Assert.AreEqual (typeof(InvalidOperationException), e.GetType (),
198                                          "#2 Incorect Exception."); 
199                         }
200                         conn.Close();                           
201
202                         /*
203                         // Test if localhost is assumed when servername is empty/missing
204                         // NOTE : msdotnet contradicts doc
205
206                         Assumes the server is localhost .. need to test this with mono on windows 
207                         conn.ConnectionString = connectionString + "server=;";
208                         try {
209                                 conn.Open ();
210                         }catch (Exception e) {
211                                 Assert.Fail ("## If server name is not given or empty ,localhost shud be tried");
212                         }
213                         ex = null; 
214                         conn.Close ();
215                          */
216                 }
217
218                 [Test]
219                 public void OpenTest_1 ()
220                 {
221                         SqlConnection conn  = new SqlConnection ();
222
223                         conn.ConnectionString = "";
224                         try {
225                                 conn.Open ();
226                                 Assert.Fail ("#1 Should throw ArgumentException and not SqlException");
227                         } catch (InvalidOperationException) {
228                         }
229
230                         conn.ConnectionString = "    ";
231                         try {
232                                 conn.Open ();
233                                 Assert.Fail ("#2 Should throw ArgumentException and not SqlException");
234                         } catch (InvalidOperationException) {
235                         }
236                 }
237
238                 [Test]
239                 public void CreateCommandTest ()
240                 {
241                         conn = new SqlConnection (connectionString);
242                         IDbCommand cmd = conn.CreateCommand ();
243                         Assert.AreSame (conn, cmd.Connection,
244                                 "#1 Connection instance should be the same");
245                 }
246
247                 [Test]
248                 public void CloseTest ()
249                 {       
250                         conn = new SqlConnection (connectionString);
251                         conn.Open ();
252                         Assert.AreEqual (ConnectionState.Open, conn.State,
253                                 "#1 Connection State should be : Open");
254                         conn.Close ();
255                         Assert.AreEqual (ConnectionState.Closed, conn.State,
256                                 "#1 Connection State Should : Closed");
257                         // Test Closing an already closed connection is Valid..
258                         conn.Close ();
259                 }
260
261                 [Test]
262                 public void DisposeTest ()
263                 {
264                         SqlConnection conn = new SqlConnection (connectionString);
265                         conn.Dispose ();
266                         Assert.AreEqual ("", conn.ConnectionString, 
267                                 "#1 Dispose shud make the Connection String empty");
268                         Assert.AreEqual (15, conn.ConnectionTimeout, 
269                                 "#2 Default ConnectionTimeout : 15" ); 
270                         Assert.AreEqual ("", conn.Database,
271                                 "#3 Default Database : empty");
272                         Assert.AreEqual ("", conn.DataSource, 
273                                 "#4 Default DataSource : empty");
274                         Assert.AreEqual (8192, conn.PacketSize, 
275                                 "#5 Default Packet Size : 8192");
276                         Assert.AreEqual (Dns.GetHostName().ToUpper (), conn.WorkstationId.ToUpper (), 
277                                 "#6 Default Workstationid : hostname");
278                         Assert.AreEqual (ConnectionState.Closed, conn.State, 
279                                 "#7 Default State : CLOSED ");
280
281                         conn = new SqlConnection ();
282                         //shud not throw exception
283                         conn.Dispose ();
284                 }
285
286                 [Test]
287                 public void ChangeDatabaseTest ()
288                 {
289                         conn = new SqlConnection (connectionString);
290                         String database = conn.Database;
291
292                         //Test if exception is thrown if connection is closed
293                         try {
294                                 conn.ChangeDatabase ("database");
295                                 Assert.AreEqual (typeof (InvalidOperationException), null,
296                                         "#1 Connection is Closed");
297                         }catch (AssertionException e){
298                                 throw e; 
299                         }catch (Exception e) {
300                                 Assert.AreEqual (typeof (InvalidOperationException), e.GetType(),
301                                         "#2 Incorrect Exception : " + e.StackTrace);
302                         }
303
304                         //Test if exception is thrown for invalid Database Names 
305                         //need to add more to the list 
306                         conn.Open ();
307                         String[] InvalidDatabaseNames = {"", null, "       "};
308                         for (int i = 0; i < InvalidDatabaseNames.Length ; ++i) {
309                                 try {
310                                         conn.ChangeDatabase (InvalidDatabaseNames[i]);
311                                         Assert.AreEqual (typeof (ArgumentException), null,
312                                                 string.Format ("#3_{0} Exception not thrown",i));
313                                 }catch (AssertionException e) {
314                                         throw e;
315                                 }catch (Exception e) {
316                                         Assert.AreEqual (typeof(ArgumentException), e.GetType (),
317                                                 string.Format( "#4_{0} Incorrect Exception : {1}",
318                                                         i, e.StackTrace));
319                                 }
320                                 Assert.AreEqual (database, conn.Database,
321                                         "#4 The Database shouldnt get changed if Operation Failed");
322                         }
323                         
324                         //Test if exception is thrown if database name is non-existent
325                         try {
326                                 conn.ChangeDatabase ("invalidDB");
327                                 Assert.Fail ("#5 Exception must be thrown if database doesent exist");
328                         }catch (AssertionException e) {
329                                 throw e;
330                         }catch (Exception e) {
331                                 Assert.AreEqual (typeof(SqlException), e.GetType (),
332                                         "#6 Incorrect Exception" + e.StackTrace);
333                         }
334                         conn.Close (); 
335
336                         //Test if '-' is a valid character in a database name
337                         //TODO : Check for database names that have more special Characters..
338                         conn.ConnectionString = connectionString;
339                         conn.Open ();
340                         try {
341                                 conn.ChangeDatabase ("mono-test");
342                                 Assert.AreEqual ("mono-test", conn.Database,
343                                         "#7 Database name should be mono-test");
344                         }catch (AssertionException e) {
345                                 throw e;
346                         }catch (Exception e){
347                                 Assert.Fail ("#8 Unexpected Exception : DB Name can have a '-' : "
348                                          + e);
349                         }
350                 }
351
352                 [Test]
353                 public void BeginTransactionTest()
354                 {
355                         conn = new SqlConnection (connectionString);
356                         SqlTransaction trans = null ;
357
358                         try {
359                                 trans = conn.BeginTransaction ();
360                                 Assert.Fail ("#1 Connection must be Open to Begin a Transaction");
361                         }catch (AssertionException e) {
362                                 throw e;
363                         }catch (Exception e) {
364                                 Assert.AreEqual (typeof (InvalidOperationException), e.GetType(),
365                                         "#2 Incorrect Exception" + e.StackTrace);
366                         }
367
368                         conn.Open ();
369                         trans = conn.BeginTransaction ();
370                         Assert.AreSame (conn, trans.Connection, 
371                                         "#3 Transaction should reference the same connection");
372                         Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel,
373                                         "#4 Isolation Level shud be ReadCommitted");
374                         trans.Rollback ();
375
376                         try {
377                                 trans = conn.BeginTransaction ();
378                                 trans = conn.BeginTransaction ();
379                                 conn.BeginTransaction ();
380                                 Assert.Fail ("#5 Parallel Transactions are not supported");
381                         }catch (AssertionException e) {
382                                 throw e;
383                         }catch (Exception e) {
384                                 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
385                                         "#6 Incorrect Exception" + e.StackTrace); 
386                         }finally {
387                                 trans.Rollback();
388                         }
389
390                         try {
391                                 trans = conn.BeginTransaction ();
392                                 trans.Rollback ();
393                                 trans = conn.BeginTransaction ();
394                                 trans.Commit();
395                                 trans = conn.BeginTransaction ();
396                         }catch (Exception e) {
397                                 Assert.Fail ("#7 Transaction can be opened after a rollback/commit");
398                         }finally {
399                                 trans.Rollback ();
400                         }
401                 }
402
403                 [Test]
404                 public void ConnectionStringPropertyTest ()
405                 {
406                         conn = new SqlConnection (connectionString) ;
407                         // Test Repeated Keyoword ..Should take the latest value 
408                         conn.ConnectionString = conn.ConnectionString + ";server=RepeatedServer;" ;
409                         Assert.AreEqual ("RepeatedServer", ((SqlConnection)conn).DataSource,
410                                         "#1 if keyword is repeated, the latest value should be taken");
411                         conn.ConnectionString += ";database=gen;Initial Catalog=gen1";
412                         Assert.AreEqual ("gen1", conn.Database,
413                                         "#2 database and initial catalog are synonyms .. ");
414
415                         // Test if properties are set correctly 
416                         string str = "server=localhost1;database=db;user id=user;";
417                         str += "password=pwd;Workstation ID=workstation;Packet Size=512;";
418                         str += "Connect Timeout=10";
419                         conn.ConnectionString = str;
420
421                         Assert.AreEqual ("localhost1", conn.DataSource,
422                                         "#3 DataSource name should be same as passed");
423                         Assert.AreEqual ("db", conn.Database,
424                                         "#4 Database name shud be same as passed");
425                         Assert.AreEqual (ConnectionState.Closed, conn.State,
426                                         "#5 Connection shud be in closed state");
427                         Assert.AreEqual ("workstation", conn.WorkstationId,
428                                         "#6 Workstation Id shud be same as passed");
429                         Assert.AreEqual (512, conn.PacketSize,
430                                         "#7 Packetsize shud be same as passed");
431                         Assert.AreEqual (10, conn.ConnectionTimeout,
432                                         "#8 ConnectionTimeout shud be same as passed");
433                         
434                         // Test if any leftover values exist from previous invocation. 
435                         conn.ConnectionString = connectionString;
436                         conn.ConnectionString = "";
437                         Assert.AreEqual ("", conn.DataSource,
438                                         "#9 Datasource shud be reset to Default : Empty");
439                         Assert.AreEqual ("", conn.Database, 
440                                         "#10 Database shud reset to Default : Empty");
441                         Assert.AreEqual (8192, conn.PacketSize, 
442                                         "#11 Packetsize shud be reset to Default : 8192");
443                         Assert.AreEqual (15, conn.ConnectionTimeout, 
444                                         "#12 ConnectionTimeour shud be reset to Default : 15");
445                         Assert.AreEqual (Dns.GetHostName ().ToUpper (), conn.WorkstationId.ToUpper (),
446                                         "#13 WorkstationId shud be reset to Default : Hostname");
447                         
448                         // Test Argument Exception is thrown for Invalid Connection Strings
449                         foreach (string connString in invalidConnectionStrings) {
450                                 try {
451                                         conn.ConnectionString = connString;
452                                         Assert.Fail (
453                                                 "#14 Exception should be thrown");
454                                 }catch (AssertionException e){
455                                         throw e;
456                                 }catch (Exception e) {
457                                         Assert.AreEqual (typeof (ArgumentException), e.GetType(),
458                                                 "#15 Incorrect Exception" + e.StackTrace);
459                                 }
460                         }
461
462                         // Test if ConnectionString is read-only when Connection is OPEN
463                         conn.ConnectionString = connectionString;
464                         conn.Open() ;
465                         try {
466                                 Assert.AreEqual (conn.State, ConnectionState.Open,
467                                                 "#16 Connection shud be open");
468                                 conn.ConnectionString =  "server=localhost;database=tmp;" ;
469                                 Assert.Fail (
470                                         "#17 ConnectionString should Read-Only when Connection is Open");
471                         }catch (AssertionException e){
472                                 throw e;
473                         }catch (Exception e) {
474                                 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
475                                         "#18 Incorrect Exception" + e.StackTrace); 
476                         }
477                         conn.Close ();
478                 }
479
480                 [Test]
481                 public void ServerVersionTest ()
482                 {       
483                         conn = new SqlConnection (connectionString);
484
485                         // Test InvalidOperation Exception is thrown if Connection is CLOSED
486                         try{
487                                 string s = conn.ServerVersion;
488                                 Assert.Fail (
489                                         "#1 InvalidOperation Exception Must be thrown if conn is closed");
490                         }catch (AssertionException e){
491                                 throw e;
492                         }catch (Exception e){
493                                 Assert.AreEqual(typeof (InvalidOperationException), e.GetType (),
494                                         "#2 Incorrect Exception" + e.StackTrace);
495                         }
496                         
497                         // Test if Release Version is as per specification.
498                         conn.Open ();
499                         String[] version = conn.ServerVersion.Split ('.') ;
500                         Assert.AreEqual (2, version[0].Length,
501                                 "#2 The Major release shud be exactly 2 characters");
502                         Assert.AreEqual (2, version[1].Length,
503                                 "#3 The Minor release shud be exactly 2 characters");
504                         Assert.AreEqual (4, version[2].Length,
505                                 "#4 The Release version should be exactly 4 digits");
506                 }
507
508                 [Test]
509                 public void DatabasePropertyTest ()
510                 {
511                         conn = new SqlConnection (connectionString);
512                         string database = conn.Database ;
513
514                         // Test if database property is updated when a query changes database
515                         conn.Open ();
516                         SqlCommand cmd = new SqlCommand ("use [mono-test]" , conn);
517                         cmd.ExecuteNonQuery ();
518                         Assert.AreEqual ("mono-test", conn.Database,
519                                 "#1 DATABASE name shud change if query changes the db");
520                         conn.Close ();
521                         Assert.AreEqual (database, conn.Database,
522                                 "#2 Shud be back to default value");
523
524                         // Test if the database property is reset on re-opening the connection
525                         conn.ConnectionString = connectionString;
526                         conn.Open ();   
527                         Assert.AreEqual (database, conn.Database,
528                                 "#3 Shud be back to original value");
529                         conn.Close ();
530                 }
531
532                 [Test]
533                 public void StateChangeEventTest () 
534                 {
535                         conn = new SqlConnection (connectionString);
536                         conn.StateChange += new StateChangeEventHandler (
537                                                         StateChangeHandlerTest1);
538                         using (conn) {
539                                 conn.Open ();
540                         }
541                         Assert.AreEqual (2, stateChangeEventCount,
542                                 "#1 The handler shud be called twice");
543                         stateChangeEventCount =0 ; 
544                         conn.StateChange -= new StateChangeEventHandler (
545                                                         StateChangeHandlerTest1);
546                         // NOTE : Need to check  the behavior if an exception is raised 
547                         // in a handler 
548                 }
549
550                 [Test]
551                 public void DisposedEventTest ()
552                 {
553                         conn = new SqlConnection (connectionString);
554                         conn.Disposed += new EventHandler (DisposedEventHandlerTest1);
555                         conn.Dispose ();
556                         Assert.AreEqual (1, disposedEventCount,
557                                  "#1 Disposed eventhandler shud be called");
558                 }
559
560                 void StateChangeHandlerTest1 (object sender , StateChangeEventArgs e)
561                 {
562                         Assert.IsTrue ((e.CurrentState != e.OriginalState),
563                                 "#1 Current and Original state shud be different");
564                         Assert.AreEqual (e.CurrentState, conn.State,
565                                 "The conn state and the arg received in event shud be same");
566                         stateChangeEventCount++ ;
567                 }
568
569                 void DisposedEventHandlerTest1 (object sender , EventArgs e)
570                 {
571                         disposedEventCount++; 
572                 }
573         }
574   #if NET_2_0
575         [TestFixture]
576         [Category ("sqlserver")]
577         public class GetSchemaTest
578         {
579                 SqlConnection conn = null;
580                 String connectionString = ConnectionManager.Singleton.ConnectionString;
581
582                 [SetUp]
583                 public void Setup()
584                 {
585                         conn = new SqlConnection(connectionString);
586                         conn.Open();
587                 }
588                 [TearDown]
589                 public void TearDown()
590                 {
591                         conn.Close();
592                 }
593                 [Test]
594                 public void GetSchemaTest1()
595                 {
596                         bool flag = false;
597                         DataTable tab1 = conn.GetSchema("databases");
598                         foreach (DataRow row in tab1.Rows)
599                         {
600                                 foreach (DataColumn col in tab1.Columns)
601                                 {
602                                         if (col.ColumnName.ToString() == "database_name" && row[col].ToString() == "monotest")
603                                         {
604                                                 flag = true;
605                                                 break;
606                                         }
607                                 }
608                                 if (flag)
609                                         break;
610                         }
611                         Assert.AreEqual(true, flag, "#GS1 failed");
612                 }
613                 [Test]
614                 [ExpectedException(typeof(ArgumentException))]
615                 public void GetSchemaTest2()
616                 {
617                         conn.GetSchema(null);
618                 }
619                 [Test]
620                 public void GetSchemaTest3()
621                 {
622                         bool flag = false;
623                         DataTable tab1 = conn.GetSchema("ForeignKeys");
624                         foreach (DataRow row in tab1.Rows)
625                         {
626                                 foreach (DataColumn col in tab1.Columns)
627                                 {
628                                         /*
629                                          * We need to consider multiple values
630                                          */
631                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "tmptable1")
632                                         {
633                                                 flag = true;
634                                                 break;
635                                         }
636                                 }
637                                 if (flag)
638                                         break;
639                         }
640                         Assert.AreEqual(true, flag, "#GS3 failed");
641                 }
642                 [Test]
643                 public void GetSchemaTest4()
644                 {
645                         bool flag = false;
646                         DataTable tab1 = conn.GetSchema("Indexes");
647                         foreach (DataRow row in tab1.Rows)
648                         {
649                                 foreach (DataColumn col in tab1.Columns)
650                                 {
651                                         /*
652                                          * We need to consider multiple values
653                                          */
654                                         if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
655                                         {
656                                                 flag = true;
657                                                 break;
658                                         }
659                                 }
660                                 if (flag)
661                                         break;
662                         }
663                         Assert.AreEqual(true, flag, "#GS4 failed");
664                 }
665                 [Test]
666                 public void GetSchemaTest5()
667                 {
668                         bool flag = false;
669                         DataTable tab1 = conn.GetSchema("IndexColumns");
670                         foreach (DataRow row in tab1.Rows)
671                         {
672                                 foreach (DataColumn col in tab1.Columns)
673                                 {
674                                         /*
675                                          * We need to consider multiple values
676                                          */
677                                         if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
678                                         {
679                                                 flag = true;
680                                                 break;
681                                         }
682                                 }
683                                 if (flag)
684                                         break;
685                         }
686                         Assert.AreEqual(true, flag, "#GS5 failed");
687                 }
688                 [Test]
689                 public void GetSchemaTest6()
690                 {
691                         bool flag = false;
692                         DataTable tab1 = conn.GetSchema("Procedures");
693                         foreach (DataRow row in tab1.Rows)
694                         {
695                                 foreach (DataColumn col in tab1.Columns)
696                                 {
697                                         /*
698                                          * We need to consider multiple values
699                                          */
700                                         if (col.ColumnName.ToString() == "SPECIFIC_NAME" && row[col].ToString() == "sp_get_age")
701                                         {
702                                                 flag = true;
703                                                 break;
704                                         }
705                                 }
706                                 if (flag)
707                                         break;
708                         }
709                         Assert.AreEqual(true, flag, "#GS6 failed");
710                 }
711                 [Test]
712                 public void GetSchemaTest7()
713                 {
714                         bool flag = false;
715                         DataTable tab1 = conn.GetSchema("ProcedureParameters");
716                         foreach (DataRow row in tab1.Rows)
717                         {
718                                 foreach (DataColumn col in tab1.Columns)
719                                 {
720                                         /*
721                                          * We need to consider multiple values
722                                          */
723                                         if (col.ColumnName.ToString() == "SPECIFIC_NAME" && row[col].ToString() == "sp_get_age")
724                                         {
725                                                 flag = true;
726                                                 break;
727                                         }
728                                 }
729                                 if (flag)
730                                         break;
731                         }
732                         Assert.AreEqual(true, flag, "#GS7 failed");
733                 }
734                 [Test]
735                 public void GetSchemaTest8()
736                 {
737                         bool flag = false;
738                         DataTable tab1 = conn.GetSchema("Tables");
739                         foreach (DataRow row in tab1.Rows)
740                         {
741                                 foreach (DataColumn col in tab1.Columns)
742                                 {
743                                         /*
744                                          * We need to consider multiple values
745                                          */
746                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
747                                         {
748                                                 flag = true;
749                                                 break;
750                                         }
751                                 }
752                                 if (flag)
753                                         break;
754                         }
755                         Assert.AreEqual(true, flag, "#GS8 failed");
756                 }
757                 [Test]
758                 public void GetSchemaTest9()
759                 {
760                         bool flag = false;
761                         DataTable tab1 = conn.GetSchema("Columns");
762                         foreach (DataRow row in tab1.Rows)
763                         {
764                                 foreach (DataColumn col in tab1.Columns)
765                                 {
766                                         /*
767                                          * We need to consider multiple values
768                                          */
769                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
770                                         {
771                                                 flag = true;
772                                                 break;
773                                         }
774                                 }
775                                 if (flag)
776                                         break;
777                         }
778                         Assert.AreEqual(true, flag, "#GS9 failed");
779                 }
780                 public void GetSchemaTest10()
781                 {
782                         bool flag = false;
783                         DataTable tab1 = conn.GetSchema("Users");
784                         foreach (DataRow row in tab1.Rows)
785                         {
786                                 foreach (DataColumn col in tab1.Columns)
787                                 {
788                                         /*
789                                          * We need to consider multiple values
790                                          */
791                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
792                                         {
793                                                 flag = true;
794                                                 break;
795                                         }
796                                 }
797                                 if (flag)
798                                         break;
799                         }
800                         Assert.AreEqual(true, flag, "#GS10 failed");
801                 }
802                 public void GetSchemaTest11()
803                 {
804                         bool flag = false;
805                         DataTable tab1 = conn.GetSchema("Views");
806                         flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
807                         foreach (DataRow row in tab1.Rows)
808                         {
809                                 foreach (DataColumn col in tab1.Columns)
810                                 {
811                                         /*
812                                          * We need to consider multiple values.
813                                          */
814                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
815                                         {
816                                                 flag = true;
817                                                 break;
818                                         }
819                                 }
820                                 if (flag)
821                                         break;
822                         }
823                         Assert.AreEqual(true, flag, "#GS11 failed");
824                 }
825                 public void GetSchemaTest12()
826                 {
827                         bool flag = false;
828                         DataTable tab1 = conn.GetSchema("ViewColumns");
829                         flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
830                         foreach (DataRow row in tab1.Rows)
831                         {
832                                 foreach (DataColumn col in tab1.Columns)
833                                 {
834                                         /*
835                                          * We need to consider multiple values.
836                                          */
837                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
838                                         {
839                                                 flag = true;
840                                                 break;
841                                         }
842                                 }
843                                 if (flag)
844                                         break;
845                         }
846                         Assert.AreEqual(true, flag, "#GS12 failed");
847                 }
848                 public void GetSchemaTest13()
849                 {
850                         bool flag = false;
851                         DataTable tab1 = conn.GetSchema("UserDefineTypes");
852                         flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
853                         foreach (DataRow row in tab1.Rows)
854                         {
855                                 foreach (DataColumn col in tab1.Columns)
856                                 {
857                                         /*
858                                          * We need to consider multiple values.
859                                          */
860                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
861                                         {
862                                                 flag = true;
863                                                 break;
864                                         }
865                                 }
866                                 if (flag)
867                                         break;
868                         }
869                         Assert.AreEqual(true, flag, "#GS13 failed");
870                 }
871                 [Test]
872                 public void GetSchemaTest14()
873                 {
874                         bool flag = false;
875                         string [] restrictions = new string[4];
876
877                         restrictions[0] = "monotest";
878                         restrictions[1] = "dbo";
879                         restrictions[2] = null;
880                         restrictions[3] = "BASE TABLE";
881                         DataTable tab1 = conn.GetSchema("Tables", restrictions);
882                         foreach (DataRow row in tab1.Rows)
883                         {
884                                 foreach (DataColumn col in tab1.Columns)
885                                 {
886                                         /*
887                                          * We need to consider multiple values
888                                          */
889                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
890                                         {
891                                                 flag = true;
892                                                 break;
893                                         }
894                                 }
895                                 if (flag)
896                                         break;
897                         }
898                         Assert.AreEqual(true, flag, "#GS14 failed");
899                 }
900                 [Test]
901                 public void GetSchemaTest15()
902                 {
903                         bool flag = false;
904                         string [] restrictions = new string[4];
905
906                         restrictions[0] = "monotest";
907                         restrictions[1] = null;
908                         restrictions[2] = "binary_family";
909                         restrictions[3] = null;
910                         DataTable tab1 = conn.GetSchema("IndexColumns", restrictions);
911                         foreach (DataRow row in tab1.Rows)
912                         {
913                                 foreach (DataColumn col in tab1.Columns)
914                                 {
915                                         /*
916                                          * We need to consider multiple values
917                                          */
918                                         if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
919                                         {
920                                                 flag = true;
921                                                 break;
922                                         }
923                                 }
924                                 if (flag)
925                                         break;
926                         }
927                         Assert.AreEqual(true, flag, "#GS15 failed");
928                 }
929                 [Test]
930                 public void GetSchemaTest16()
931                 {
932                         bool flag = false;
933                         string [] restrictions = new string[4];
934
935                         restrictions[0] = "monotest";
936                         restrictions[1] = null;
937                         restrictions[2] = "sp_get_age";
938                         restrictions[3] = null;
939                         DataTable tab1 = conn.GetSchema("Procedures", restrictions);
940                         foreach (DataRow row in tab1.Rows)
941                         {
942                                 foreach (DataColumn col in tab1.Columns)
943                                 {
944                                         /*
945                                          * We need to consider multiple values
946                                          */
947                                         if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "sp_get_age")
948                                         {
949                                                 flag = true;
950                                                 break;
951                                         }
952                                 }
953                                 if (flag)
954                                         break;
955                         }
956                         Assert.AreEqual(true, flag, "#GS16 failed");
957                 }
958                 [Test]
959                 public void GetSchemaTest17()
960                 {
961                         bool flag = false;
962                         DataTable tab1 = conn.GetSchema();
963                         foreach (DataRow row in tab1.Rows)
964                         {
965                                 foreach (DataColumn col in tab1.Columns)
966                                 {
967                                         /*
968                                          * We need to consider multiple values
969                                          */
970                                         if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
971                                         {
972                                                 flag = true;
973                                                 break;
974                                         }
975                                 }
976                                 if (flag)
977                                         break;
978                         }
979                         Assert.AreEqual(true, flag, "#GS17 failed");
980                 }
981                 [Test]
982                 public void GetSchemaTest18()
983                 {
984                         bool flag = false;
985                         DataTable tab1 = conn.GetSchema("RESTRICTIONS");
986                         foreach (DataRow row in tab1.Rows)
987                         {
988                                 foreach (DataColumn col in tab1.Columns)
989                                 {
990                                         /*
991                                          * We need to consider multiple values
992                                          */
993                                         if (col.ColumnName.ToString() == "RestrictionDefault" && row[col].ToString() == "CONSTRAINT_NAME")
994                                         {
995                                                 flag = true;
996                                                 break;
997                                         }
998                                 }
999                                 if (flag)
1000                                         break;
1001                         }
1002                         Assert.AreEqual(true, flag, "#GS18 failed");
1003                 }
1004                 [Test]
1005                 [ExpectedException(typeof(ArgumentException))]
1006                 public void GetSchemaTest19()
1007                 {
1008                         String [] restrictions = new String[1];
1009                         DataTable tab1 = conn.GetSchema("RESTRICTIONS", restrictions);
1010                 }
1011                 [Test]
1012                 public void GetSchemaTest20()
1013                 {
1014                         bool flag = false;
1015                         DataTable tab1 = conn.GetSchema("DataTypes");
1016                         foreach (DataRow row in tab1.Rows)
1017                         {
1018                                 foreach (DataColumn col in tab1.Columns)
1019                                 {
1020                                         /*
1021                                          * We need to consider multiple values
1022                                          */
1023                                         if (col.ColumnName.ToString() == "TypeName" && row[col].ToString() == "uniqueidentifier")
1024                                         {
1025                                                 flag = true;
1026                                                 break;
1027                                         }
1028                                 }
1029                                 if (flag)
1030                                         break;
1031                         }
1032                         Assert.AreEqual(true, flag, "#GS20 failed");
1033                 }
1034                 [Test]
1035                 public void GetSchemaTest21()
1036                 {
1037                         bool flag = false;
1038                         DataTable tab1 = conn.GetSchema();
1039                         foreach (DataRow row in tab1.Rows)
1040                         {
1041                                 foreach (DataColumn col in tab1.Columns)
1042                                 {
1043                                         /*
1044                                          * We need to consider multiple values
1045                                          */
1046                                         if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
1047                                         {
1048                                                 flag = true;
1049                                                 break;
1050                                         }
1051                                 }
1052                                 if (flag)
1053                                         break;
1054                         }
1055                         Assert.AreEqual(true, flag, "#GS21 failed");
1056                 }
1057                 [Test]
1058                 public void GetSchemaTest22()
1059                 {
1060                         bool flag = false;
1061                         DataTable tab1 = conn.GetSchema("ReservedWords");
1062                         foreach (DataRow row in tab1.Rows)
1063                         {
1064                                 foreach (DataColumn col in tab1.Columns)
1065                                 {
1066                                         /*
1067                                          * We need to consider multiple values
1068                                          */
1069                                         if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "UPPER")
1070                                         {
1071                                                 flag = true;
1072                                                 break;
1073                                         }
1074                                 }
1075                                 if (flag)
1076                                         break;
1077                         }
1078                         Assert.AreEqual(true, flag, "#GS22 failed");
1079                 }
1080                 [Test]
1081                 public void GetSchemaTest23()
1082                 {
1083                         bool flag = false;
1084                         DataTable tab1 = conn.GetSchema("ReservedWords");
1085                         foreach (DataRow row in tab1.Rows)
1086                         {
1087                                 foreach (DataColumn col in tab1.Columns)
1088                                 {
1089                                         /*
1090                                          * We need to consider multiple values
1091                                          */
1092                                         if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "upper")
1093                                         {
1094                                                 flag = true;
1095                                                 break;
1096                                         }
1097                                 }
1098                                 if (flag)
1099                                         break;
1100                         }
1101                         Assert.AreEqual(false, flag, "#GS23 failed");
1102                 }
1103                 [Test]
1104                 public void GetSchemaTest24()
1105                 {
1106                         bool flag = false;
1107                         string [] restrictions = new string[4];
1108
1109                         restrictions[0] = "monotest";
1110                         restrictions[1] = null;
1111                         restrictions[2] = "sp_get_age";
1112                         restrictions[3] = null;
1113                         DataTable tab1 = conn.GetSchema("Procedures", restrictions);
1114                         foreach (DataRow row in tab1.Rows)
1115                         {
1116                                 foreach (DataColumn col in tab1.Columns)
1117                                 {
1118                                         /*
1119                                          * We need to consider multiple values
1120                                          */
1121                                         if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "mono")
1122                                         {
1123                                                 flag = true;
1124                                                 break;
1125                                         }
1126                                 }
1127                                 if (flag)
1128                                         break;
1129                         }
1130                         Assert.AreEqual(false, flag, "#GS24 failed");
1131                 }
1132                 [Test]
1133                 [ExpectedException(typeof(ArgumentException))]
1134                 public void GetSchemaTest25()
1135                 {
1136                         String [] restrictions = new String[1];
1137                         DataTable tab1 = conn.GetSchema("Mono", restrictions);
1138                 }
1139         }
1140   #endif
1141 }