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