[runtime] Switch getenv to use heap memory
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlConnectionTest.cs
1 //
2 // SqlConnectionTest.cs - NUnit Test Cases for testing the
3 //                          SqlConnection 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.Collections;
32 using System.Data;
33 using System.Data.SqlClient;
34 using System.Net;
35 using System.Threading;
36
37 using NUnit.Framework;
38
39 namespace MonoTests.System.Data
40 {
41         [TestFixture]
42         [Category ("sqlserver")]
43         public class SqlConnectionTest
44         {
45                 SqlConnection conn;
46                 String connectionString;
47                 ArrayList events;
48                 EngineConfig engine;
49
50                 [SetUp]
51                 public void SetUp ()
52                 {
53                         events = new ArrayList ();
54                         connectionString = ConnectionManager.Singleton.ConnectionString;
55                         engine = ConnectionManager.Singleton.Engine;
56                 }
57
58                 [TearDown]
59                 public void TearDown ()
60                 {
61                         if (conn != null)
62                                 conn.Dispose ();
63                         SqlConnection.ClearAllPools ();
64                 }
65
66                 [Test]
67                 public void OverloadedConstructorTest ()
68                 {
69                         //check synonyms.
70                         //do i need to check for all the synonyms.. 
71                         conn = new SqlConnection ("Timeout=10;Connect Timeout=20;Connection Timeout=30");
72                         Assert.AreEqual (30, conn.ConnectionTimeout, "#A1");
73                         conn = new SqlConnection ("Connect Timeout=100;Connection Timeout=200;Timeout=300");
74                         Assert.AreEqual (300, conn.ConnectionTimeout, "#A2");
75                         conn = new SqlConnection ("Connection Timeout=1000;Timeout=2000;Connect Timeout=3000");
76                         Assert.AreEqual (3000, conn.ConnectionTimeout, "#A3");
77
78                         //'==' doesent work correctly in both msdotnet and mono
79                         /*
80                         conn = new SqlConnection ("server=local==host;database=tmp;");
81                         Assert.AreEqual ("local==host", conn.DataSource, 
82                                 "# Datasource name is set incorrectly");
83                         */
84                         string connStr = "Server='loca\"lhost';Database='''Db'; packet Size=\"512\";"
85                                 + "connect Timeout=20;Workstation Id=\"'\"\"desktop\";";
86                         conn = new SqlConnection (connStr);
87                         Assert.AreEqual (connStr , conn.ConnectionString , "#B1");
88                         Assert.AreEqual ("loca\"lhost" , conn.DataSource , "#B2");
89                         Assert.AreEqual ("'Db" , conn.Database , "#B3");
90                         Assert.AreEqual (512 , conn.PacketSize , "#B4");
91                         Assert.AreEqual (20 , conn.ConnectionTimeout , "#B5");
92                         Assert.AreEqual ("'\"desktop" , conn.WorkstationId , "#B6");
93                 }
94
95                 [Test]
96                 public void Open ()
97                 {
98                         conn = new SqlConnection (connectionString);
99                         conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
100                         conn.Open ();
101
102                         Assert.AreEqual (ConnectionState.Open, conn.State, "#1");
103                         Assert.AreEqual (1, events.Count, "#2");
104                         StateChangeEventArgs args = events [0] as StateChangeEventArgs;
105                         Assert.IsNotNull (args, "#3");
106                         Assert.AreEqual (ConnectionState.Closed, args.OriginalState, "#4");
107                         Assert.AreEqual (ConnectionState.Open, args.CurrentState, "#5");
108
109                         conn.Close ();
110                 }
111
112                 [Test]
113                 public void Open_Connection_Open ()
114                 {
115                         conn = new SqlConnection (connectionString);
116                         conn.Open ();
117
118                         try {
119                                 conn.Open ();
120                                 Assert.Fail ("#1");
121                         } catch (InvalidOperationException ex) {
122                                 // The connection was not closed. The connection's
123                                 // current state is open
124                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
125                                 Assert.IsNull (ex.InnerException, "#3");
126                                 Assert.IsNotNull (ex.Message, "#4");
127                         } finally {
128                                 conn.Close ();
129                         }
130                 }
131
132                 [Test]
133                 public void Open_ConnectionString_LoginInvalid ()
134                 {
135                         // login invalid
136                         conn = new SqlConnection (connectionString + "user id=invalidLogin");
137                         try {
138                                 conn.Open ();
139                                 Assert.Fail ("#1");
140                         } catch (SqlException ex) {
141                                 // Login failed for user 'invalidLogin'
142                                 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
143                                 Assert.AreEqual ((byte) 14, ex.Class, "#3");
144                                 Assert.IsNull (ex.InnerException, "#4");
145                                 Assert.IsNotNull (ex.Message, "#5");
146                                 Assert.IsTrue (ex.Message.IndexOf ("'invalidLogin'") != -1, "#6");
147                                 Assert.AreEqual (18456, ex.Number, "#7");
148                                 Assert.AreEqual ((byte) 1, ex.State, "#8");
149                         } finally {
150                                 conn.Close ();
151                         }
152                 }
153
154                 [Test]
155                 public void Open_ConnectionString_DatabaseInvalid ()
156                 {
157                         conn = new SqlConnection (connectionString + "database=invalidDB");
158                         try {
159                                 conn.Open ();
160                                 Assert.Fail ("#1");
161                         } catch (SqlException ex) {
162                                 // Cannot open database "invalidDB" requested
163                                 // by the login. The login failed
164                                 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
165                                 Assert.AreEqual ((byte) 11, ex.Class, "#3");
166                                 Assert.IsNull (ex.InnerException, "#4");
167                                 Assert.IsNotNull (ex.Message, "#5");
168                                 Assert.IsTrue (ex.Message.IndexOf ("invalidDB") != -1, "#6: " + ex.Message);
169                                 Assert.AreEqual (4060, ex.Number, "#7");
170                                 Assert.AreEqual ((byte) 1, ex.State, "#8");
171                         } finally {
172                                 conn.Close ();
173                         }
174
175                 }
176
177                 [Test]
178                 public void Open_ConnectionString_PasswordInvalid ()
179                 {
180                         // password invalid
181                         conn = new SqlConnection (connectionString + ";password=invalidPassword");
182                         try {
183                                 conn.Open ();
184                                 Assert.Fail ("#1");
185                         } catch (SqlException ex) {
186                                 // Login failed for user '...'
187                                 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
188                                 Assert.AreEqual ((byte) 14, ex.Class, "#3");
189                                 Assert.IsNull (ex.InnerException, "#4");
190                                 Assert.IsNotNull (ex.Message, "#5");
191                                 Assert.AreEqual (18456, ex.Number, "#6");
192                                 Assert.AreEqual ((byte) 1, ex.State, "#7");
193                         } finally {
194                                 conn.Close ();
195                         }
196                 }
197
198                 [Test]
199                 public void Open_ConnectionString_ServerInvalid ()
200                 {
201                         Assert.Ignore ("Long running");
202
203                         // server invalid
204                         conn = new SqlConnection (connectionString + ";server=invalidServerName");
205                         try {
206                                 conn.Open ();
207                                 Assert.Fail ("#1");
208                         } catch (SqlException ex) {
209                                 // An error has occurred while establishing a
210                                 // connection to the server...
211                                 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
212                                 Assert.AreEqual ((byte) 20, ex.Class, "#3");
213                                 Assert.IsNull (ex.InnerException, "#4");
214                                 Assert.IsNotNull (ex.Message, "#5");
215                                 Assert.AreEqual (53, ex.Number, "#6");
216                                 Assert.AreEqual ((byte) 0, ex.State, "#7");
217                         } finally {
218                                 conn.Close ();
219                         }
220                         }
221
222                 [Test] // bug #383061
223                 public void Open_MaxPoolSize_Reached ()
224                 {
225                         connectionString += "Pooling=true;Connection Lifetime=6;"
226                                 + "Connect Timeout=3;Max Pool Size=2";
227
228                         SqlConnection conn1 = new SqlConnection (connectionString);
229                         conn1.Open ();
230
231                         SqlConnection conn2 = new SqlConnection (connectionString);
232                         conn2.Open ();
233
234                         DateTime start = DateTime.Now;
235
236                         try {
237                                 using (SqlConnection sqlConnection = new SqlConnection (connectionString)) {
238                                         sqlConnection.Open ();
239                                 }
240                                 Assert.Fail ("#A1");
241                         } catch (InvalidOperationException ex) {
242                                 // System.InvalidOperationException: Timeout expired.
243                                 // The timeout period elapsed prior to obtaining a
244                                 // connection from the pool. This may have occurred
245                                 // because all pooled connections were in use and max
246                                 // pool size was reached.
247                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
248                                 Assert.IsNull (ex.InnerException, "#A3");
249                                 Assert.IsNotNull (ex.Message, "#A4");
250                         }
251
252                         TimeSpan elapsed = DateTime.Now - start;
253
254                         Assert.IsTrue (elapsed.TotalSeconds >= 3, "#B1:" + elapsed.TotalSeconds);
255                         Assert.IsTrue (elapsed.TotalSeconds < 4, "#B2:" + elapsed.TotalSeconds);
256
257                         conn2.Close ();
258
259                         // as the second connection is closed, we should now be
260                         // able to open a new connection (which essentially
261                         // uses the pooled connection from conn2)
262                         SqlConnection conn3 = new SqlConnection (connectionString);
263                         conn3.Open ();
264                         conn3.Close ();
265
266                         conn1.Close ();
267                 }
268
269                 [Test] // bug #412574
270                 public void Close ()
271                 {
272                         conn = new SqlConnection (connectionString);
273                         conn.Open ();
274                         conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
275                         conn.Close ();
276
277                         Assert.AreEqual (ConnectionState.Closed, conn.State, "#1");
278                         Assert.AreEqual (1, events.Count, "#2");
279                         StateChangeEventArgs args = events [0] as StateChangeEventArgs;
280                         Assert.IsNotNull (args, "#3");
281                         Assert.AreEqual (ConnectionState.Open, args.OriginalState, "#4");
282                         Assert.AreEqual (ConnectionState.Closed, args.CurrentState, "5");
283
284                         conn.Close ();
285
286                         Assert.AreEqual (1, events.Count, "#6");
287                 }
288
289                 [Test]
290                 public void ChangeDatabase ()
291                 {
292                         conn = new SqlConnection (connectionString);
293                         conn.Open ();
294                         conn.ChangeDatabase ("master");
295                         Assert.AreEqual ("master", conn.Database);
296                 }
297
298                 [Test]
299                 public void ChangeDatabase_DatabaseName_DoesNotExist ()
300                 {
301                         conn = new SqlConnection (connectionString);
302                         conn.Open ();
303
304                         String database = conn.Database;
305
306                         try {
307                                 conn.ChangeDatabase ("doesnotexist");
308                                 Assert.Fail ("#1");
309                         } catch (SqlException ex) {
310                                 // Could not locate entry in sysdatabases for
311                                 // database 'doesnotexist'. No entry found with
312                                 // that name. Make sure that the name is entered
313                                 // correctly.
314                                 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
315                                 Assert.AreEqual ((byte) 16, ex.Class, "#3");
316                                 Assert.IsNull (ex.InnerException, "#4");
317                                 Assert.IsNotNull (ex.Message, "#5");
318                                 Assert.IsTrue (ex.Message.IndexOf ("'doesnotexist'") != -1, "#6");
319                                 Assert.AreEqual (911, ex.Number, "#7");
320                                 Assert.AreEqual ((byte) 1, ex.State, "#8");
321
322                                 Assert.AreEqual (database, conn.Database, "#9");
323                         } finally {
324                                 conn.Close ();
325                         }
326                 }
327
328                 [Test]
329                 public void ChangeDatabase_DatabaseName_Empty ()
330                 {
331                         conn = new SqlConnection (connectionString);
332                         conn.Open ();
333                         try {
334                                 conn.ChangeDatabase (string.Empty);
335                                 Assert.Fail ("#1");
336                         } catch (ArgumentException ex) {
337                                 // Database cannot be null, the empty string,
338                                 // or string of only whitespace
339                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
340                                 Assert.IsNull (ex.InnerException, "#3");
341                                 Assert.IsNotNull (ex.Message, "#4");
342                                 Assert.IsNull (ex.ParamName);
343                         }
344                 }
345
346                 [Test]
347                 public void ChangeDatabase_DatabaseName_Null ()
348                 {
349                         conn = new SqlConnection (connectionString);
350                         conn.Open ();
351                         try {
352                                 conn.ChangeDatabase ((string) null);
353                                 Assert.Fail ("#1");
354                         } catch (ArgumentException ex) {
355                                 // Database cannot be null, the empty string,
356                                 // or string of only whitespace
357                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
358                                 Assert.IsNull (ex.InnerException, "#3");
359                                 Assert.IsNotNull (ex.Message, "#4");
360                                 Assert.IsNull (ex.ParamName);
361                         }
362                 }
363
364                 [Test] // bug #412581
365                 public void ChangeDatabase_DatabaseName_Whitespace ()
366                 {
367                         Assert.Ignore ("bug #412581");
368
369                         conn = new SqlConnection (connectionString);
370                         conn.Open ();
371                         try {
372                                 conn.ChangeDatabase ("   ");
373                                 Assert.Fail ("#1");
374                         } catch (SqlException ex) {
375                                 // Could not locate entry in sysdatabases for
376                                 // database '   '. No entry found with that name.
377                                 // Make sure that the name is entered correctly
378                                 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
379                                 Assert.AreEqual ((byte) 16, ex.Class, "#3");
380                                 Assert.IsNull (ex.InnerException, "#4");
381                                 Assert.IsNotNull (ex.Message, "#5");
382                                 Assert.IsTrue (ex.Message.IndexOf ("'   '") != -1, "#6");
383                                 Assert.AreEqual (911, ex.Number, "#7");
384                                 Assert.AreEqual ((byte) 1, ex.State, "#8");
385                         }
386                 }
387
388                 [Test]
389                 public void ClearAllPools ()
390                 {
391                         SqlConnection conn1 = new SqlConnection (connectionString + ";Pooling=false");
392                         conn1.Open ();
393
394                         int initial_connection_count = GetConnectionCount (conn1);
395
396                         SqlConnection conn2 = new SqlConnection (connectionString + ";App=A");
397                         conn2.Open ();
398                         conn2.Close ();
399
400                         SqlConnection conn3 = new SqlConnection (connectionString + ";App=B");
401                         conn3.Open ();
402                         conn3.Close ();
403
404                         Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
405
406                         SqlConnection.ClearAllPools ();
407
408                         Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#2");
409                         conn1.Close ();
410                 }
411
412                 [Test] // bug #443131
413                 public void ClearPool ()
414                 {
415                         SqlConnection conn1 = new SqlConnection (connectionString);
416                         conn1.Open ();
417
418                         int initial_connection_count = GetConnectionCount (conn1);
419
420                         SqlConnection conn2 = new SqlConnection (connectionString);
421                         conn2.Open ();
422
423                         SqlConnection conn3 = new SqlConnection (connectionString);
424                         conn3.Open ();
425                         conn3.Close ();
426
427                         Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
428
429                         SqlConnection.ClearPool (conn1);
430
431                         // check if pooled connections that were not in use are
432                         // actually closed
433                         Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn1), "#2");
434
435                         conn2.Close ();
436
437                         // check if connections that were in use when the pool
438                         // was cleared will not be returned to the pool when
439                         // closed (and are closed instead)
440                         Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#3");
441
442                         SqlConnection conn4 = new SqlConnection (connectionString);
443                         conn4.Open ();
444
445                         SqlConnection conn5 = new SqlConnection (connectionString);
446                         conn5.Open ();
447
448                         SqlConnection conn6 = new SqlConnection (connectionString);
449                         conn6.Open ();
450
451                         Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#4");
452
453                         conn5.Close ();
454                         conn6.Close ();
455
456                         // check if new connections are stored in the pool again
457                         Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#5");
458
459                         conn1.Close ();
460
461                         Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn4), "#6");
462
463                         SqlConnection.ClearPool (conn3);
464
465                         // the connection passed to ClearPool does not have to
466                         // be open
467                         Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#7");
468
469                         SqlConnection conn7 = new SqlConnection (connectionString);
470                         conn7.Open ();
471                         conn7.Close ();
472
473                         Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#8");
474
475                         conn3.ConnectionString += ";App=B";
476                         SqlConnection.ClearPool (conn3);
477
478                         // check if a pool is identified by its connection string
479                         Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#9");
480
481                         SqlConnection conn8 = new SqlConnection (connectionString);
482                         SqlConnection.ClearPool (conn8);
483
484                         // connection should not have been opened before to
485                         // clear the corresponding pool
486                         Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#10");
487
488                         SqlConnection conn9 = new SqlConnection (connectionString);
489                         conn9.Open ();
490                         conn9.Close ();
491
492                         Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#11");
493
494                         conn3.ConnectionString = connectionString;
495                         SqlConnection.ClearPool (conn3);
496
497                         Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#12");
498
499                         SqlConnection conn10 = new SqlConnection (connectionString);
500                         conn10.Open ();
501
502                         SqlConnection conn11 = new SqlConnection (connectionString + ";App=B");
503                         conn11.Open ();
504
505                         SqlConnection conn12 = new SqlConnection (connectionString + ";App=B");
506                         conn12.Open ();
507
508                         SqlConnection conn13 = new SqlConnection (connectionString + ";App=B");
509                         conn13.Open ();
510
511                         conn10.Close ();
512                         conn11.Close ();
513                         conn12.Close ();
514                         conn13.Close ();
515
516                         Assert.AreEqual (initial_connection_count + 4, GetConnectionCount (conn4), "#13");
517
518                         // check that other connection pools are not affected
519                         SqlConnection.ClearPool (conn13);
520
521                         Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#14");
522
523                         SqlConnection conn14 = new SqlConnection (connectionString);
524                         conn14.Open ();
525                         conn14.Dispose ();
526
527                         // a disposed connection cannot be used to clear a pool
528                         SqlConnection.ClearPool (conn14);
529
530                         Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#15");
531
532                         SqlConnection.ClearPool (conn4);
533
534                         Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#16");
535
536                         conn4.Close ();
537                 }
538
539                 [Test]
540                 public void InterfaceTransactionTest ()
541                 {
542                         conn = new SqlConnection (connectionString);
543                         conn.Open ();
544                         IDbCommand idbCommand = new SqlCommand ("use [mono-test]", conn);
545                         idbCommand.Connection = null;
546                         Assert.AreEqual (null, idbCommand.Connection, "Connection should be null");
547                         idbCommand.Transaction = null;
548                         Assert.AreEqual (null, idbCommand.Transaction, "Transaction should be null");
549
550                         conn.Close ();
551                 }
552
553                 [Test]
554                 public void BeginTransaction ()
555                 {
556                         conn = new SqlConnection (connectionString);
557                         conn.Open ();
558
559                         SqlTransaction trans = conn.BeginTransaction ();
560                         Assert.AreSame (conn, trans.Connection, "#A1");
561                         Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel, "#A2");
562                         trans.Rollback ();
563
564                         trans = conn.BeginTransaction ();
565
566                         try {
567                                 conn.BeginTransaction ();
568                                 Assert.Fail ("#B1");
569                         } catch (InvalidOperationException ex) {
570                                 // SqlConnection does not support parallel transactions
571                                 Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(), "#B2");
572                                 Assert.IsNull (ex.InnerException, "#B3");
573                                 Assert.IsNotNull (ex.Message, "#B4");
574                         } finally {
575                                 trans.Rollback();
576                         }
577
578                         try {
579                                 trans = conn.BeginTransaction ();
580                                 trans.Rollback ();
581                                 trans = conn.BeginTransaction ();
582                                 trans.Commit ();
583                                 trans = conn.BeginTransaction ();
584                         } finally {
585                                 trans.Rollback ();
586                         }
587                 }
588
589                 [Test]
590                 public void ConnectionString ()
591                 {
592                         conn = new SqlConnection (connectionString);
593                         // Test Repeated Keyoword should take the latest value
594                         conn.ConnectionString = conn.ConnectionString + ";server=RepeatedServer;";
595                         Assert.AreEqual ("RepeatedServer", ((SqlConnection)conn).DataSource, "#A1");
596                         conn.ConnectionString += ";database=gen;Initial Catalog=gen1";
597                         Assert.AreEqual ("gen1", conn.Database, "#A2");
598
599                         // Test if properties are set correctly
600                         string str = "server=localhost1;database=db;user id=user;";
601                         str += "password=pwd;Workstation ID=workstation;Packet Size=512;";
602                         str += "Connect Timeout=10";
603                         conn.ConnectionString = str;
604
605                         Assert.AreEqual ("localhost1", conn.DataSource, "#B1");
606                         Assert.AreEqual ("db", conn.Database, "#B2");
607                         Assert.AreEqual (ConnectionState.Closed, conn.State, "#B3");
608                         Assert.AreEqual ("workstation", conn.WorkstationId, "#B4");
609                         Assert.AreEqual (512, conn.PacketSize, "#B5");
610                         Assert.AreEqual (10, conn.ConnectionTimeout, "#B6");
611                         
612                         // Test if any leftover values exist from previous invocation
613                         conn.ConnectionString = connectionString;
614                         conn.ConnectionString = string.Empty;
615                         Assert.AreEqual (string.Empty, conn.DataSource, "#C1");
616                         Assert.AreEqual ("", conn.Database, "#C2");
617                         Assert.AreEqual (8000, conn.PacketSize, "#C3");
618                         Assert.AreEqual (15, conn.ConnectionTimeout, "#C4");
619                         Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#C5");
620                 }
621
622                 [Test]
623                 public void ConnectionString_Connection_Open ()
624                 {
625                         conn = new SqlConnection (connectionString);
626                         conn.ConnectionString = connectionString;
627                         conn.Open ();
628                         try {
629                                 conn.ConnectionString = "server=localhost;database=tmp;";
630                                 Assert.Fail ("#1");
631                         } catch (InvalidOperationException ex) {
632                                 // Not allowed to change the 'ConnectionString'
633                                 // property. The connection's current state is open
634                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
635                                 Assert.IsNull (ex.InnerException, "#3");
636                                 Assert.IsNotNull (ex.Message, "#4");
637                         } finally {
638                                 conn.Close ();
639                         }
640                 }
641
642                 [Test]
643                 public void ServerVersionTest ()
644                 {
645                         conn = new SqlConnection (connectionString);
646
647                         // Test InvalidOperation Exception is thrown if Connection is CLOSED
648                         try {
649                                 string s = conn.ServerVersion;
650                                 Assert.Fail ("#A1:" + s);
651                         } catch (InvalidOperationException ex) {
652                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
653                                 Assert.IsNull (ex.InnerException, "#A3");
654                                 Assert.IsNotNull (ex.Message, "#A4");
655                         }
656                         
657                         // Test if Release Version is as per specification.
658                         conn.Open ();
659                         String [] version = conn.ServerVersion.Split ('.');
660                         Assert.AreEqual (2, version[0].Length,
661                                 "#B1 The Major release shud be exactly 2 characters");
662                         Assert.AreEqual (2, version[1].Length,
663                                 "#B2 The Minor release shud be exactly 2 characters");
664                         Assert.AreEqual (4, version[2].Length,
665                                 "#B3 The Release version should be exactly 4 digits");
666                 }
667
668                 [Test]
669                 public void Database ()
670                 {
671                         conn = new SqlConnection (connectionString);
672                         string database = conn.Database;
673
674                         SqlCommand cmd;
675
676                         // Test if database property is updated when a query changes database
677                         conn.Open ();
678                         cmd = new SqlCommand ("use [master]" , conn);
679                         cmd.ExecuteNonQuery ();
680                         Assert.AreEqual ("master", conn.Database, "#1");
681
682                         // ensure we're really in the expected database
683                         if (ClientVersion == 7)
684                                 cmd.CommandText = "SELECT name FROM sysdatabases WHERE name = 'master'";
685                         else
686                                 cmd.CommandText = "SELECT name FROM sys.databases WHERE name = 'master'";
687                         using (SqlDataReader dr = cmd.ExecuteReader ()) {
688                                 Assert.IsTrue (dr.Read (), "#2");
689                         }
690
691                         conn.Close ();
692                         Assert.AreEqual (database, conn.Database, "#3");
693
694                         // Test if the database property is reset on re-opening the connection
695                         conn.ConnectionString = connectionString;
696                         conn.Open ();
697                         Assert.AreEqual (database, conn.Database, "#4");
698
699                         // ensure we're really in the expected database
700                         cmd.CommandText = "SELECT fname FROM employee WHERE id = 2";
701                         using (SqlDataReader dr = cmd.ExecuteReader ()) {
702                                 Assert.IsTrue (dr.Read (), "#5");
703                                 Assert.AreEqual ("ramesh", dr.GetValue (0), "#6");
704                         }
705
706                         conn.Close ();
707                 }
708
709                 [Test] // bug #412571
710                 public void Dispose ()
711                 {
712                         StateChangeEventArgs stateChangeArgs;
713                         EventArgs disposedArgs;
714
715                         conn = new SqlConnection (connectionString + ";Connection Timeout=30;Packet Size=512;Workstation Id=Desktop");
716                         conn.Disposed += new EventHandler (Connection_Disposed);
717                         conn.Open ();
718                         conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
719                         Assert.AreEqual (0, events.Count, "#A1");
720                         conn.Dispose ();
721                         Assert.AreEqual (string.Empty, conn.ConnectionString, "#A2");
722                         Assert.AreEqual (15, conn.ConnectionTimeout, "#A3");
723                         Assert.AreEqual (string.Empty, conn.Database, "#A4");
724                         Assert.AreEqual (string.Empty, conn.DataSource, "#A5");
725                         Assert.AreEqual (8000, conn.PacketSize, "#A6");
726                         Assert.AreEqual (ConnectionState.Closed, conn.State, "#A7");
727                         Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#A8");
728                         Assert.AreEqual (2, events.Count, "#A9");
729
730                         stateChangeArgs = events [0] as StateChangeEventArgs;
731                         Assert.IsNotNull (stateChangeArgs, "#B1");
732                         Assert.AreEqual (typeof (StateChangeEventArgs), stateChangeArgs.GetType (), "#B2");
733                         Assert.AreEqual (ConnectionState.Open, stateChangeArgs.OriginalState, "#B3");
734                         Assert.AreEqual (ConnectionState.Closed, stateChangeArgs.CurrentState, "B4");
735
736                         disposedArgs = events [1] as EventArgs;
737                         Assert.IsNotNull (disposedArgs, "#C1");
738                         Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#C2");
739
740                         conn.Dispose ();
741
742                         Assert.AreEqual (ConnectionState.Closed, conn.State, "#D1");
743                         Assert.AreEqual (3, events.Count, "#D2");
744
745                         disposedArgs = events [2] as EventArgs;
746                         Assert.IsNotNull (disposedArgs, "#E1");
747                         Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#E2");
748                 }
749
750                 void Connection_StateChange (object sender , StateChangeEventArgs e)
751                 {
752                         events.Add (e);
753                 }
754
755                 void Connection_Disposed (object sender , EventArgs e)
756                 {
757                         events.Add (e);
758                 }
759
760                 [Test]
761                 public void FireInfoMessageEventOnUserErrorsTest ()
762                 {
763                         conn = new SqlConnection ();
764                         Assert.AreEqual(false, conn.FireInfoMessageEventOnUserErrors, "#1 The default value should be false");
765                         conn.FireInfoMessageEventOnUserErrors = true;
766                         Assert.AreEqual(true, conn.FireInfoMessageEventOnUserErrors, "#1 The value should be true after setting the property to true");
767                 }
768
769                 [Test]
770                 public void StatisticsEnabledTest ()
771                 {
772                         conn = new SqlConnection (); 
773                         Assert.AreEqual(false, conn.StatisticsEnabled, "#1 The default value should be false");
774                         conn.StatisticsEnabled = true;
775                         Assert.AreEqual(true, conn.StatisticsEnabled, "#1 The value should be true after setting the property to true");
776                 }
777
778                 [Test]
779                 public void ChangePasswordTest ()
780                 {
781                         string tmpPassword = "modifiedbymonosqlclient";
782                         SqlConnection.ChangePassword (connectionString, tmpPassword);
783                         SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder (connectionString);
784                         string oldPassword = connBuilder.Password;
785                         connBuilder.Password = tmpPassword;
786                         SqlConnection.ChangePassword (connBuilder.ConnectionString, oldPassword); // Modify to the original password
787                 }
788
789                 static int GetConnectionCount (SqlConnection conn)
790                 {
791                         Thread.Sleep (200);
792
793                         SqlCommand cmd = conn.CreateCommand ();
794                         cmd.CommandText = "select count(*) from master..sysprocesses where db_name(dbid) = @dbname";
795                         cmd.Parameters.Add (new SqlParameter ("@dbname", conn.Database));
796                         int connection_count = (int) cmd.ExecuteScalar ();
797                         cmd.Dispose ();
798
799                         return connection_count;
800                 }
801
802                 int ClientVersion {
803                         get {
804                                 return (engine.ClientVersion);
805                         }
806                 }
807         }
808
809         [TestFixture]
810         [Category ("sqlserver")]
811         public class GetSchemaTest
812         {
813                 SqlConnection conn = null;
814                 String connectionString = ConnectionManager.Singleton.ConnectionString;
815
816                 [SetUp]
817                 public void Setup()
818                 {
819                         conn = new SqlConnection(connectionString);
820                         conn.Open();
821                 }
822
823                 [TearDown]
824                 public void TearDown()
825                 {
826                         conn.Close();
827                 }
828
829                 [Test]
830                 public void GetSchemaTest1()
831                 {
832                         bool flag = false;
833                         DataTable tab1 = conn.GetSchema("databases");
834                         foreach (DataRow row in tab1.Rows)
835                         {
836                                 foreach (DataColumn col in tab1.Columns)
837                                 {
838                                         if (col.ColumnName.ToString() == "database_name" && row[col].ToString() == "monotest")
839                                         {
840                                                 flag = true;
841                                                 break;
842                                         }
843                                 }
844                                 if (flag)
845                                         break;
846                         }
847                         Assert.AreEqual(true, flag, "#GS1 failed");
848                 }
849
850                 [Test]
851                 [ExpectedException(typeof(ArgumentException))]
852                 public void GetSchemaTest2()
853                 {
854                         conn.GetSchema(null);
855                 }
856
857                 [Test]
858                 public void GetSchemaTest3 ()
859                 {
860                         Assert.Ignore ("We currently have no foreign keys defined in the test database");
861
862                         bool flag = false;
863                         DataTable tab1 = conn.GetSchema("ForeignKeys");
864                         foreach (DataRow row in tab1.Rows)
865                         {
866                                 foreach (DataColumn col in tab1.Columns)
867                                 {
868                                         /*
869                                          * We need to consider multiple values
870                                          */
871                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "tmptable1")
872                                         {
873                                                 flag = true;
874                                                 break;
875                                         }
876                                 }
877                                 if (flag)
878                                         break;
879                         }
880                         Assert.AreEqual(true, flag, "#GS3 failed");
881                 }
882
883                 [Test]
884                 public void GetSchemaTest4()
885                 {
886                         bool flag = false;
887                         DataTable tab1 = conn.GetSchema("Indexes");
888                         foreach (DataRow row in tab1.Rows)
889                         {
890                                 foreach (DataColumn col in tab1.Columns)
891                                 {
892                                         /*
893                                          * We need to consider multiple values
894                                          */
895                                         if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
896                                         {
897                                                 flag = true;
898                                                 break;
899                                         }
900                                 }
901                                 if (flag)
902                                         break;
903                         }
904                         Assert.AreEqual(true, flag, "#GS4 failed");
905                 }
906
907                 [Test]
908                 public void GetSchemaTest5()
909                 {
910                         bool flag = false;
911                         DataTable tab1 = conn.GetSchema("IndexColumns");
912                         foreach (DataRow row in tab1.Rows)
913                         {
914                                 foreach (DataColumn col in tab1.Columns)
915                                 {
916                                         /*
917                                          * We need to consider multiple values
918                                          */
919                                         if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
920                                         {
921                                                 flag = true;
922                                                 break;
923                                         }
924                                 }
925                                 if (flag)
926                                         break;
927                         }
928                         Assert.AreEqual(true, flag, "#GS5 failed");
929                 }
930
931                 [Test]
932                 public void GetSchemaTest6()
933                 {
934                         bool flag = false;
935                         DataTable tab1 = conn.GetSchema("Procedures");
936                         foreach (DataRow row in tab1.Rows)
937                         {
938                                 foreach (DataColumn col in tab1.Columns)
939                                 {
940                                         /*
941                                          * We need to consider multiple values
942                                          */
943                                         if (col.ColumnName.ToString() == "SPECIFIC_NAME" && row[col].ToString() == "sp_get_age")
944                                         {
945                                                 flag = true;
946                                                 break;
947                                         }
948                                 }
949                                 if (flag)
950                                         break;
951                         }
952                         Assert.AreEqual(true, flag, "#GS6 failed");
953                 }
954
955                 [Test]
956                 public void GetSchemaTest7()
957                 {
958                         bool flag = false;
959                         DataTable tab1 = conn.GetSchema("ProcedureParameters");
960                         foreach (DataRow row in tab1.Rows)
961                         {
962                                 foreach (DataColumn col in tab1.Columns)
963                                 {
964                                         /*
965                                          * We need to consider multiple values
966                                          */
967                                         if (col.ColumnName.ToString() == "SPECIFIC_NAME" && row[col].ToString() == "sp_get_age")
968                                         {
969                                                 flag = true;
970                                                 break;
971                                         }
972                                 }
973                                 if (flag)
974                                         break;
975                         }
976                         Assert.AreEqual(true, flag, "#GS7 failed");
977                 }
978
979                 [Test]
980                 public void GetSchemaTest8()
981                 {
982                         bool flag = false;
983                         DataTable tab1 = conn.GetSchema("Tables");
984                         foreach (DataRow row in tab1.Rows)
985                         {
986                                 foreach (DataColumn col in tab1.Columns)
987                                 {
988                                         /*
989                                          * We need to consider multiple values
990                                          */
991                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
992                                         {
993                                                 flag = true;
994                                                 break;
995                                         }
996                                 }
997                                 if (flag)
998                                         break;
999                         }
1000                         Assert.AreEqual(true, flag, "#GS8 failed");
1001                 }
1002
1003                 [Test]
1004                 public void GetSchemaTest9()
1005                 {
1006                         bool flag = false;
1007                         DataTable tab1 = conn.GetSchema("Columns");
1008                         foreach (DataRow row in tab1.Rows)
1009                         {
1010                                 foreach (DataColumn col in tab1.Columns)
1011                                 {
1012                                         /*
1013                                          * We need to consider multiple values
1014                                          */
1015                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
1016                                         {
1017                                                 flag = true;
1018                                                 break;
1019                                         }
1020                                 }
1021                                 if (flag)
1022                                         break;
1023                         }
1024                         Assert.AreEqual(true, flag, "#GS9 failed");
1025                 }
1026
1027                 [Test]
1028                 public void GetSchemaTest10()
1029                 {
1030                         bool flag = false;
1031                         DataTable tab1 = conn.GetSchema("Users");
1032                         foreach (DataRow row in tab1.Rows)
1033                         {
1034                                 foreach (DataColumn col in tab1.Columns)
1035                                 {
1036                                         /*
1037                                          * We need to consider multiple values
1038                                          */
1039                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
1040                                         {
1041                                                 flag = true;
1042                                                 break;
1043                                         }
1044                                 }
1045                                 if (flag)
1046                                         break;
1047                         }
1048                         Assert.AreEqual(true, flag, "#GS10 failed");
1049                 }
1050
1051                 [Test]
1052                 public void GetSchemaTest11 ()
1053                 {
1054                         Assert.Ignore ("Incorrect syntax near 'TABLE_SCHEMA'");
1055
1056                         bool flag = false;
1057                         DataTable tab1 = conn.GetSchema("Views");
1058                         flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
1059                         foreach (DataRow row in tab1.Rows)
1060                         {
1061                                 foreach (DataColumn col in tab1.Columns)
1062                                 {
1063                                         /*
1064                                          * We need to consider multiple values.
1065                                          */
1066                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
1067                                         {
1068                                                 flag = true;
1069                                                 break;
1070                                         }
1071                                 }
1072                                 if (flag)
1073                                         break;
1074                         }
1075                         Assert.AreEqual(true, flag, "#GS11 failed");
1076                 }
1077
1078                 [Test]
1079                 public void GetSchemaTest12 ()
1080                 {
1081                         Assert.Ignore ("Incorrect syntax near '('");
1082
1083                         bool flag = false;
1084                         DataTable tab1 = conn.GetSchema("ViewColumns");
1085                         flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
1086                         foreach (DataRow row in tab1.Rows)
1087                         {
1088                                 foreach (DataColumn col in tab1.Columns)
1089                                 {
1090                                         /*
1091                                          * We need to consider multiple values.
1092                                          */
1093                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
1094                                         {
1095                                                 flag = true;
1096                                                 break;
1097                                         }
1098                                 }
1099                                 if (flag)
1100                                         break;
1101                         }
1102                         Assert.AreEqual(true, flag, "#GS12 failed");
1103                 }
1104
1105                 [Test]
1106                 public void GetSchemaTest13 ()
1107                 {
1108                         Assert.Ignore ("The multi-part identifier \"assportemblies.name\" could not be bound");
1109
1110                         bool flag = false;
1111                         DataTable tab1 = conn.GetSchema("UserDefinedTypes");
1112                         flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
1113                         foreach (DataRow row in tab1.Rows)
1114                         {
1115                                 foreach (DataColumn col in tab1.Columns)
1116                                 {
1117                                         /*
1118                                          * We need to consider multiple values.
1119                                          */
1120                                         if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
1121                                         {
1122                                                 flag = true;
1123                                                 break;
1124                                         }
1125                                 }
1126                                 if (flag)
1127                                         break;
1128                         }
1129                         Assert.AreEqual(true, flag, "#GS13 failed");
1130                 }
1131
1132                 [Test]
1133                 public void GetSchemaTest14()
1134                 {
1135                         bool flag = false;
1136                         string [] restrictions = new string[4];
1137
1138                         restrictions[0] = "monotest";
1139                         restrictions[1] = "dbo";
1140                         restrictions[2] = null;
1141                         restrictions[3] = "BASE TABLE";
1142                         DataTable tab1 = conn.GetSchema("Tables", restrictions);
1143                         foreach (DataRow row in tab1.Rows)
1144                         {
1145                                 foreach (DataColumn col in tab1.Columns)
1146                                 {
1147                                         /*
1148                                          * We need to consider multiple values
1149                                          */
1150                                         if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
1151                                         {
1152                                                 flag = true;
1153                                                 break;
1154                                         }
1155                                 }
1156                                 if (flag)
1157                                         break;
1158                         }
1159                         Assert.AreEqual(true, flag, "#GS14 failed");
1160                 }
1161
1162                 [Test]
1163                 public void GetSchemaTest15()
1164                 {
1165                         bool flag = false;
1166                         string [] restrictions = new string[4];
1167
1168                         restrictions[0] = "monotest";
1169                         restrictions[1] = null;
1170                         restrictions[2] = "binary_family";
1171                         restrictions[3] = null;
1172                         DataTable tab1 = conn.GetSchema("IndexColumns", restrictions);
1173                         foreach (DataRow row in tab1.Rows)
1174                         {
1175                                 foreach (DataColumn col in tab1.Columns)
1176                                 {
1177                                         /*
1178                                          * We need to consider multiple values
1179                                          */
1180                                         if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
1181                                         {
1182                                                 flag = true;
1183                                                 break;
1184                                         }
1185                                 }
1186                                 if (flag)
1187                                         break;
1188                         }
1189                         Assert.AreEqual(true, flag, "#GS15 failed");
1190                 }
1191
1192                 [Test]
1193                 public void GetSchemaTest16()
1194                 {
1195                         bool flag = false;
1196                         string [] restrictions = new string[4];
1197
1198                         restrictions[0] = "monotest";
1199                         restrictions[1] = null;
1200                         restrictions[2] = "sp_get_age";
1201                         restrictions[3] = null;
1202                         DataTable tab1 = conn.GetSchema("Procedures", restrictions);
1203                         foreach (DataRow row in tab1.Rows)
1204                         {
1205                                 foreach (DataColumn col in tab1.Columns)
1206                                 {
1207                                         /*
1208                                          * We need to consider multiple values
1209                                          */
1210                                         if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "sp_get_age")
1211                                         {
1212                                                 flag = true;
1213                                                 break;
1214                                         }
1215                                 }
1216                                 if (flag)
1217                                         break;
1218                         }
1219                         Assert.AreEqual(true, flag, "#GS16 failed");
1220                 }
1221
1222                 [Test]
1223                 public void GetSchemaTest17()
1224                 {
1225                         bool flag = false;
1226                         DataTable tab1 = conn.GetSchema();
1227                         foreach (DataRow row in tab1.Rows)
1228                         {
1229                                 foreach (DataColumn col in tab1.Columns)
1230                                 {
1231                                         /*
1232                                          * We need to consider multiple values
1233                                          */
1234                                         if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
1235                                         {
1236                                                 flag = true;
1237                                                 break;
1238                                         }
1239                                 }
1240                                 if (flag)
1241                                         break;
1242                         }
1243                         Assert.AreEqual(true, flag, "#GS17 failed");
1244                 }
1245
1246                 [Test]
1247                 public void GetSchemaTest18()
1248                 {
1249                         bool flag = false;
1250                         DataTable tab1 = conn.GetSchema("RESTRICTIONS");
1251                         foreach (DataRow row in tab1.Rows)
1252                         {
1253                                 foreach (DataColumn col in tab1.Columns)
1254                                 {
1255                                         /*
1256                                          * We need to consider multiple values
1257                                          */
1258                                         if (col.ColumnName.ToString() == "RestrictionDefault" && row[col].ToString() == "CONSTRAINT_NAME")
1259                                         {
1260                                                 flag = true;
1261                                                 break;
1262                                         }
1263                                 }
1264                                 if (flag)
1265                                         break;
1266                         }
1267                         Assert.AreEqual(true, flag, "#GS18 failed");
1268                 }
1269
1270                 [Test]
1271                 [ExpectedException (typeof (ArgumentException))]
1272                 public void GetSchemaTest19 ()
1273                 {
1274                         String [] restrictions = new String[1];
1275                         conn.GetSchema("RESTRICTIONS", restrictions);
1276                 }
1277
1278                 [Test]
1279                 public void GetSchemaTest20 ()
1280                 {
1281                         bool flag = false;
1282                         DataTable tab1 = conn.GetSchema("DataTypes");
1283                         foreach (DataRow row in tab1.Rows)
1284                         {
1285                                 foreach (DataColumn col in tab1.Columns)
1286                                 {
1287                                         /*
1288                                          * We need to consider multiple values
1289                                          */
1290                                         if (col.ColumnName.ToString() == "TypeName" && row[col].ToString() == "uniqueidentifier")
1291                                         {
1292                                                 flag = true;
1293                                                 break;
1294                                         }
1295                                 }
1296                                 if (flag)
1297                                         break;
1298                         }
1299                         Assert.AreEqual(true, flag, "#GS20 failed");
1300                 }
1301
1302                 [Test]
1303                 public void GetSchemaTest21()
1304                 {
1305                         bool flag = false;
1306                         DataTable tab1 = conn.GetSchema();
1307                         foreach (DataRow row in tab1.Rows)
1308                         {
1309                                 foreach (DataColumn col in tab1.Columns)
1310                                 {
1311                                         /*
1312                                          * We need to consider multiple values
1313                                          */
1314                                         if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
1315                                         {
1316                                                 flag = true;
1317                                                 break;
1318                                         }
1319                                 }
1320                                 if (flag)
1321                                         break;
1322                         }
1323                         Assert.AreEqual(true, flag, "#GS21 failed");
1324                 }
1325                 [Test]
1326                 public void GetSchemaTest22()
1327                 {
1328                         bool flag = false;
1329                         DataTable tab1 = conn.GetSchema("ReservedWords");
1330                         foreach (DataRow row in tab1.Rows)
1331                         {
1332                                 foreach (DataColumn col in tab1.Columns)
1333                                 {
1334                                         /*
1335                                          * We need to consider multiple values
1336                                          */
1337                                         if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "UPPER")
1338                                         {
1339                                                 flag = true;
1340                                                 break;
1341                                         }
1342                                 }
1343                                 if (flag)
1344                                         break;
1345                         }
1346                         Assert.AreEqual(true, flag, "#GS22 failed");
1347                 }
1348
1349                 [Test]
1350                 public void GetSchemaTest23()
1351                 {
1352                         bool flag = false;
1353                         DataTable tab1 = conn.GetSchema("ReservedWords");
1354                         foreach (DataRow row in tab1.Rows)
1355                         {
1356                                 foreach (DataColumn col in tab1.Columns)
1357                                 {
1358                                         /*
1359                                          * We need to consider multiple values
1360                                          */
1361                                         if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "upper")
1362                                         {
1363                                                 flag = true;
1364                                                 break;
1365                                         }
1366                                 }
1367                                 if (flag)
1368                                         break;
1369                         }
1370                         Assert.AreEqual(false, flag, "#GS23 failed");
1371                 }
1372
1373                 [Test]
1374                 public void GetSchemaTest24()
1375                 {
1376                         bool flag = false;
1377                         string [] restrictions = new string[4];
1378
1379                         restrictions[0] = "monotest";
1380                         restrictions[1] = null;
1381                         restrictions[2] = "sp_get_age";
1382                         restrictions[3] = null;
1383                         DataTable tab1 = conn.GetSchema("Procedures", restrictions);
1384                         foreach (DataRow row in tab1.Rows)
1385                         {
1386                                 foreach (DataColumn col in tab1.Columns)
1387                                 {
1388                                         /*
1389                                          * We need to consider multiple values
1390                                          */
1391                                         if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "mono")
1392                                         {
1393                                                 flag = true;
1394                                                 break;
1395                                         }
1396                                 }
1397                                 if (flag)
1398                                         break;
1399                         }
1400                         Assert.AreEqual(false, flag, "#GS24 failed");
1401                 }
1402
1403                 [Test]
1404                 [ExpectedException (typeof (ArgumentException))]
1405                 public void GetSchemaTest25 ()
1406                 {
1407                         String [] restrictions = new String [1];
1408                         conn.GetSchema ("Mono", restrictions);
1409                 }
1410         }
1411 }