* DataReaderTest.cs: Added tests for GetChars, GetOrdinal,
[mono.git] / mcs / class / System.Data / Test / ProviderTests / ProviderIndependant / DataReaderTest.cs
1 // DataReaderTest.cs - NUnit Test Cases for testing the
2 // DataReader family of classes
3 //
4 // Authors:
5 //      Sureshkumar T (tsureshkumar@novell.com)
6 //      Gert Driesen (drieseng@users.sourceforge.net)
7 // 
8 // Copyright (c) 2004 Novell Inc., and the individuals listed on the
9 // ChangeLog entries.
10 //
11 // Permission is hereby granted, free of charge, to any person
12 // obtaining a copy of this software and associated documentation
13 // files (the "Software"), to deal in the Software without
14 // restriction, including without limitation the rights to use, copy,
15 // modify, merge, publish, distribute, sublicense, and/or sell copies
16 // of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26 // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 // SOFTWARE.
30
31 using System;
32 using System.Data;
33 using System.Data.Common;
34 using System.Data.Odbc;
35 using System.Data.SqlClient;
36 using System.Data.SqlTypes;
37 using System.Globalization;
38
39 using Mono.Data;
40
41 using NUnit.Framework;
42
43 namespace MonoTests.System.Data
44 {
45         [TestFixture]
46         [Category ("odbc")]
47         [Category ("sqlserver")]
48         public class DataReaderTest
49         {
50                 static byte [] long_bytes = new byte [] {
51                         0x00, 0x66, 0x06, 0x66, 0x97, 0x00, 0x66, 0x06, 0x66,
52                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
53                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
54                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
55                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
56                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
57                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
58                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
59                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
60                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
61                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
62                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
63                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
64                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
65                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
66                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
67                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
68                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
69                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
70                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
71                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
72                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
73                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
74                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
75                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
76                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
77                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
78                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
79                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
80                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
81                         0x06, 0x66, 0x06, 0x66, 0x98};
82
83                 IDbConnection conn;
84                 IDbCommand cmd;
85
86                 [SetUp]
87                 public void SetUp ()
88                 {
89                         conn = ConnectionManager.Singleton.Connection;
90                         ConnectionManager.Singleton.OpenConnection ();
91                         cmd = conn.CreateCommand ();
92                 }
93
94                 [TearDown]
95                 public void TearDown ()
96                 {
97                         if (cmd != null)
98                                 cmd.Dispose ();
99                         ConnectionManager.Singleton.CloseConnection ();
100                 }
101
102                 [Test]
103                 public void FieldCount ()
104                 {
105                         IDataReader reader = null;
106
107                         try {
108                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
109                                 reader = cmd.ExecuteReader ();
110                                 Assert.AreEqual (6, reader.FieldCount);
111                         } finally {
112                                 if (reader != null)
113                                         reader.Close ();
114                         }
115                 }
116
117                 [Test]
118                 public void FieldCount_Command_Disposed ()
119                 {
120                         IDataReader reader = null;
121
122                         try {
123                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
124                                 reader = cmd.ExecuteReader ();
125                                 cmd.Dispose ();
126                                 Assert.AreEqual (6, reader.FieldCount);
127                         } finally {
128                                 if (reader != null)
129                                         reader.Close ();
130                         }
131                 }
132
133                 [Test]
134                 public void FieldCount_Reader_Closed ()
135                 {
136                         IDataReader reader = null;
137
138                         try {
139                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
140                                 reader = cmd.ExecuteReader ();
141                                 reader.Close ();
142                                 try {
143                                         int fieldcount = reader.FieldCount;
144                                         Assert.Fail ("#1:" + fieldcount);
145                                 } catch (InvalidOperationException ex) {
146                                         // Invalid attempt to FieldCount when
147                                         // reader is closed
148                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
149                                         Assert.IsNull (ex.InnerException, "#3");
150                                         Assert.IsNotNull (ex.Message, "#4");
151                                 }
152                         } finally {
153                                 if (reader != null)
154                                         reader.Close ();
155                         }
156                 }
157
158                 [Test]
159                 public void GetChars_Index_Invalid ()
160                 {
161                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
162
163                         using (IDataReader rdr = cmd.ExecuteReader ()) {
164                                 Assert.IsTrue (rdr.Read ());
165
166                                 try {
167                                         rdr.GetChars (-1, 0, (char []) null, 0, 0);
168                                         Assert.Fail ("#A1");
169                                 } catch (IndexOutOfRangeException ex) {
170                                         // Index was outside the bounds of the array
171                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
172                                         Assert.IsNull (ex.InnerException, "#A3");
173                                         Assert.IsNotNull (ex.Message, "#A4");
174                                 }
175
176                                 try {
177                                         rdr.GetChars (1, 0, (char []) null, 0, 0);
178                                         Assert.Fail ("#B1");
179                                 } catch (IndexOutOfRangeException ex) {
180                                         // Index was outside the bounds of the array
181                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
182                                         Assert.IsNull (ex.InnerException, "#B3");
183                                         Assert.IsNotNull (ex.Message, "#B4");
184                                 }
185                         }
186
187                         using (IDataReader rdr = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
188                                 Assert.IsTrue (rdr.Read ());
189
190                                 try {
191                                         rdr.GetChars (-1, 0, (char []) null, 0, 0);
192                                         Assert.Fail ("#C1");
193                                 } catch (IndexOutOfRangeException ex) {
194                                         // Index was outside the bounds of the array
195                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#C2");
196                                         Assert.IsNull (ex.InnerException, "#C3");
197                                         Assert.IsNotNull (ex.Message, "#C4");
198                                 }
199
200                                 try {
201                                         rdr.GetChars (1, 0, (char []) null, 0, 0);
202                                         Assert.Fail ("#D1");
203                                 } catch (IndexOutOfRangeException ex) {
204                                         // Index was outside the bounds of the array
205                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#D2");
206                                         Assert.IsNull (ex.InnerException, "#D3");
207                                         Assert.IsNotNull (ex.Message, "#D4");
208                                 }
209                         }
210                 }
211
212                 [Test]
213                 public void GetChars_Reader_Closed ()
214                 {
215                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
216
217                         using (IDataReader rdr = cmd.ExecuteReader ()) {
218                                 Assert.IsTrue (rdr.Read ());
219                                 rdr.Close ();
220
221                                 try {
222                                         rdr.GetChars (-1, 0, (char []) null, 0, 0);
223                                         Assert.Fail ("#A1");
224                                 } catch (InvalidOperationException ex) {
225                                         // No data exists for the row/column
226                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
227                                         Assert.IsNull (ex.InnerException, "#A3");
228                                         Assert.IsNotNull (ex.Message, "#A4");
229                                 }
230                         }
231
232                         using (IDataReader rdr = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
233                                 Assert.IsTrue (rdr.Read ());
234                                 rdr.Close ();
235
236                                 try {
237                                         rdr.GetChars (-1, 0, (char []) null, 0, 0);
238                                         Assert.Fail ("#B1");
239                                 } catch (InvalidOperationException ex) {
240                                         // No data exists for the row/column
241                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
242                                         Assert.IsNull (ex.InnerException, "#B3");
243                                         Assert.IsNotNull (ex.Message, "#B4");
244                                 }
245                         }
246                 }
247
248                 [Test]
249                 public void GetChars_Reader_NoData ()
250                 {
251                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 666";
252
253                         using (IDataReader rdr = cmd.ExecuteReader ()) {
254                                 try {
255                                         rdr.GetChars (-1, 0, (char []) null, 0, 0);
256                                         Assert.Fail ("#A1");
257                                 } catch (InvalidOperationException ex) {
258                                         // No data exists for the row/column
259                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
260                                         Assert.IsNull (ex.InnerException, "#A3");
261                                         Assert.IsNotNull (ex.Message, "#A4");
262                                 }
263
264                                 Assert.IsFalse (rdr.Read (), "#B");
265
266                                 try {
267                                         rdr.GetChars (-1, 0, (char []) null, 0, 0);
268                                         Assert.Fail ("#C1");
269                                 } catch (InvalidOperationException ex) {
270                                         // No data exists for the row/column
271                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
272                                         Assert.IsNull (ex.InnerException, "#C3");
273                                         Assert.IsNotNull (ex.Message, "#C4");
274                                 }
275                         }
276                 }
277
278                 [Test]
279                 public void GetDataTypeName ()
280                 {
281                         IDataReader reader = null;
282
283                         try {
284                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
285                                 reader = cmd.ExecuteReader ();
286
287                                 switch (ConnectionManager.Singleton.Engine.Type) {
288                                 case EngineType.SQLServer:
289                                         Assert.AreEqual ("int", reader.GetDataTypeName (0), "#1");
290                                         break;
291                                 case EngineType.MySQL:
292                                         Assert.AreEqual ("integer", reader.GetDataTypeName (0), "#1");
293                                         break;
294                                 default:
295                                         Assert.Fail ("Engine type not supported.");
296                                         break;
297                                 }
298                                 Assert.AreEqual ("varchar", reader.GetDataTypeName (1), "#2");
299                                 Assert.AreEqual ("varchar", reader.GetDataTypeName (2), "#3");
300                                 Assert.AreEqual ("datetime", reader.GetDataTypeName (3), "#4");
301                                 Assert.AreEqual ("datetime", reader.GetDataTypeName (4), "#5");
302                                 Assert.AreEqual ("varchar", reader.GetDataTypeName (5), "#6");
303                         } finally {
304                                 if (reader != null)
305                                         reader.Close ();
306                         }
307                 }
308
309                 [Test]
310                 public void GetDataTypeName_Index_Invalid ()
311                 {
312                         IDataReader reader = null;
313
314                         try {
315                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
316                                 reader = cmd.ExecuteReader ();
317
318                                 try {
319                                         reader.GetDataTypeName (-1);
320                                         Assert.Fail ("#A1");
321                                 } catch (IndexOutOfRangeException ex) {
322                                         // Index was outside the bounds of the array
323                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
324                                         Assert.IsNull (ex.InnerException, "#A3");
325                                         Assert.IsNotNull (ex.Message, "#A4");
326                                 }
327
328                                 try {
329                                         reader.GetDataTypeName (6);
330                                         Assert.Fail ("#B1");
331                                 } catch (IndexOutOfRangeException ex) {
332                                         // Index was outside the bounds of the array
333                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
334                                         Assert.IsNull (ex.InnerException, "#B3");
335                                         Assert.IsNotNull (ex.Message, "#B4");
336                                 }
337                         } finally {
338                                 if (reader != null)
339                                         reader.Close ();
340                         }
341                 }
342
343                 [Test]
344                 public void GetDataTypeName_Reader_Closed ()
345                 {
346                         IDataReader reader = null;
347
348                         try {
349                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
350                                 reader = cmd.ExecuteReader ();
351                                 reader.Close ();
352
353                                 try {
354                                         reader.GetDataTypeName (0);
355                                         Assert.Fail ("#1");
356                                 } catch (InvalidOperationException ex) {
357                                         // No data exists for the row/column
358                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
359                                         Assert.IsNull (ex.InnerException, "#3");
360                                         Assert.IsNotNull (ex.Message, "#4");
361                                 }
362                         } finally {
363                                 if (reader != null)
364                                         reader.Close ();
365                         }
366                 }
367
368                 [Test]
369                 public void GetFieldType ()
370                 {
371                         IDataReader reader = null;
372
373                         try {
374                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
375                                 reader = cmd.ExecuteReader ();
376                                 Assert.AreEqual (typeof (int), reader.GetFieldType (0), "#1");
377                                 Assert.AreEqual (typeof (string), reader.GetFieldType (2), "#2");
378                                 Assert.AreEqual (typeof (DateTime), reader.GetFieldType (4), "#3");
379                         } finally {
380                                 if (reader != null)
381                                         reader.Close ();
382                         }
383                 }
384
385                 [Test]
386                 public void GetFieldType_Index_Invalid ()
387                 {
388                         IDataReader reader = null;
389
390                         try {
391                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
392                                 reader = cmd.ExecuteReader ();
393                                 try {
394                                         reader.GetFieldType (-1);
395                                         Assert.Fail ("#A1");
396                                 } catch (IndexOutOfRangeException ex) {
397                                         // Index was outside the bounds of the array
398                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
399                                         Assert.IsNull (ex.InnerException, "#A3");
400                                         Assert.IsNotNull (ex.Message, "#A4");
401                                 }
402
403                                 try {
404                                         reader.GetFieldType (6);
405                                         Assert.Fail ("#B1");
406                                 } catch (IndexOutOfRangeException ex) {
407                                         // Index was outside the bounds of the array
408                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
409                                         Assert.IsNull (ex.InnerException, "#B3");
410                                         Assert.IsNotNull (ex.Message, "#B4");
411                                 }
412                         } finally {
413                                 if (reader != null)
414                                         reader.Close ();
415                         }
416                 }
417
418                 [Test]
419                 public void GetFieldType_Reader_Closed ()
420                 {
421                         IDataReader reader = null;
422
423                         try {
424                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
425                                 reader = cmd.ExecuteReader ();
426                                 reader.Close ();
427                                 try {
428                                         reader.GetFieldType (0);
429                                         Assert.Fail ("#1");
430                                 } catch (InvalidOperationException ex) {
431                                         // No data exists for the row/column
432                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
433                                         Assert.IsNull (ex.InnerException, "#3");
434                                         Assert.IsNotNull (ex.Message, "#4");
435                                 }
436                         } finally {
437                                 if (reader != null)
438                                         reader.Close ();
439                         }
440                 }
441
442                 [Test]
443                 public void GetName ()
444                 {
445                         IDataReader reader = null;
446
447                         try {
448                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
449                                 reader = cmd.ExecuteReader ();
450                                 Assert.AreEqual ("id", reader.GetName (0), "#1");
451                                 Assert.AreEqual ("fname", reader.GetName (1), "#2");
452                                 Assert.AreEqual ("lname", reader.GetName (2), "#3");
453                                 Assert.AreEqual ("dob", reader.GetName (3), "#4");
454                                 Assert.AreEqual ("doj", reader.GetName (4), "#5");
455                                 Assert.AreEqual ("email", reader.GetName (5), "#6");
456                         } finally {
457                                 if (reader != null)
458                                         reader.Close ();
459                         }
460                 }
461
462                 [Test]
463                 public void GetName_Index_Invalid ()
464                 {
465                         IDataReader reader = null;
466
467                         try {
468                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
469                                 reader = cmd.ExecuteReader ();
470                                 try {
471                                         reader.GetName (-1);
472                                         Assert.Fail ("#A1");
473                                 } catch (IndexOutOfRangeException ex) {
474                                         // Index was outside the bounds of the array
475                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
476                                         Assert.IsNull (ex.InnerException, "#A3");
477                                         Assert.IsNotNull (ex.Message, "#A4");
478                                 }
479
480                                 try {
481                                         reader.GetName (6);
482                                         Assert.Fail ("#B1");
483                                 } catch (IndexOutOfRangeException ex) {
484                                         // Index was outside the bounds of the array
485                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
486                                         Assert.IsNull (ex.InnerException, "#B3");
487                                         Assert.IsNotNull (ex.Message, "#B4");
488                                 }
489                         } finally {
490                                 if (reader != null)
491                                         reader.Close ();
492                         }
493                 }
494
495                 [Test]
496                 public void GetName_Reader_Closed ()
497                 {
498                         IDataReader reader = null;
499
500                         try {
501                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
502                                 reader = cmd.ExecuteReader ();
503                                 reader.Close ();
504                                 try {
505                                         reader.GetName (0);
506                                         Assert.Fail ("#1");
507                                 } catch (InvalidOperationException ex) {
508                                         // No data exists for the row/column
509                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
510                                         Assert.IsNull (ex.InnerException, "#3");
511                                         Assert.IsNotNull (ex.Message, "#4");
512                                 }
513                         } finally {
514                                 if (reader != null)
515                                         reader.Close ();
516                         }
517                 }
518
519                 [Test]
520                 public void GetOrdinal ()
521                 {
522                         IDataReader reader = null;
523
524                         try {
525                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
526                                 reader = cmd.ExecuteReader ();
527                                 Assert.AreEqual (0, reader.GetOrdinal ("id"), "#1");
528                                 Assert.AreEqual (1, reader.GetOrdinal ("fname"), "#2");
529                                 Assert.AreEqual (2, reader.GetOrdinal ("lname"), "#3");
530                                 Assert.AreEqual (3, reader.GetOrdinal ("doB"), "#4");
531                                 Assert.AreEqual (4, reader.GetOrdinal ("doj"), "#5");
532                                 Assert.AreEqual (5, reader.GetOrdinal ("EmaiL"), "#6");
533                                 Assert.AreEqual (0, reader.GetOrdinal ("iD"), "#7");
534                                 Assert.AreEqual (5, reader.GetOrdinal ("eMail"), "#8");
535                         } finally {
536                                 if (reader != null)
537                                         reader.Close ();
538                         }
539                 }
540
541                 [Test]
542                 public void GetOrdinal_Name_DoesNotExist ()
543                 {
544                         IDataReader reader = null;
545
546                         try {
547                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
548                                 reader = cmd.ExecuteReader ();
549                                 try {
550                                         reader.GetOrdinal ("non_existing_column");
551                                         Assert.Fail ("#A1");
552                                 } catch (IndexOutOfRangeException ex) {
553                                         // Index was outside the bounds of the array
554                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
555                                         Assert.IsNull (ex.InnerException, "#A3");
556                                         Assert.IsNotNull (ex.Message, "#A4");
557                                 }
558
559                                 try {
560                                         reader.GetOrdinal (string.Empty);
561                                         Assert.Fail ("#B1");
562                                 } catch (IndexOutOfRangeException ex) {
563                                         // Index was outside the bounds of the array
564                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
565                                         Assert.IsNull (ex.InnerException, "#B3");
566                                         Assert.IsNotNull (ex.Message, "#B4");
567                                 }
568                         } finally {
569                                 if (reader != null)
570                                         reader.Close ();
571                         }
572                 }
573
574                 [Test]
575                 public void GetOrdinal_Name_Null ()
576                 {
577                         IDataReader reader = null;
578
579                         try {
580                                 cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
581                                 reader = cmd.ExecuteReader ();
582                                 try {
583                                         reader.GetOrdinal (null);
584                                         Assert.Fail ("#1");
585                                 } catch (ArgumentNullException ex) {
586                                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
587                                         Assert.IsNull (ex.InnerException, "#3");
588                                         Assert.IsNotNull (ex.Message, "#4");
589                                         Assert.AreEqual ("fieldName", ex.ParamName, "#5");
590                                 }
591                         } finally {
592                                 if (reader != null)
593                                         reader.Close ();
594                         }
595                 }
596
597                 [Test]
598                 public void GetOrdinal_Reader_Closed ()
599                 {
600                         cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
601
602                         using (IDataReader rdr = cmd.ExecuteReader ()) {
603                                 rdr.Close ();
604
605                                 try {
606                                         rdr.GetOrdinal (null);
607                                         Assert.Fail ("#A1");
608                                 } catch (InvalidOperationException ex) {
609                                         // No data exists for the row/column
610                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
611                                         Assert.IsNull (ex.InnerException, "#A3");
612                                         Assert.IsNotNull (ex.Message, "#A4");
613                                 }
614                         }
615                 }
616
617                 [Test]
618                 public void GetOrdinal_Reader_NoData ()
619                 {
620                         cmd.CommandText = "SELECT * FROM employee WHERE id = 666";
621
622                         using (IDataReader rdr = cmd.ExecuteReader ()) {
623                                 Assert.AreEqual (0, rdr.GetOrdinal ("id"), "#A1");
624                                 Assert.AreEqual (5, rdr.GetOrdinal ("eMail"), "#A2");
625
626                                 Assert.IsFalse (rdr.Read (), "#B");
627
628                                 Assert.AreEqual (2, rdr.GetOrdinal ("lname"), "#C1");
629                                 Assert.AreEqual (3, rdr.GetOrdinal ("dob"), "#C2");
630                         }
631                 }
632
633                 [Test]
634                 public void GetSchemaTable_Command_Disposed ()
635                 {
636                         if (RunningOnMono && (conn is OdbcConnection))
637                                 Assert.Ignore ("Our statement handle is closed when we dispose the (Odbc)Command");
638
639                         IDataReader reader = null;
640
641                         try {
642                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
643                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
644                                 cmd.Dispose ();
645                                 DataTable schema = reader.GetSchemaTable ();
646                                 Assert.AreEqual (3, schema.Rows.Count, "RowCount");
647                         } finally {
648                                 if (reader != null)
649                                         reader.Close ();
650                         }
651                 }
652
653                 [Test]
654                 public void GetSchemaTable_Reader_Closed ()
655                 {
656                         IDataReader reader = null;
657
658                         try {
659                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
660                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
661                                 reader.Close ();
662
663                                 try {
664                                         reader.GetSchemaTable ();
665                                         Assert.Fail ("#1");
666                                 } catch (InvalidOperationException ex) {
667                                         // Invalid attempt to call GetSchemaTable
668                                         // when reader is closed
669                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
670                                         Assert.IsNull (ex.InnerException, "#3");
671                                         Assert.IsNotNull (ex.Message, "#4");
672                                 }
673                         } finally {
674                                 if (reader != null)
675                                         reader.Close ();
676                         }
677                 }
678
679                 [Test]
680                 public void GetNameTest ()
681                 {
682                         cmd.CommandText = "SELECT type_tinyint from numeric_family"; ;
683                         using (IDataReader reader = cmd.ExecuteReader ()) {
684                                 Assert.AreEqual ("type_tinyint", reader.GetName (0), "#1");
685                         }
686                 }
687
688                 [Test]
689                 public void IsClosed_Command_Disposed ()
690                 {
691                         IDataReader reader = null;
692
693                         try {
694                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
695                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
696                                 Assert.IsFalse (reader.IsClosed, "#1");
697                                 cmd.Dispose ();
698                                 Assert.IsFalse (reader.IsClosed, "#2");
699                         } finally {
700                                 if (reader != null)
701                                         reader.Close ();
702                         }
703                 }
704
705                 [Test]
706                 public void IsClosed_Connection_Closed ()
707                 {
708                         if (RunningOnMono)
709                                 Assert.Ignore ("We do not mark the corresponding Reader closed when we close a Connection.");
710
711                         IDataReader reader = null;
712
713                         try {
714                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
715                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
716                                 Assert.IsFalse (reader.IsClosed, "#1");
717                                 ConnectionManager.Singleton.CloseConnection ();
718                                 Assert.IsTrue (reader.IsClosed, "#2");
719                         } finally {
720                                 if (reader != null)
721                                         reader.Close ();
722                         }
723                 }
724
725                 [Test]
726                 public void IsClosed_Reader_Closed ()
727                 {
728                         IDataReader reader = null;
729
730                         try {
731                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
732                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
733                                 Assert.IsFalse (reader.IsClosed, "#1");
734                                 reader.Close ();
735                                 Assert.IsTrue (reader.IsClosed, "#2");
736                         } finally {
737                                 if (reader != null)
738                                         reader.Close ();
739                         }
740                 }
741
742                 [Test]
743                 public void NumericTest()
744                 {
745                         cmd.CommandText = "select type_numeric1 from numeric_family where id = 1;";
746
747                         using (IDataReader reader = cmd.ExecuteReader ()) {
748                                 Assert.IsTrue (reader.Read(), "#1");
749                                 object value = reader.GetValue (0);
750                                 Assert.AreEqual (typeof (decimal), value.GetType (), "#2");
751                                 Assert.AreEqual (1000m, value, "#3");
752                         }
753                 }
754
755                 [Test]
756                 public void TinyIntTest ()
757                 {
758                         cmd.CommandText = "select type_tinyint from numeric_family where id = 1;";
759                         using (IDataReader reader = cmd.ExecuteReader ()) {
760                                 Assert.IsTrue (reader.Read (), "#1");
761                                 object value = reader.GetValue (0);
762                                 Assert.AreEqual (typeof (byte), value.GetType (), "#2");
763                                 Assert.AreEqual (255, value, "#3");
764                         }
765                 }
766                 
767                 [Test]
768                 public void GetByteTest () 
769                 {
770                         cmd.CommandText = "select type_tinyint from numeric_family where id = 1";
771                         using (IDataReader reader = cmd.ExecuteReader ()) {
772                                 Assert.IsTrue (reader.Read (), "#1");
773                                 byte b = reader.GetByte (0);
774                                 Assert.AreEqual (255, b, "#2");
775                         }
776                 }
777
778                 [Test]
779                 public void GetValue_Reader_Closed ()
780                 {
781                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
782
783                         using (IDataReader reader = cmd.ExecuteReader ()) {
784                                 Assert.IsTrue (reader.Read ());
785                                 reader.Close ();
786
787                                 try {
788                                         reader.GetValue (-1);
789                                         Assert.Fail ("#1");
790                                 } catch (InvalidOperationException ex) {
791                                         // No data exists for the row/column
792                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
793                                         Assert.IsNull (ex.InnerException, "#3");
794                                         Assert.IsNotNull (ex.Message, "#4");
795                                 }
796                         }
797                 }
798
799                 [Test]
800                 public void GetValue_Reader_NoData ()
801                 {
802                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 666";
803
804                         using (IDataReader rdr = cmd.ExecuteReader ()) {
805                                 try {
806                                         rdr.GetValue (-1);
807                                         Assert.Fail ("#A1");
808                                 } catch (InvalidOperationException ex) {
809                                         // No data exists for the row/column
810                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
811                                         Assert.IsNull (ex.InnerException, "#A3");
812                                         Assert.IsNotNull (ex.Message, "#A4");
813                                 }
814
815                                 Assert.IsFalse (rdr.Read (), "#B");
816
817                                 try {
818                                         rdr.GetValue (-1);
819                                         Assert.Fail ("#C1");
820                                 } catch (InvalidOperationException ex) {
821                                         // No data exists for the row/column
822                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
823                                         Assert.IsNull (ex.InnerException, "#C3");
824                                         Assert.IsNotNull (ex.Message, "#C4");
825                                 }
826                         }
827                 }
828
829                 [Test]
830                 public void GetValueBinaryTest ()
831                 {
832                         cmd.CommandText = "select type_binary from binary_family where id = 1";
833                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
834                                 Assert.IsTrue (reader.Read (), "#1");
835                                 object ob = reader.GetValue (0);
836                                 Assert.IsNotNull (ob, "#2");
837                                 Assert.AreEqual (typeof (byte []), ob.GetType (), "#3");
838                         }
839                 }
840                 
841                 [Test]
842                 public void GetBytes ()
843                 {
844                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
845
846                         CommandBehavior behavior;
847
848                         behavior = CommandBehavior.SingleResult | CommandBehavior.SequentialAccess;
849                         using (IDataReader reader = cmd.ExecuteReader (behavior)) {
850                                 Assert.IsTrue (reader.Read (), "#A1");
851
852                                 // Get By Parts for the column blob
853                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
854                                 int buffsize = 3;
855                                 int offset = 0;
856                                 long ret = 0;
857                                 long count = 0;
858                                 byte [] val = new byte [totalsize];
859                                 do {
860                                         ret = reader.GetBytes (0, offset, val, offset,
861                                                 (int) Math.Min (buffsize, totalsize - count));
862                                         offset += (int) ret;
863                                         count += ret;
864                                 } while (count < totalsize);
865
866                                 Assert.AreEqual (5, count, "#A2");
867                                 Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#A3");
868                         }
869
870                         behavior = CommandBehavior.SingleResult;
871                         using (IDataReader reader = cmd.ExecuteReader (behavior)) {
872                                 Assert.IsTrue (reader.Read (), "#B1");
873
874                                 // Get By Parts for the column blob
875                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
876                                 int buffsize = 3;
877                                 int offset = 0;
878                                 long ret = 0;
879                                 long count = 0;
880                                 byte [] val = new byte [totalsize];
881                                 do {
882                                         ret = reader.GetBytes (0, offset, val, offset,
883                                                 (int) Math.Min (buffsize, totalsize - count));
884                                         offset += (int) ret;
885                                         count += ret;
886                                 } while (count < totalsize);
887
888                                 Assert.AreEqual (5, count, "#B2");
889                                 Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#B3");
890                         }
891
892                         behavior = CommandBehavior.SingleResult;
893                         using (IDataReader reader = cmd.ExecuteReader (behavior)) {
894                                 Assert.IsTrue (reader.Read (), "#D1");
895
896                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
897
898                                 byte [] val = new byte [totalsize];
899                                 long ret = reader.GetBytes (0, 0L, val, 0, (int) (totalsize * 2));
900                                 Assert.AreEqual (totalsize, ret, "#D2");
901                                 Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#D3");
902                         }
903
904                         /* FIXME: dataIndex is currently ignored */
905                         /*
906                         behavior = CommandBehavior.SingleResult | CommandBehavior.SequentialAccess;
907                         using (IDataReader reader = cmd.ExecuteReader (behavior)) {
908                                 Assert.IsTrue (reader.Read (), "#E1");
909
910                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
911
912                                 int bufferIndex = 3;
913                                 long ret = 0L;
914                                 byte [] val = new byte [totalsize + bufferIndex];
915                                 for (int i = 0; i < val.Length; i++)
916                                         val [i] = 0x0a;
917                                 ret = reader.GetBytes (0, 1L, val, bufferIndex, (int) (totalsize - 2));
918                                 Assert.AreEqual (3, ret, "#E2");
919                                 Assert.AreEqual (new byte [] { 0x0a, 0x0a, 0x0a, 0x56, 0x00, 0x44, 0x0a, 0x0a }, val, "#E3");
920                                 try {
921                                         reader.GetBytes (0, 3L, val, 1, 2);
922                                         Assert.Fail ("#E4");
923                                 } catch (InvalidOperationException ex) {
924                                         // Invalid GetBytes attempt at dataIndex '3'.
925                                         // With CommandBehavior.SequentialAccess, you
926                                         // may only read from dataIndex '4' or greater
927                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E5");
928                                         Assert.IsNull (ex.InnerException, "#E6");
929                                         Assert.IsNotNull (ex.Message, "#E7");
930                                         Assert.IsTrue (ex.Message.IndexOf ("CommandBehavior.SequentialAccess") != -1, "#E8:" + ex.Message);
931                                         Assert.IsTrue (ex.Message.IndexOf ("'" + 3L.ToString (CultureInfo.InvariantCulture) + "'") != -1, "#E9:" + ex.Message);
932                                         Assert.IsTrue (ex.Message.IndexOf ("'" + 4L.ToString (CultureInfo.InvariantCulture) + "'") != -1, "#E10:" + ex.Message);
933                                 }
934
935                                 ret = reader.GetBytes (0, 4L, val, bufferIndex + 4, 2);
936                                 Assert.AreEqual (1, ret, "#E11");
937                                 Assert.AreEqual (new byte [] { 0x0a, 0x0a, 0x0a, 0x56, 0x00, 0x44, 0x0a, 0x22 }, val, "#E12");
938                         }
939
940                         behavior = CommandBehavior.SingleResult;
941                         using (IDataReader reader = cmd.ExecuteReader (behavior)) {
942                                 Assert.IsTrue (reader.Read (), "#F1");
943
944                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
945
946                                 int bufferIndex = 3;
947                                 long ret = 0L;
948                                 byte [] val = new byte [totalsize + bufferIndex];
949                                 for (int i = 0; i < val.Length; i++)
950                                         val [i] = 0x0a;
951                                 ret = reader.GetBytes (0, 1L, val, bufferIndex, (int) (totalsize - 2));
952                                 Assert.AreEqual (3, ret, "#F2");
953                                 Assert.AreEqual (new byte [] { 0x0a, 0x0a, 0x0a, 0x56, 0x00, 0x44, 0x0a, 0x0a }, val, "#F3");
954                                 ret = reader.GetBytes (0, 3L, val, 1, 2);
955                                 Assert.AreEqual (2, ret, "#F4");
956                                 Assert.AreEqual (new byte [] { 0x0a, 0x44, 0x22, 0x56, 0x00, 0x44, 0x0a, 0x0a }, val, "#F5");
957                         }
958                         */
959                 }
960
961                 [Test]
962                 public void GetBytes_Buffer_Null ()
963                 {
964                         cmd.CommandText = "SELECT type_blob FROM binary_family where id in (1,2,3,4) order by id";
965
966                         conn.Close ();
967                         conn = ConnectionManager.Singleton.Connection;
968                         ConnectionManager.Singleton.OpenConnection ();
969
970                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
971                                 Console.WriteLine ("A");
972                                 Assert.IsTrue (reader.Read (), "#A1");
973                                 Console.WriteLine ("B");
974                                 Assert.AreEqual (5, reader.GetBytes (0, 0, null, 0, 0), "#A2");
975                                 Console.WriteLine ("C");
976                                 Assert.IsTrue (reader.Read (), "#B1");
977                                 Assert.AreEqual (275, reader.GetBytes (0, 0, null, 0, 0), "#B2");
978
979                                 Assert.IsTrue (reader.Read (), "#C1");
980                                 Assert.AreEqual (0, reader.GetBytes (0, 0, null, 0, 0), "#C2");
981
982                                 Assert.IsTrue (reader.Read (), "#D1");
983                                 if (conn is SqlConnection) {
984 #if NET_2_0
985                                         try {
986                                                 reader.GetBytes (0, 0, null, 0, 0);
987                                                 Assert.Fail ("#D2");
988                                         } catch (SqlNullValueException ex) {
989                                                 // Data is Null. This method or
990                                                 // property cannot be called on
991                                                 // Null values
992                                                 Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "#D3");
993                                                 Assert.IsNull (ex.InnerException, "#D4");
994                                                 Assert.IsNotNull (ex.Message, "#D5");
995                                         }
996 #else
997                                         Assert.AreEqual (0, reader.GetBytes (0, 0, null, 0, 0), "#D2");
998 #endif
999                                 } else {
1000                                         Assert.AreEqual (-1, reader.GetBytes (0, 0, null, 0, 0), "#D2");
1001                                 }
1002                         }
1003                 }
1004
1005                 [Test]
1006                 public void GetBytes_DataIndex_OffSet ()
1007                 {
1008                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
1009
1010                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
1011                                 Assert.IsTrue (reader.Read ());
1012
1013                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
1014                                 byte [] val = new byte [totalsize];
1015                                 long ret;
1016
1017                                 // start reading at index 0
1018                                 ret = reader.GetBytes (0, 0, val, 0, 5);
1019                                 Assert.AreEqual (5, ret, "#A1");
1020                                 for (int i = 0; i < ret; i++)
1021                                         Assert.AreEqual (long_bytes [i], val [i], "#A2:" + i);
1022                                 Assert.AreEqual (0x00, val [5], "#A3");
1023
1024                                 // attempt to read data prior to current pointer
1025                                 try {
1026                                         reader.GetBytes (0, 4, val, 0, 5);
1027                                         Assert.Fail ("#B1");
1028                                 } catch (InvalidOperationException ex) {
1029                                         // Invalid GetBytes attempt at dataIndex '4'
1030                                         // With CommandBehavior.SequentialAccess,
1031                                         // you may only read from dataIndex '5'
1032                                         // or greater.
1033                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1034                                         Assert.IsNull (ex.InnerException, "#B3");
1035                                         Assert.IsNotNull (ex.Message, "#B4");
1036                                         Assert.IsTrue (ex.Message.IndexOf ("'4'") != -1, "#B5:" + ex.Message);
1037                                         Assert.IsTrue (ex.Message.IndexOf ("'5'") != -1, "#B6:" + ex.Message);
1038                                 }
1039
1040                                 // continue reading at current pointer
1041                                 ret = reader.GetBytes (0, 5, val, 5, 6);
1042                                 Assert.AreEqual (6, ret, "#C1");
1043                                 for (int i = 0; i < 11; i++)
1044                                         Assert.AreEqual (long_bytes [i], val [i], "#C2:" + i);
1045                                 Assert.AreEqual (0x00, val [11], "#C3");
1046
1047                                 // skip 4 characters
1048                                 ret = reader.GetBytes (0, 15, val, 13, (val.Length - 13));
1049                                 Assert.AreEqual (260, ret, "#D1");
1050                                 for (int i = 0; i < 11; i++)
1051                                         Assert.AreEqual (long_bytes [i], val [i], "#D2:" + i);
1052                                 for (int i = 11; i < 13; i++)
1053                                         Assert.AreEqual (0x00, val [i], "#D3:" + i);
1054                                 for (int i = 13; i < (totalsize - 4); i++)
1055                                         Assert.AreEqual (long_bytes [i + 2], val [i], "#D4:" + i);
1056                         }
1057
1058                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
1059                                 Assert.IsTrue (reader.Read ());
1060
1061                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
1062                                 byte [] val = new byte [totalsize];
1063                                 long ret;
1064
1065                                 int offset = (int) totalsize - 5;
1066                                 int buffer_offset = 7;
1067
1068                                 // start reading at a specific position
1069                                 ret = reader.GetBytes (0, offset, val, buffer_offset,
1070                                         val.Length - buffer_offset);
1071                                 Assert.AreEqual (5, ret, "#E1");
1072                                 for (int i = 0; i < buffer_offset; i++)
1073                                         Assert.AreEqual (0x00, val [i], "#E2:" + i);
1074                                 for (int i = 0; i < ret; i++)
1075                                         Assert.AreEqual (long_bytes [offset + i], val [buffer_offset + i], "#E3:" + i);
1076                                 for (int i = (buffer_offset + (int) ret); i < val.Length; i++)
1077                                         Assert.AreEqual (0x00, val [i], "#E4:" + i);
1078                         }
1079                 }
1080
1081                 [Test]
1082                 public void GetBytes_Reader_Closed ()
1083                 {
1084                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
1085
1086                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
1087                                 Assert.IsTrue (reader.Read (), "#1");
1088                                 reader.Close ();
1089
1090                                 try {
1091                                         reader.GetBytes (0, 0, null, -1, 0);
1092                                         Assert.Fail ("#2");
1093                                 } catch (InvalidOperationException ex) {
1094                                         // No data exists for the row/column
1095                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
1096                                         Assert.IsNull (ex.InnerException, "#4");
1097                                         Assert.IsNotNull (ex.Message, "#5");
1098                                 }
1099                         }
1100                 }
1101
1102                 [Test]
1103                 public void GetBytes_Reader_NoData ()
1104                 {
1105                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
1106
1107                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
1108                                 try {
1109                                         reader.GetBytes (0, 0, null, -1, 0);
1110                                         Assert.Fail ("#2");
1111                                 } catch (InvalidOperationException ex) {
1112                                         // No data exists for the row/column
1113                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
1114                                         Assert.IsNull (ex.InnerException, "#4");
1115                                         Assert.IsNotNull (ex.Message, "#5");
1116                                 }
1117                         }
1118                 }
1119
1120                 [Test]
1121                 public void GetSchemaTableTest_AutoIncrement ()
1122                 {
1123                         cmd.CommandText = "select type_autoincrement from numeric_family";
1124                         cmd.ExecuteNonQuery ();
1125                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly)) {
1126                                 DataTable schemaTable = reader.GetSchemaTable ();
1127                                 Assert.IsTrue ((bool) schemaTable.Rows [0]["IsAutoIncrement"], "#1");
1128
1129                                 if (!RunningOnMono) {
1130                                         /* FIXME: we always set it to false */
1131                                         if (schemaTable.Columns.Contains ("IsIdentity"))
1132                                                 Assert.IsTrue ((bool) schemaTable.Rows [0] ["IsIdentity"], "#2");
1133                                 }
1134                         }
1135                 }
1136
1137                 [Test]
1138                 public void GetValues_Reader_Closed ()
1139                 {
1140                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
1141
1142                         using (IDataReader rdr = cmd.ExecuteReader ()) {
1143                                 Assert.IsTrue (rdr.Read ());
1144                                 rdr.Close ();
1145
1146                                 try {
1147                                         rdr.GetValues ((object []) null);
1148                                         Assert.Fail ("#1");
1149                                 } catch (InvalidOperationException ex) {
1150                                         // No data exists for the row/column
1151                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1152                                         Assert.IsNull (ex.InnerException, "#3");
1153                                         Assert.IsNotNull (ex.Message, "#4");
1154                                 }
1155                         }
1156                 }
1157
1158                 [Test]
1159                 public void GetValues_Reader_NoData ()
1160                 {
1161                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 666";
1162
1163                         using (IDataReader rdr = cmd.ExecuteReader ()) {
1164                                 try {
1165                                         rdr.GetValues ((object []) null);
1166                                         Assert.Fail ("#A1");
1167                                 } catch (InvalidOperationException ex) {
1168                                         // No data exists for the row/column
1169                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1170                                         Assert.IsNull (ex.InnerException, "#A3");
1171                                         Assert.IsNotNull (ex.Message, "#A4");
1172                                 }
1173
1174                                 Assert.IsFalse (rdr.Read (), "#B");
1175
1176                                 try {
1177                                         rdr.GetValues ((object []) null);
1178                                         Assert.Fail ("#C1");
1179                                 } catch (InvalidOperationException ex) {
1180                                         // No data exists for the row/column
1181                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
1182                                         Assert.IsNull (ex.InnerException, "#C3");
1183                                         Assert.IsNotNull (ex.Message, "#C4");
1184                                 }
1185                         }
1186                 }
1187
1188                 static bool RunningOnMono {
1189                         get {
1190                                 return (Type.GetType ("System.MonoType", false) != null);
1191                         }
1192                 }
1193         }
1194 }