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