Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGert Driesen <drieseng@users.sourceforge.net>2009-01-04 02:33:20 +0300
committerGert Driesen <drieseng@users.sourceforge.net>2009-01-04 02:33:20 +0300
commita7331a74c3d38c44302ee8a8d059f04a0ed3baef (patch)
tree8ba52b02b7e4a9d28fde4aa1b3e2a8f55ab69230 /mcs/class/System.Data/Test
parent8a6bd370d1809e04065e1515fba5c344df6e1362 (diff)
* DataReaderTest.cs: Added tests for GetChars, GetOrdinal,
GetValue and GetValues. Improved existing tests. * DbDataReaderTest.cs: Moved GetProviderSpecificValue test to provider specific tests (as its behavior differs between Odbc and SqlClient). Removed unused property. svn path=/trunk/mcs/; revision=122384
Diffstat (limited to 'mcs/class/System.Data/Test')
-rw-r--r--mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog8
-rw-r--r--mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs328
-rw-r--r--mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DbDataReaderTest.cs32
3 files changed, 309 insertions, 59 deletions
diff --git a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog
index a422bee6be2..d24efc75c83 100644
--- a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog
+++ b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/ChangeLog
@@ -1,3 +1,11 @@
+2009-01-03 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * DataReaderTest.cs: Added tests for GetChars, GetOrdinal,
+ GetValue and GetValues. Improved existing tests.
+ * DbDataReaderTest.cs: Moved GetProviderSpecificValue test
+ to provider specific tests (as its behavior differs between
+ Odbc and SqlClient). Removed unused property.
+
2008-12-31 Gert Driesen <drieseng@users.sourceforge.net>
* DataReaderTest.cs: Added tests that were previously part of
diff --git a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs
index fa1ed0d1ece..51b04ec7716 100644
--- a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs
+++ b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DataReaderTest.cs
@@ -156,6 +156,126 @@ namespace MonoTests.System.Data
}
[Test]
+ public void GetChars_Index_Invalid ()
+ {
+ 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");
+ }
+ }
+
+ 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 ()
+ {
+ 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");
+ }
+ }
+
+ 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 ()
+ {
+ 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;
@@ -197,14 +317,22 @@ namespace MonoTests.System.Data
try {
reader.GetDataTypeName (-1);
- Assert.Fail ("#1");
- } catch (IndexOutOfRangeException) {
+ 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 ("#2");
- } catch (IndexOutOfRangeException) {
+ 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)
@@ -264,14 +392,22 @@ namespace MonoTests.System.Data
reader = cmd.ExecuteReader ();
try {
reader.GetFieldType (-1);
- Assert.Fail ("#1");
- } catch (IndexOutOfRangeException) {
+ 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 ("#1");
- } catch (IndexOutOfRangeException) {
+ 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)
@@ -333,14 +469,22 @@ namespace MonoTests.System.Data
reader = cmd.ExecuteReader ();
try {
reader.GetName (-1);
- Assert.Fail ("#1");
- } catch (IndexOutOfRangeException) {
+ 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 ("#2");
- } catch (IndexOutOfRangeException) {
+ 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)
@@ -383,9 +527,9 @@ namespace MonoTests.System.Data
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 (3, reader.GetOrdinal ("doB"), "#4");
Assert.AreEqual (4, reader.GetOrdinal ("doj"), "#5");
- Assert.AreEqual (5, reader.GetOrdinal ("email"), "#6");
+ Assert.AreEqual (5, reader.GetOrdinal ("EmaiL"), "#6");
Assert.AreEqual (0, reader.GetOrdinal ("iD"), "#7");
Assert.AreEqual (5, reader.GetOrdinal ("eMail"), "#8");
} finally {
@@ -404,14 +548,22 @@ namespace MonoTests.System.Data
reader = cmd.ExecuteReader ();
try {
reader.GetOrdinal ("non_existing_column");
- Assert.Fail ("#1");
- } catch (IndexOutOfRangeException) {
+ 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 ("#2");
- } catch (IndexOutOfRangeException) {
+ 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)
@@ -445,24 +597,36 @@ namespace MonoTests.System.Data
[Test]
public void GetOrdinal_Reader_Closed ()
{
- IDataReader reader = null;
+ cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
+
+ using (IDataReader rdr = cmd.ExecuteReader ()) {
+ rdr.Close ();
- try {
- cmd.CommandText = "SELECT * FROM employee WHERE lname='kumar'";
- reader = cmd.ExecuteReader ();
- reader.Close ();
try {
- reader.GetOrdinal ("does_not_exist");
- Assert.Fail ("#1");
+ rdr.GetOrdinal (null);
+ Assert.Fail ("#A1");
} 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");
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
}
- } finally {
- if (reader != null)
- reader.Close ();
+ }
+ }
+
+ [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");
}
}
@@ -612,6 +776,57 @@ namespace MonoTests.System.Data
}
[Test]
+ public void GetValue_Reader_Closed ()
+ {
+ cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
+
+ using (IDataReader reader = cmd.ExecuteReader ()) {
+ Assert.IsTrue (reader.Read ());
+ reader.Close ();
+
+ try {
+ reader.GetValue (-1);
+ 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");
+ }
+ }
+ }
+
+ [Test]
+ public void GetValue_Reader_NoData ()
+ {
+ cmd.CommandText = "SELECT type_blob FROM binary_family where id = 666";
+
+ using (IDataReader rdr = cmd.ExecuteReader ()) {
+ try {
+ rdr.GetValue (-1);
+ 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.GetValue (-1);
+ 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 GetValueBinaryTest ()
{
cmd.CommandText = "select type_binary from binary_family where id = 1";
@@ -919,6 +1134,57 @@ namespace MonoTests.System.Data
}
}
+ [Test]
+ public void GetValues_Reader_Closed ()
+ {
+ cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
+
+ using (IDataReader rdr = cmd.ExecuteReader ()) {
+ Assert.IsTrue (rdr.Read ());
+ rdr.Close ();
+
+ try {
+ rdr.GetValues ((object []) null);
+ 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");
+ }
+ }
+ }
+
+ [Test]
+ public void GetValues_Reader_NoData ()
+ {
+ cmd.CommandText = "SELECT type_blob FROM binary_family where id = 666";
+
+ using (IDataReader rdr = cmd.ExecuteReader ()) {
+ try {
+ rdr.GetValues ((object []) 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");
+ }
+
+ Assert.IsFalse (rdr.Read (), "#B");
+
+ try {
+ rdr.GetValues ((object []) null);
+ 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");
+ }
+ }
+ }
+
static bool RunningOnMono {
get {
return (Type.GetType ("System.MonoType", false) != null);
diff --git a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DbDataReaderTest.cs b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DbDataReaderTest.cs
index 2050784839e..21aaaab9eeb 100644
--- a/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DbDataReaderTest.cs
+++ b/mcs/class/System.Data/Test/ProviderTests/ProviderIndependant/DbDataReaderTest.cs
@@ -109,37 +109,13 @@ namespace MonoTests.System.Data
try {
rdr.GetProviderSpecificValues (null);
- Assert.Fail ("#B1");
+ Assert.Fail ("#C1");
} catch (InvalidOperationException ex) {
// Invalid attempt to read when no data
// is present
- Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- }
- }
-
- [Test]
- public void GetProviderSpecificValues_Values_Null ()
- {
- cmd.CommandText = "SELECT * FROM employee";
- rdr = cmd.ExecuteReader ();
- rdr.Read ();
-
- try {
- rdr.GetProviderSpecificValues (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 ("values", ex.ParamName, "#5");
- }
- }
-
- static bool RunningOnMono {
- get {
- return (Type.GetType ("System.MonoType", false) != null);
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
+ Assert.IsNull (ex.InnerException, "#C3");
+ Assert.IsNotNull (ex.Message, "#C4");
}
}
}