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