context: // DataReaderTest.cs - NUnit Test Cases for testing the
  // DataReader family of classes
  //
  // Authors:
  //      Sureshkumar T (tsureshkumar@novell.com)
  //	Gert Driesen (drieseng@users.sourceforge.net)
  //	Veerapuram Varadhan  (vvaradhan@novell.com)
  // 
  // Copyright (c) 2004 Novell Inc., and the individuals listed on the
  // ChangeLog entries.
  //
  // Permission is hereby granted, free of charge, to any person
  // obtaining a copy of this software and associated documentation
  // files (the "Software"), to deal in the Software without
  // restriction, including without limitation the rights to use, copy,
  // modify, merge, publish, distribute, sublicense, and/or sell copies
  // of the Software, and to permit persons to whom the Software is
  // furnished to do so, subject to the following conditions:
  //
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  //
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  // SOFTWARE.
  
  using System;
  using System.Data;
  using System.Data.Common;
  using System.Data.Odbc;
  using System.Data.SqlClient;
  using System.Data.SqlTypes;
  using System.Globalization;
  using System.Text;
  
  using Mono.Data;
  
  using NUnit.Framework;
  
  namespace MonoTests.System.Data
  {
  	[TestFixture]
  	[Category ("odbc")]
  	[Category ("sqlserver")]
  	public class DataReaderTest
  	{
  		static byte [] long_bytes = new byte [] {
  			0x00, 0x66, 0x06, 0x66, 0x97, 0x00, 0x66, 0x06, 0x66,
  			0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  			0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  			0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  			0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  			0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  			0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  			0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  			0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  			0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  			0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  			0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  			0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  			0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  			0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  			0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  			0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  			0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  			0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  			0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  			0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  			0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  			0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  			0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  			0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  			0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
  			0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
  			0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
  			0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
  			0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
  			0x06, 0x66, 0x06, 0x66, 0x98};
  
  		IDbConnection conn;
  		IDbCommand cmd;
  
  		[SetUp]
  		public void SetUp ()
  		{
  			conn = ConnectionManager.Singleton.Connection;
  			ConnectionManager.Singleton.OpenConnection ();
  			cmd = conn.CreateCommand ();
  		}
  
  		[TearDown]
  		public void TearDown ()
  		{
  			if (cmd != null)
  				cmd.Dispose ();
  			ConnectionManager.Singleton.CloseConnection ();
  		}
  
  		[Test]
  		public void FieldCount ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				Assert.AreEqual (6, reader.FieldCount);
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void FieldCount_Command_Disposed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				cmd.Dispose ();
  				Assert.AreEqual (6, reader.FieldCount);
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void FieldCount_Reader_Closed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				reader.Close ();
  				try {
  					int fieldcount = reader.FieldCount;
  					Assert.Fail ("#1:" + fieldcount);
  				} catch (InvalidOperationException ex) {
  					// Invalid attempt to FieldCount when
  					// reader is closed
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  					Assert.IsNull (ex.InnerException, "#3");
  					Assert.IsNotNull (ex.Message, "#4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetChars_Index_Invalid ()
  		{
  			//Console.WriteLine ("In GetChars_Index_Invalid - first_executereader");
  			cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
  
  			using (IDataReader rdr = cmd.ExecuteReader ()) {
  				Assert.IsTrue (rdr.Read ());
  
  				try {
  					rdr.GetChars (-1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#A1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				try {
  					rdr.GetChars (1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#B1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			}
  
  			//Console.WriteLine ("In GetChars_Index_Invalid - second_executereader");
  			using (IDataReader rdr = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
  				Assert.IsTrue (rdr.Read ());
  
  				try {
  					rdr.GetChars (-1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#C1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#C2");
  					Assert.IsNull (ex.InnerException, "#C3");
  					Assert.IsNotNull (ex.Message, "#C4");
  				}
  
  				try {
  					rdr.GetChars (1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#D1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#D2");
  					Assert.IsNull (ex.InnerException, "#D3");
  					Assert.IsNotNull (ex.Message, "#D4");
  				}
  			}
  		}
  
  		[Test]
  		public void GetChars_Reader_Closed ()
  		{
  			//Console.WriteLine ("GetChars_Reader_Closed - first_executereader");
  			cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
  
  			using (IDataReader rdr = cmd.ExecuteReader ()) {
  				Assert.IsTrue (rdr.Read ());
  				rdr.Close ();
  
  				try {
  					rdr.GetChars (-1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#A1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  			}
  
  			//Console.WriteLine ("GetChars_Reader_Closed - second_executereader");
  			using (IDataReader rdr = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
  				Assert.IsTrue (rdr.Read ());
  				rdr.Close ();
  
  				try {
  					rdr.GetChars (-1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#B1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			}
  		}
  
  		[Test]
  		public void GetChars_Reader_NoData ()
  		{
  			//Console.WriteLine ("GetChars_Reader_NoData - first_executereader");
  			cmd.CommandText = "SELECT type_blob FROM binary_family where id = 666";
  
  			using (IDataReader rdr = cmd.ExecuteReader ()) {
  				try {
  					rdr.GetChars (-1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#A1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				Assert.IsFalse (rdr.Read (), "#B");
  
  				try {
  					rdr.GetChars (-1, 0, (char []) null, 0, 0);
  					Assert.Fail ("#C1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
  					Assert.IsNull (ex.InnerException, "#C3");
  					Assert.IsNotNull (ex.Message, "#C4");
  				}
  			}
  		}
  
  		[Test]
  		public void GetDataTypeName ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  
  				switch (ConnectionManager.Singleton.Engine.Type) {
  				case EngineType.SQLServer:
  					Assert.AreEqual ("int", reader.GetDataTypeName (0), "#1");
  					break;
  				case EngineType.MySQL:
  					Assert.AreEqual ("integer", reader.GetDataTypeName (0), "#1");
  					break;
  				default:
  					Assert.Fail ("Engine type not supported.");
  					break;
  				}
  				Assert.AreEqual ("varchar", reader.GetDataTypeName (1), "#2");
  				Assert.AreEqual ("varchar", reader.GetDataTypeName (2), "#3");
  				Assert.AreEqual ("datetime", reader.GetDataTypeName (3), "#4");
  				Assert.AreEqual ("datetime", reader.GetDataTypeName (4), "#5");
  				Assert.AreEqual ("varchar", reader.GetDataTypeName (5), "#6");
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetDataTypeName_Index_Invalid ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  
  				try {
  					reader.GetDataTypeName (-1);
  					Assert.Fail ("#A1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				try {
  					reader.GetDataTypeName (6);
  					Assert.Fail ("#B1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetDataTypeName_Reader_Closed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				reader.Close ();
  
  				try {
  					reader.GetDataTypeName (0);
  					Assert.Fail ("#1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  					Assert.IsNull (ex.InnerException, "#3");
  					Assert.IsNotNull (ex.Message, "#4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetFieldType ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				Assert.AreEqual (typeof (int), reader.GetFieldType (0), "#1");
  				Assert.AreEqual (typeof (string), reader.GetFieldType (2), "#2");
  				Assert.AreEqual (typeof (DateTime), reader.GetFieldType (4), "#3");
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetFieldType_Index_Invalid ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				try {
  					reader.GetFieldType (-1);
  					Assert.Fail ("#A1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				try {
  					reader.GetFieldType (6);
  					Assert.Fail ("#B1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetFieldType_Reader_Closed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				reader.Close ();
  				try {
  					reader.GetFieldType (0);
  					Assert.Fail ("#1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  					Assert.IsNull (ex.InnerException, "#3");
  					Assert.IsNotNull (ex.Message, "#4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetName ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				Assert.AreEqual ("id", reader.GetName (0), "#1");
  				Assert.AreEqual ("fname", reader.GetName (1), "#2");
  				Assert.AreEqual ("lname", reader.GetName (2), "#3");
  				Assert.AreEqual ("dob", reader.GetName (3), "#4");
  				Assert.AreEqual ("doj", reader.GetName (4), "#5");
  				Assert.AreEqual ("email", reader.GetName (5), "#6");
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetName_Index_Invalid ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				try {
  					reader.GetName (-1);
  					Assert.Fail ("#A1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				try {
  					reader.GetName (6);
  					Assert.Fail ("#B1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetName_Reader_Closed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				reader.Close ();
  				try {
  					reader.GetName (0);
  					Assert.Fail ("#1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  					Assert.IsNull (ex.InnerException, "#3");
  					Assert.IsNotNull (ex.Message, "#4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetOrdinal ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				Assert.AreEqual (0, reader.GetOrdinal ("id"), "#1");
  				Assert.AreEqual (1, reader.GetOrdinal ("fname"), "#2");
  				Assert.AreEqual (2, reader.GetOrdinal ("lname"), "#3");
  				Assert.AreEqual (3, reader.GetOrdinal ("doB"), "#4");
  				Assert.AreEqual (4, reader.GetOrdinal ("doj"), "#5");
  				Assert.AreEqual (5, reader.GetOrdinal ("EmaiL"), "#6");
  				Assert.AreEqual (0, reader.GetOrdinal ("iD"), "#7");
  				Assert.AreEqual (5, reader.GetOrdinal ("eMail"), "#8");
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetOrdinal_Name_NotFound ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				try {
  					reader.GetOrdinal ("non_existing_column");
  					Assert.Fail ("#A1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				try {
  					reader.GetOrdinal (string.Empty);
  					Assert.Fail ("#B1");
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetOrdinal_Name_Null ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				try {
  					reader.GetOrdinal (null);
  					Assert.Fail ("#1");
  				} catch (ArgumentNullException ex) {
  					Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  					Assert.IsNull (ex.InnerException, "#3");
  					Assert.IsNotNull (ex.Message, "#4");
  					Assert.AreEqual ("fieldName", ex.ParamName, "#5");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetOrdinal_Reader_Closed ()
  		{
  			cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  
  			using (IDataReader rdr = cmd.ExecuteReader ()) {
  				rdr.Close ();
  
  				try {
  					rdr.GetOrdinal (null);
  					Assert.Fail ("#A1");
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  			}
  		}
  
  		[Test]
  		public void GetOrdinal_Reader_NoData ()
  		{
  			cmd.CommandText = "SELECT * FROM employee WHERE id = 666";
  
  			using (IDataReader rdr = cmd.ExecuteReader ()) {
  				Assert.AreEqual (0, rdr.GetOrdinal ("id"), "#A1");
  				Assert.AreEqual (5, rdr.GetOrdinal ("eMail"), "#A2");
  
  				Assert.IsFalse (rdr.Read (), "#B");
  
  				Assert.AreEqual (2, rdr.GetOrdinal ("lname"), "#C1");
  				Assert.AreEqual (3, rdr.GetOrdinal ("dob"), "#C2");
  			}
  		}
  
  		[Test]
  		public void GetSchemaTable_Command_Disposed ()
  		{
  			if (RunningOnMono && (conn is OdbcConnection))
  				Assert.Ignore ("Our statement handle is closed when we dispose the (Odbc)Command");
  
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
  				reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
  				cmd.Dispose ();
  				DataTable schema = reader.GetSchemaTable ();
  				Assert.AreEqual (3, schema.Rows.Count, "RowCount");
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetSchemaTable_Reader_Closed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
  				reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
  				reader.Close ();
  
  				try {
  					reader.GetSchemaTable ();
  					Assert.Fail ("#1");
  				} catch (InvalidOperationException ex) {
  					// Invalid attempt to call GetSchemaTable
  					// when reader is closed
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  					Assert.IsNull (ex.InnerException, "#3");
  					Assert.IsNotNull (ex.Message, "#4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test]
  		public void GetNameTest ()
  		{
  			cmd.CommandText = "SELECT type_tinyint from numeric_family"; ;
  			using (IDataReader reader = cmd.ExecuteReader ()) {
  				Assert.AreEqual ("type_tinyint", reader.GetName (0), "#1");
  			}
  		}
  
  		[Test] // this [Int32]
  		public void Indexer1 ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				Assert.IsTrue (reader.Read ());
  				Assert.AreEqual (1, reader [0], "#0");
  				Assert.AreEqual ("suresh", reader [1], "#1");
  				Assert.AreEqual ("kumar", reader [2], "#2");
  				Assert.AreEqual (new DateTime (1978, 8, 22), reader [3], "#3");
  				Assert.AreEqual (new DateTime (2001, 3, 12), reader [4], "#4");
  				Assert.AreEqual ("suresh@gmail.com", reader [5], "#5");
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test] // this [Int32]
  		public void Indexer1_Reader_Closed ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "select fname from employee";
  				reader = cmd.ExecuteReader ();
  				reader.Read ();
  				reader.Close ();
  
  				try {
  					object value = reader [0];
  					Assert.Fail ("#A1:" + value);
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				reader = cmd.ExecuteReader ();
  				reader.Close ();
  
  				try {
  					object value = reader [0];
  					Assert.Fail ("#B1:" + value);
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test] // this [Int32]
  		public void Indexer1_Reader_NoData ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "select fname from employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				try {
  					object value = reader [0];
  					Assert.Fail ("#A1:" + value);
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				Assert.IsTrue (reader.Read ());
  				Assert.IsFalse (reader.Read ());
  
  				try {
  					object value = reader [0];
  					Assert.Fail ("#B1:" + value);
  				} catch (InvalidOperationException ex) {
  					// No data exists for the row/column
  					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test] // this [Int32]
  		public void Indexer1_Value_Invalid ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "select fname from employee";
  				reader = cmd.ExecuteReader ();
  				Assert.IsTrue (reader.Read ());
  				try {
  					object value = reader [-1];
  					Assert.Fail ("#A1:" + value);
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
  					Assert.IsNull (ex.InnerException, "#A3");
  					Assert.IsNotNull (ex.Message, "#A4");
  				}
  
  				try {
  					object value = reader [1];
  					Assert.Fail ("#B1:" + value);
  				} catch (IndexOutOfRangeException ex) {
  					// Index was outside the bounds of the array
  					Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
  					Assert.IsNull (ex.InnerException, "#B3");
  					Assert.IsNotNull (ex.Message, "#B4");
  				}
  			} finally {
  				if (reader != null)
  					reader.Close ();
  			}
  		}
  
  		[Test] // this [String]
  		public void Indexer2 ()
  		{
  			IDataReader reader = null;
  
  			try {
  				cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
  				reader = cmd.ExecuteReader ();
  				Assert.IsTrue (reader.Read ());
  				Assert.AreEqual (1, reader ["id"], "id");
  				Assert.AreEqual ("suresh", reader ["fname"], "fname");
  				Assert.AreEqual ("kumar", reader ["lname"], "lname");
  				Assert.AreEqual (new DateTime (1978, 8, 22), reader ["doB"], "doB");
  				Assert.AreEqual (new DateTime (2001, 3, 12), reader ["doj"], "doj");
  				Assert.AreEqual ("suresh@gmail.com", reader ["EmaiL"], "EmaiL");
  
gt: 				Assert.AreEqual (1, reader ["iD"], "iD");