* DataRow.cs: Added missing null checks. Cosmetic changes to exception
[mono.git] / mcs / class / System.Data / Test / System.Data / DataRowTest2.cs
index 8b3dc07b27408a0ba95db428a8cb6ac7cd0728cc..923c25387dac567236960089eed4689f9a7c879d 100644 (file)
@@ -37,6 +37,14 @@ namespace MonoTests.System.Data
 {
        [TestFixture] public class DataRowTest2
        {
+               bool _rowChanged;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       _rowChanged = false;
+               }
+
                [Test] public void AcceptChanges()
                {
                        DataTable myTable = new DataTable("myTable"); 
@@ -867,6 +875,504 @@ namespace MonoTests.System.Data
                        Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW84");
                }
 
+               [Test] // Object this [DataColumn]
+               public void Indexer1 ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+                       Address addressB = new Address ("Y", 4);
+                       Person personC = new Person ("Jackson");
+                       Address addressC = new Address ("Z", 3);
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       dt.Rows.Add (new object [] { addressB, personB });
+                       DataRow dr;
+
+                       dr = dt.Rows [0];
+                       Assert.AreEqual (addressA, dr [dc0], "#A1");
+                       Assert.AreSame (personA, dr [dc1], "#A2");
+
+                       dr = dt.Rows [1];
+                       Assert.AreEqual (addressB, dr [dc0], "#B1");
+                       Assert.AreSame (personB, dr [dc1], "#B2");
+
+                       dr = dt.Rows [0];
+                       dr [dc0] = addressC;
+                       Assert.AreEqual (addressC, dr [dc0], "#C1");
+                       Assert.AreSame (personA, dr [dc1], "#C2");
+
+                       dr = dt.Rows [1];
+                       dr [dc1] = personC;
+                       Assert.AreEqual (addressB, dr [dc0], "#D1");
+                       Assert.AreSame (personC, dr [dc1], "#D2");
+               }
+
+               [Test] // Object this [DataColumn]
+               public void Indexer1_Column_Null ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       DataRow dr = dt.Rows [0];
+
+                       try {
+                               object value = dr [(DataColumn) null];
+                               Assert.Fail ("#A1:" + value);
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.AreEqual ("column", ex.ParamName, "#A5");
+                       }
+
+                       try {
+                               dr [(DataColumn) null] = personB;
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.AreEqual ("column", ex.ParamName, "#B5");
+                       }
+               }
+
+               [Test] // Object this [DataColumn]
+               [NUnit.Framework.Category ("NotWorking")]
+               public void Indexer1_Value_Null ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+                       Address addressB = new Address ("Y", 4);
+                       Person personC = new Person ("Jackson");
+                       Address addressC = new Address ("Z", 3);
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       dt.Rows.Add (new object [] { addressB, personB });
+
+                       DataRow dr = dt.Rows [0];
+
+                       try {
+                               dr [dc0] = null;
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentException ex) {
+                               // Cannot set Column 'Col0' to be null.
+                               // Please use DBNull instead
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsTrue (ex.Message.IndexOf ("Col0") != -1, "#A5");
+                               Assert.IsTrue (ex.Message.IndexOf ("DBNull") != -1, "#A6");
+                       }
+
+                       Assert.AreEqual (addressA, dr [dc0], "#B1");
+                       Assert.IsFalse (dr.IsNull (dc0), "#B2");
+                       Assert.AreSame (personA, dr [dc1], "#B3");
+                       Assert.IsFalse (dr.IsNull (dc1), "#B4");
+
+#if NET_2_0
+                       dr [dc1] = null;
+#else
+                       try {
+                               dr [dc1] = null;
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Cannot set Column 'Col1' to be null.
+                               // Please use DBNull instead
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsTrue (ex.Message.IndexOf ("Col1") != -1, "#B5");
+                               Assert.IsTrue (ex.Message.IndexOf ("DBNull") != -1, "#B6");
+                       }
+                       dr [dc1] = DBNull.Value;
+#endif
+
+                       Assert.AreEqual (addressA, dr [dc0], "#C1");
+                       Assert.IsFalse (dr.IsNull (dc0), "#C2");
+                       Assert.AreSame (DBNull.Value, dr [dc1], "#C3");
+                       Assert.IsTrue (dr.IsNull (dc1), "#C4");
+
+                       dr [dc0] = DBNull.Value;
+
+                       Assert.AreSame (DBNull.Value, dr [dc0], "#D1");
+                       Assert.IsTrue (dr.IsNull (dc0), "#D2");
+                       Assert.AreSame (DBNull.Value, dr [dc1], "#D3");
+                       Assert.IsTrue (dr.IsNull (dc1), "#D4");
+
+                       dr [dc1] = personC;
+                       Assert.AreSame (DBNull.Value, dr [dc0], "#E1");
+                       Assert.IsTrue (dr.IsNull (dc0), "#E2");
+                       Assert.AreEqual (personC, dr [dc1], "#E3");
+                       Assert.IsFalse (dr.IsNull (dc1), "#E4");
+
+                       dr [dc1] = DBNull.Value;
+
+                       Assert.AreSame (DBNull.Value, dr [dc0], "#F1");
+                       Assert.IsTrue (dr.IsNull (dc0), "#F2");
+                       Assert.AreSame (DBNull.Value, dr [dc1], "#F3");
+                       Assert.IsTrue (dr.IsNull (dc1), "#F4");
+               }
+
+               [Test] // Object this [Int32]
+               public void Indexer2 ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+                       Address addressB = new Address ("Y", 4);
+                       Person personC = new Person ("Jackson");
+                       Address addressC = new Address ("Z", 3);
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       dt.Rows.Add (new object [] { addressB, personB });
+                       DataRow dr;
+                       
+                       dr = dt.Rows [0];
+                       Assert.AreEqual (addressA, dr [0], "#A1");
+                       Assert.AreSame (personA, dr [1], "#A2");
+
+                       dr = dt.Rows [1];
+                       Assert.AreEqual (addressB, dr [0], "#B1");
+                       Assert.AreSame (personB, dr [1], "#B2");
+
+                       dr = dt.Rows [0];
+                       dr [0] = addressC;
+                       Assert.AreEqual (addressC, dr [0], "#C1");
+                       Assert.AreSame (personA, dr [1], "#C2");
+
+                       dr = dt.Rows [1];
+                       dr [1] = personC;
+                       Assert.AreEqual (addressB, dr [0], "#D1");
+                       Assert.AreSame (personC, dr [1], "#D2");
+               }
+
+               [Test] // Object this [Int32]
+               [NUnit.Framework.Category ("NotWorking")]
+               public void Indexer2_Value_Null ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+                       Address addressB = new Address ("Y", 4);
+                       Person personC = new Person ("Jackson");
+                       Address addressC = new Address ("Z", 3);
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       dt.Rows.Add (new object [] { addressB, personB });
+
+                       DataRow dr = dt.Rows [0];
+
+                       try {
+                               dr [0] = null;
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentException ex) {
+                               // Cannot set Column 'Col0' to be null.
+                               // Please use DBNull instead
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsTrue (ex.Message.IndexOf ("Col0") != -1, "#A5");
+                               Assert.IsTrue (ex.Message.IndexOf ("DBNull") != -1, "#A6");
+                       }
+
+                       Assert.AreEqual (addressA, dr [0], "#B1");
+                       Assert.IsFalse (dr.IsNull (0), "#B2");
+                       Assert.AreSame (personA, dr [1], "#B3");
+                       Assert.IsFalse (dr.IsNull (1), "#B4");
+
+#if NET_2_0
+                       dr [1] = null;
+#else
+                       try {
+                               dr [1] = null;
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Cannot set Column 'Col1' to be null.
+                               // Please use DBNull instead
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsTrue (ex.Message.IndexOf ("Col1") != -1, "#B5");
+                               Assert.IsTrue (ex.Message.IndexOf ("DBNull") != -1, "#B6");
+                       }
+                       dr [1] = DBNull.Value;
+#endif
+
+                       Assert.AreEqual (addressA, dr [0], "#C1");
+                       Assert.IsFalse (dr.IsNull (0), "#C2");
+                       Assert.AreSame (DBNull.Value, dr [1], "#C3");
+                       Assert.IsTrue (dr.IsNull (1), "#C4");
+
+                       dr [0] = DBNull.Value;
+
+                       Assert.AreSame (DBNull.Value, dr [0], "#D1");
+                       Assert.IsTrue (dr.IsNull (0), "#D2");
+                       Assert.AreSame (DBNull.Value, dr [1], "#D3");
+                       Assert.IsTrue (dr.IsNull (1), "#D4");
+
+                       dr [1] = personC;
+                       Assert.AreSame (DBNull.Value, dr [0], "#E1");
+                       Assert.IsTrue (dr.IsNull (0), "#E2");
+                       Assert.AreEqual (personC, dr [1], "#E3");
+                       Assert.IsFalse (dr.IsNull (1), "#E4");
+
+                       dr [1] = DBNull.Value;
+
+                       Assert.AreSame (DBNull.Value, dr [0], "#F1");
+                       Assert.IsTrue (dr.IsNull (0), "#F2");
+                       Assert.AreSame (DBNull.Value, dr [1], "#F3");
+                       Assert.IsTrue (dr.IsNull (1), "#F4");
+               }
+
+               [Test] // Object this [String]
+               public void Indexer3 ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+                       Address addressB = new Address ("Y", 4);
+                       Person personC = new Person ("Jackson");
+                       Address addressC = new Address ("Z", 3);
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       dt.Rows.Add (new object [] { addressB, personB });
+                       DataRow dr;
+
+                       dr = dt.Rows [0];
+                       Assert.AreEqual (addressA, dr ["Col0"], "#A1");
+                       Assert.AreSame (personA, dr ["Col1"], "#A2");
+
+                       dr = dt.Rows [1];
+                       Assert.AreEqual (addressB, dr ["Col0"], "#B1");
+                       Assert.AreSame (personB, dr ["Col1"], "#B2");
+
+                       dr = dt.Rows [0];
+                       dr ["Col0"] = addressC;
+                       Assert.AreEqual (addressC, dr ["Col0"], "#C1");
+                       Assert.AreSame (personA, dr ["Col1"], "#C2");
+
+                       dr = dt.Rows [1];
+                       dr ["Col1"] = personC;
+                       Assert.AreEqual (addressB, dr ["Col0"], "#D1");
+                       Assert.AreSame (personC, dr ["Col1"], "#D2");
+               }
+
+               [Test] // Object this [String]
+               public void Indexer3_ColumnName_Empty ()
+               {
+                       DataTable dt = new DataTable ("Persons");
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn (string.Empty, typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+
+                       DataRow dr = dt.Rows [0];
+
+                       try {
+                               object value = dr [string.Empty];
+                               Assert.Fail ("#A1:" + value);
+                       } catch (ArgumentException ex) {
+                               //  Column '' does not belong to table Persons
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsTrue (ex.Message.IndexOf ("''") != -1, "#A5");
+                               Assert.IsTrue (ex.Message.IndexOf ("Persons") != -1, "#A6");
+                               Assert.IsNull (ex.ParamName, "#A7");
+                       }
+
+                       try {
+                               dr [string.Empty] = personB;
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Column '' does not belong to table Persons
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsTrue (ex.Message.IndexOf ("''") != -1, "#B5");
+                               Assert.IsTrue (ex.Message.IndexOf ("Persons") != -1, "#B6");
+                               Assert.IsNull (ex.ParamName, "#B7");
+                       }
+               }
+
+               [Test] // Object this [String]
+               [NUnit.Framework.Category ("NotWorking")]
+               public void Indexer3_ColumnName_Null ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+
+                       DataRow dr = dt.Rows [0];
+
+                       try {
+                               object value = dr [(string) null];
+                               Assert.Fail ("#A1:" + value);
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+#if NET_2_0
+                               Assert.AreEqual ("name", ex.ParamName, "#A5");
+#else
+                               Assert.AreEqual ("key", ex.ParamName, "#A5");
+#endif
+                               throw;
+                       }
+
+                       try {
+                               dr [(string) null] = personB;
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+#if NET_2_0
+                               Assert.AreEqual ("name", ex.ParamName, "#B5");
+#else
+                               Assert.AreEqual ("key", ex.ParamName, "#B5");
+#endif
+                       }
+               }
+
+               [Test] // Object this [String]
+               [NUnit.Framework.Category ("NotWorking")]
+               public void Indexer3_Value_Null ()
+               {
+                       DataTable dt = new DataTable ();
+                       DataColumn dc0 = new DataColumn ("Col0", typeof (Address));
+                       dt.Columns.Add (dc0);
+                       DataColumn dc1 = new DataColumn ("Col1", typeof (Person));
+                       dt.Columns.Add (dc1);
+
+                       Person personA = new Person ("Miguel");
+                       Address addressA = new Address ("X", 5);
+                       Person personB = new Person ("Chris");
+                       Address addressB = new Address ("Y", 4);
+                       Person personC = new Person ("Jackson");
+                       Address addressC = new Address ("Z", 3);
+
+                       dt.Rows.Add (new object [] { addressA, personA });
+                       dt.Rows.Add (new object [] { addressB, personB });
+
+                       DataRow dr = dt.Rows [0];
+
+                       try {
+                               dr ["Col0"] = null;
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentException ex) {
+                               // Cannot set Column 'Col0' to be null.
+                               // Please use DBNull instead
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsTrue (ex.Message.IndexOf ("Col0") != -1, "#A5");
+                               Assert.IsTrue (ex.Message.IndexOf ("DBNull") != -1, "#A6");
+                       }
+
+                       Assert.AreEqual (addressA, dr ["Col0"], "#B1");
+                       Assert.IsFalse (dr.IsNull ("Col0"), "#B2");
+                       Assert.AreSame (personA, dr ["Col1"], "#B3");
+                       Assert.IsFalse (dr.IsNull ("Col1"), "#B4");
+
+#if NET_2_0
+                       dr ["Col1"] = null;
+#else
+                       try {
+                               dr ["Col1"] = null;
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Cannot set Column 'Col1' to be null.
+                               // Please use DBNull instead
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsTrue (ex.Message.IndexOf ("Col1") != -1, "#B5");
+                               Assert.IsTrue (ex.Message.IndexOf ("DBNull") != -1, "#B6");
+                       }
+                       dr ["Col1"] = DBNull.Value;
+#endif
+
+                       Assert.AreEqual (addressA, dr ["Col0"], "#C1");
+                       Assert.IsFalse (dr.IsNull ("Col0"), "#C2");
+                       Assert.AreSame (DBNull.Value, dr ["Col1"], "#C3");
+                       Assert.IsTrue (dr.IsNull ("Col1"), "#C4");
+
+                       dr ["Col0"] = DBNull.Value;
+
+                       Assert.AreSame (DBNull.Value, dr ["Col0"], "#D1");
+                       Assert.IsTrue (dr.IsNull ("Col0"), "#D2");
+                       Assert.AreSame (DBNull.Value, dr ["Col1"], "#D3");
+                       Assert.IsTrue (dr.IsNull ("Col1"), "#D4");
+
+                       dr ["Col1"] = personC;
+                       Assert.AreSame (DBNull.Value, dr ["Col0"], "#E1");
+                       Assert.IsTrue (dr.IsNull ("Col0"), "#E2");
+                       Assert.AreEqual (personC, dr ["Col1"], "#E3");
+                       Assert.IsFalse (dr.IsNull ("Col1"), "#E4");
+
+                       dr ["Col1"] = DBNull.Value;
+
+                       Assert.AreSame (DBNull.Value, dr ["Col0"], "#F1");
+                       Assert.IsTrue (dr.IsNull ("Col0"), "#F2");
+                       Assert.AreSame (DBNull.Value, dr ["Col1"], "#F3");
+                       Assert.IsTrue (dr.IsNull ("Col1"), "#F4");
+               }
+
                [Test] public void IsNull_ByDataColumn()
                {
                        DataTable dt = new DataTable(); 
@@ -1130,6 +1636,8 @@ namespace MonoTests.System.Data
 
                        // error string
                        Assert.AreEqual(sColErr  ,  dr.GetColumnError(0) , "DRW117");
+                       dr.SetColumnError (0, "");
+                       Assert.AreEqual("",  dr.GetColumnError (0) , "DRW118");
                }
 
                [Test] public void SetColumnError_ByColumnNameError()
@@ -1179,6 +1687,7 @@ namespace MonoTests.System.Data
                        Assert.AreEqual(drArrExcepted ,  drArrResult, "DRW120");
                }
 
+               [Test]
                public void testMore()
                {
                        DataSet ds = DataProvider.CreateForigenConstraint();
@@ -1187,6 +1696,7 @@ namespace MonoTests.System.Data
                        ds.Tables[1].Rows[0].SetParentRow(drParent);
                }
 
+               [Test]
                public void test()
                {
                        // test SetParentRow
@@ -1286,11 +1796,11 @@ namespace MonoTests.System.Data
                
                [Test] public void DataRow_RowError()
                {
-                       DataTable dt = new DataTable ("myTable"); \r
-                       DataRow dr = dt.NewRow ();\r
-       \r
-                       Assert.AreEqual ( dr.RowError, string.Empty );\r
-                                               \r
+                       DataTable dt = new DataTable ("myTable"); 
+                       DataRow dr = dt.NewRow ();
+       
+                       Assert.AreEqual ( dr.RowError, string.Empty );
+                                               
                        dr.RowError = "Err";
                        Assert.AreEqual ( dr.RowError , "Err" );
                }
@@ -1299,13 +1809,13 @@ namespace MonoTests.System.Data
                [ExpectedException (typeof (ConstraintException))]
                public void DataRow_RowError2()
                {
-                       DataTable dt1 = DataProvider.CreateUniqueConstraint();\r
-\r
-                       dt1.BeginLoadData();\r
-\r
-                       DataRow  dr = dt1.NewRow();\r
-                       dr[0] = 3;\r
-                       dt1.Rows.Add(dr);\r
+                       DataTable dt1 = DataProvider.CreateUniqueConstraint();
+
+                       dt1.BeginLoadData();
+
+                       DataRow  dr = dt1.NewRow();
+                       dr[0] = 3;
+                       dt1.Rows.Add(dr);
                        dt1.EndLoadData();
                }
                
@@ -1313,179 +1823,214 @@ namespace MonoTests.System.Data
                [ExpectedException (typeof (ConstraintException))]
                public void DataRow_RowError3()
                {
-                       DataSet ds= DataProvider.CreateForigenConstraint();\r
-                       ds.Tables[0].BeginLoadData();\r
-                       ds.Tables[0].Rows[0][0] = 10; \r
+                       DataSet ds= DataProvider.CreateForigenConstraint();
+                       ds.Tables[0].BeginLoadData();
+                       ds.Tables[0].Rows[0][0] = 10; 
                        ds.Tables[0].EndLoadData(); //Foreign constraint violation
                }
 
+
+               [Test]
+               public void TestRowErrors ()
+               {
+                       DataTable table = new DataTable ();
+                       DataColumn col1 = table.Columns.Add ("col1", typeof (int));
+                       DataColumn col2 = table.Columns.Add ("col2", typeof (int));
+                       DataColumn col3 = table.Columns.Add ("col3", typeof (int));
+
+                       col1.AllowDBNull = false;
+                       table.Constraints.Add ("uc", new DataColumn[] {col2,col3}, false);
+                       table.BeginLoadData ();
+                       table.Rows.Add (new object[] {null,1,1});
+                       table.Rows.Add (new object[] {1,1,1});
+                       try {
+                               table.EndLoadData ();
+                               Assert.Fail ("#0");
+                       } catch (ConstraintException) {}
+                       Assert.IsTrue (table.HasErrors, "#1");
+                       DataRow[] rows = table.GetErrors ();
+
+                       Assert.AreEqual (2, rows.Length, "#2");
+                       Assert.AreEqual ("Column 'col1' does not allow DBNull.Value.", table.Rows [0].RowError, "#3");
+                       Assert.AreEqual ("Column 'col2, col3' is constrained to be unique.  Value '1, 1' is already present."
+                                       , table.Rows [1].RowError, "#4");
+
+                       Assert.AreEqual (table.Rows [0].RowError, table.Rows [0].GetColumnError (0), "#5");
+                       Assert.AreEqual (table.Rows [1].RowError, table.Rows [0].GetColumnError (1), "#6");
+                       Assert.AreEqual (table.Rows [1].RowError, table.Rows [0].GetColumnError (2), "#7");
+
+                       Assert.AreEqual ("", table.Rows [1].GetColumnError (0), "#8");
+                       Assert.AreEqual (table.Rows [1].RowError, table.Rows [1].GetColumnError (1), "#9");
+                       Assert.AreEqual (table.Rows [1].RowError, table.Rows [1].GetColumnError (2), "#10");
+               }
+
                [Test]
-               public void BeginEdit()\r
-               {\r
-                       DataTable myTable = new DataTable("myTable"); \r
-                       DataColumn dc = new DataColumn("Id",typeof(int));\r
-                       dc.Unique=true;\r
-                       myTable.Columns.Add(dc);\r
-                       myTable.Rows.Add(new object[] {1});\r
-                       myTable.Rows.Add(new object[] {2});\r
-                       myTable.Rows.Add(new object[] {3});\r
-                       \r
-                       DataRow myRow = myTable.Rows[0];\r
-                       \r
-                       try     \r
-                       { \r
-                               myRow[0] = 2; //row[0] now conflict with row[1] \r
-                               Assert.Fail("DRW121: failed to throw ConstraintException");\r
-                       }\r
-                       catch (ConstraintException) {}\r
-                       catch (AssertionException exc) {throw  exc;}\r
-                       catch (Exception exc)\r
-                       {\r
-                               Assert.Fail("DRW122: Add. Wrong exception type. Got:" + exc);\r
-                       }\r
-\r
-                       //Will NOT! throw exception\r
-                       myRow.BeginEdit();\r
-                       myRow[0] = 2; //row[0] now conflict with row[1] \r
-                                       \r
-                       DataTable dt = DataProvider.CreateParentDataTable();\r
-                       DataRow dr = dt.Rows[0];\r
-                       dr.Delete();\r
-                       try\r
-                       {\r
-                               dr.BeginEdit();                         \r
-                               Assert.Fail("DRW123: failed to throw DeletedRowInaccessibleException");\r
-                       }\r
-                       catch (DeletedRowInaccessibleException) {}\r
-                       catch (AssertionException exc) {throw  exc;}\r
-                       catch (Exception exc)\r
-                       {\r
-                               Assert.Fail("DRW124: Add. Wrong exception type. Got:" + exc);\r
-                       }\r
+               public void BeginEdit()
+               {
+                       DataTable myTable = new DataTable("myTable"); 
+                       DataColumn dc = new DataColumn("Id",typeof(int));
+                       dc.Unique=true;
+                       myTable.Columns.Add(dc);
+                       myTable.Rows.Add(new object[] {1});
+                       myTable.Rows.Add(new object[] {2});
+                       myTable.Rows.Add(new object[] {3});
+                       
+                       DataRow myRow = myTable.Rows[0];
+                       
+                       try     
+                       { 
+                               myRow[0] = 2; //row[0] now conflict with row[1] 
+                               Assert.Fail("DRW121: failed to throw ConstraintException");
+                       }
+                       catch (ConstraintException) {}
+                       catch (AssertionException exc) {throw  exc;}
+                       catch (Exception exc)
+                       {
+                               Assert.Fail("DRW122: Add. Wrong exception type. Got:" + exc);
+                       }
+
+                       //Will NOT! throw exception
+                       myRow.BeginEdit();
+                       myRow[0] = 2; //row[0] now conflict with row[1] 
+                                       
+                       DataTable dt = DataProvider.CreateParentDataTable();
+                       DataRow dr = dt.Rows[0];
+                       dr.Delete();
+                       try
+                       {
+                               dr.BeginEdit();                         
+                               Assert.Fail("DRW123: failed to throw DeletedRowInaccessibleException");
+                       }
+                       catch (DeletedRowInaccessibleException) {}
+                       catch (AssertionException exc) {throw  exc;}
+                       catch (Exception exc)
+                       {
+                               Assert.Fail("DRW124: Add. Wrong exception type. Got:" + exc);
+                       }
                }
 
                [Test]
-               public void GetChildRows_DataRelation()\r
-               {\r
-                       DataRow dr;\r
-                       DataRow[] drArrExcepted,drArrResult;\r
-                       DataTable dtChild,dtParent;\r
-                       DataSet ds = new DataSet();\r
-\r
-                       //Create tables\r
-                       dtChild = DataProvider.CreateChildDataTable();\r
-                       dtParent= DataProvider.CreateParentDataTable(); \r
-\r
-                       //Add tables to dataset\r
-                       ds.Tables.Add(dtChild);\r
-                       ds.Tables.Add(dtParent);\r
-                       dr = dtParent.Rows[0];\r
-\r
-                       //Add Relation\r
-                       DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);\r
-                       ds.Relations.Add(dRel);\r
-                       //Get Excepted result\r
-                       drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);\r
-                       //Get Result\r
-                       drArrResult = dr.GetChildRows(dRel);\r
-                       \r
-                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW125");\r
+               public void GetChildRows_DataRelation()
+               {
+                       DataRow dr;
+                       DataRow[] drArrExcepted,drArrResult;
+                       DataTable dtChild,dtParent;
+                       DataSet ds = new DataSet();
+
+                       //Create tables
+                       dtChild = DataProvider.CreateChildDataTable();
+                       dtParent= DataProvider.CreateParentDataTable(); 
+
+                       //Add tables to dataset
+                       ds.Tables.Add(dtChild);
+                       ds.Tables.Add(dtParent);
+                       dr = dtParent.Rows[0];
+
+                       //Add Relation
+                       DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+                       ds.Relations.Add(dRel);
+                       //Get Excepted result
+                       drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);
+                       //Get Result
+                       drArrResult = dr.GetChildRows(dRel);
+                       
+                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW125");
                }
 
                [Test]
-               public void GetParentRows_DataRelation_DataRowVersion()\r
-               {\r
-                       DataRow drParent,drChild;\r
-                       DataRow[] drArrExcepted,drArrResult;\r
-                       DataTable dtChild,dtParent;\r
-                       DataSet ds = new DataSet();\r
-                       //Create tables\r
-                       dtChild = DataProvider.CreateChildDataTable();\r
-                       dtParent= DataProvider.CreateParentDataTable(); \r
-                       //Add tables to dataset\r
-                       ds.Tables.Add(dtChild);\r
-                       ds.Tables.Add(dtParent);\r
-                                       \r
-                       drParent = dtParent.Rows[0];\r
-                       drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];\r
-\r
-                       //Duplicate several rows in order to create Many to Many relation\r
-                       dtParent.ImportRow(drParent); \r
-                       dtParent.ImportRow(drParent); \r
-                       dtParent.ImportRow(drParent);                           \r
-                                       \r
-                       //Add Relation\r
-                       DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);\r
-                       ds.Relations.Add(dRel);\r
-\r
-                       //Get Excepted result\r
-                       drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );\r
-                       //Get Result DataRowVersion.Current\r
-                       drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Current);\r
-                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW126");\r
-\r
-                       //Get Excepted result\r
-                       drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );\r
-                       //Get Result DataRowVersion.Current\r
-                       drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Original );\r
-                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW127");\r
-\r
-                       //Get Excepted result, in this case Current = Default\r
-                       drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);\r
-                       //Get Result DataRowVersion.Current\r
-                       drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Default  );\r
-                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW128");\r
-                       \r
-                       try\r
-                       {\r
-                               DataTable dtOtherParent = DataProvider.CreateParentDataTable();\r
-                               DataTable dtOtherChild = DataProvider.CreateChildDataTable();\r
-\r
-                               DataRelation drl = new DataRelation("newRelation",dtOtherParent.Columns[0],dtOtherChild.Columns[0]);\r
-                               drChild.GetParentRows(drl,DataRowVersion.Current); \r
-                               Assert.Fail("DRW129: failed to throw ArgumentException");\r
-                       }\r
-                       catch (ArgumentException) {}\r
-                       catch (AssertionException exc) {throw  exc;}\r
-                       catch (Exception exc)\r
-                       {\r
-                               Assert.Fail("DRW130: Add. Wrong exception type. Got:" + exc);\r
+               public void GetParentRows_DataRelation_DataRowVersion()
+               {
+                       DataRow drParent,drChild;
+                       DataRow[] drArrExcepted,drArrResult;
+                       DataTable dtChild,dtParent;
+                       DataSet ds = new DataSet();
+                       //Create tables
+                       dtChild = DataProvider.CreateChildDataTable();
+                       dtParent= DataProvider.CreateParentDataTable(); 
+                       //Add tables to dataset
+                       ds.Tables.Add(dtChild);
+                       ds.Tables.Add(dtParent);
+                                       
+                       drParent = dtParent.Rows[0];
+                       drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
+
+                       //Duplicate several rows in order to create Many to Many relation
+                       dtParent.ImportRow(drParent); 
+                       dtParent.ImportRow(drParent); 
+                       dtParent.ImportRow(drParent);                           
+                                       
+                       //Add Relation
+                       DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
+                       ds.Relations.Add(dRel);
+
+                       //Get Excepted result
+                       drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
+                       //Get Result DataRowVersion.Current
+                       drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Current);
+                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW126");
+
+                       //Get Excepted result
+                       drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
+                       //Get Result DataRowVersion.Current
+                       drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Original );
+                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW127");
+
+                       //Get Excepted result, in this case Current = Default
+                       drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
+                       //Get Result DataRowVersion.Current
+                       drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Default  );
+                       Assert.AreEqual(drArrExcepted, drArrResult, "DRW128");
+                       
+                       try
+                       {
+                               DataTable dtOtherParent = DataProvider.CreateParentDataTable();
+                               DataTable dtOtherChild = DataProvider.CreateChildDataTable();
+
+                               DataRelation drl = new DataRelation("newRelation",dtOtherParent.Columns[0],dtOtherChild.Columns[0]);
+                               drChild.GetParentRows(drl,DataRowVersion.Current); 
+                               Assert.Fail("DRW129: failed to throw ArgumentException");
+                       }
+                       catch (ArgumentException) {}
+                       catch (AssertionException exc) {throw  exc;}
+                       catch (Exception exc)
+                       {
+                               Assert.Fail("DRW130: Add. Wrong exception type. Got:" + exc);
                        }
                }
 
                [Test]
-               public void ItemArray()\r
-               {\r
-                       DataTable dt = GetDataTable();                          \r
-                       DataRow dr = dt.Rows[0];\r
-               \r
-                       Assert.AreEqual(1, (int)dr.ItemArray[0] , "DRW131" );\r
-\r
-                       Assert.AreEqual("Ofer", (string)dr.ItemArray[1] , "DRW132" );\r
-\r
-                       dt = GetDataTable();\r
-\r
-                       dr = dt.Rows[0];\r
-                       \r
-                       //Changing row via itemArray\r
-\r
-                       dt.Rows[0].ItemArray = new object[] {2,"Oren"};\r
-\r
-                       Assert.AreEqual(2, (Int32)dr.ItemArray[0] , "DRW133" );\r
-                       Assert.AreEqual("Oren", (string)dr.ItemArray[1] , "DRW134" );\r
-\r
-                       try\r
-                       {\r
-                               dt.Rows[0].ItemArray = new object[] {2,"Oren","some1else"};\r
-                               Assert.Fail("DRW135: failed to throw ArgumentException");\r
-                       }\r
-                       catch (ArgumentException) {}\r
-                       catch (AssertionException exc) {throw  exc;}\r
-                       catch (Exception exc)\r
-                       {\r
-                               Assert.Fail("DRW136: Add. Wrong exception type. Got:" + exc);\r
-                       }\r
-               }\r
+               public void ItemArray()
+               {
+                       DataTable dt = GetDataTable();
+                       DataRow dr = dt.Rows[0];
+
+                       Assert.AreEqual(1, (int)dr.ItemArray[0] , "DRW131" );
+
+                       Assert.AreEqual("Ofer", (string)dr.ItemArray[1] , "DRW132" );
+
+                       dt = GetDataTable();
+
+                       dr = dt.Rows[0];
+                       
+                       //Changing row via itemArray
+
+                       dt.Rows[0].ItemArray = new object[] {2,"Oren"};
+
+                       Assert.AreEqual(2, (Int32)dr.ItemArray[0] , "DRW133" );
+                       Assert.AreEqual("Oren", (string)dr.ItemArray[1] , "DRW134" );
+
+                       try
+                       {
+                               dt.Rows[0].ItemArray = new object[] {2,"Oren","some1else"};
+                               Assert.Fail("DRW135: failed to throw ArgumentException");
+                       }
+                       catch (ArgumentException) {}
+                       catch (AssertionException exc) {throw  exc;}
+                       catch (Exception exc)
+                       {
+                               Assert.Fail("DRW136: Add. Wrong exception type. Got:" + exc);
+                       }
+               }
 
                [Test]
                public void ItemArray_NewTable ()
@@ -1504,80 +2049,313 @@ namespace MonoTests.System.Data
                        // Should not throw RowNotInTableException
                        object[] obj = dr.ItemArray;
                }
-\r
-               private DataTable GetDataTable()\r
-               {\r
-                       DataTable dt = new DataTable("myTable"); \r
-                       dt.Columns.Add("Id",typeof(int));\r
-                       dt.Columns.Add("Name",typeof(string));\r
-\r
-                       DataRow dr = dt.NewRow();\r
-                       dr.ItemArray = new object[] {1,"Ofer"};\r
-\r
-                       dt.Rows.Add(dr);\r
-\r
-                       return dt;\r
-               }
-
-               public void RowError()\r
-               {\r
-                       DataTable dt = new DataTable("myTable"); \r
-                       DataRow dr = dt.NewRow();\r
-\r
-                       Assert.AreEqual(string.Empty , dr.RowError, "DRW137");\r
-                                               \r
-                       dr.RowError = "Err";            \r
-\r
-                       Assert.AreEqual("Err", dr.RowError , "DRW138" );\r
-\r
-                       DataTable dt1 = DataProvider.CreateUniqueConstraint();\r
-\r
-                       try\r
-                       {\r
-                               dt1.BeginLoadData();\r
-\r
-                               dr = dt1.NewRow();\r
-                               dr[0] = 3;\r
-                               dt1.Rows.Add(dr);\r
-                               dt1.EndLoadData();\r
-                               Assert.Fail("DRW139: failed to throw ConstraintException");\r
-                       }\r
-                       catch (ConstraintException) \r
-                       {\r
-                               Assert.AreEqual(2,dt1.GetErrors().Length,"DRW141");\r
-                               Assert.AreEqual(true,dt1.GetErrors()[0].RowError.Length > 10,"DRW142");\r
-                               Assert.AreEqual(true,dt1.GetErrors()[1].RowError.Length > 10,"DRW143");\r
-                       }\r
-                       catch (AssertionException exc) {throw  exc;}\r
-                       catch (Exception exc)\r
-                       {\r
-                               Assert.Fail("DRW144: Wrong exception type. Got:" + exc);\r
-                       }\r
-\r
-\r
-                       DataSet ds=null;\r
-                       try\r
-                       {\r
-                               ds= DataProvider.CreateForigenConstraint();\r
-                               ds.Tables[0].BeginLoadData();\r
-                               ds.Tables[0].Rows[0][0] = 10; //Forigen constraint violation\r
-                               //ds.Tables[0].AcceptChanges();\r
-                               ds.Tables[0].EndLoadData();\r
-                               Assert.Fail("DRW139: failed to throw ConstraintException");\r
-                       }\r
-                       catch (ConstraintException) \r
-                       {\r
-                               Assert.AreEqual(3,ds.Tables[1].GetErrors().Length,"DRW145");\r
-                               for(int index=0;index<3;index++)\r
-                               {\r
-                                       Assert.AreEqual(true,ds.Tables[1].GetErrors()[index].RowError.Length > 10,"RDW146");\r
-                               }\r
-                       }\r
-                       catch (AssertionException exc) {throw  exc;}\r
-                       catch (Exception exc)\r
-                       {\r
-                               Assert.Fail("DRW147: Wrong exception type. Got:" + exc);\r
-                       }\r
+
+               private DataTable GetDataTable()
+               {
+                       DataTable dt = new DataTable("myTable"); 
+                       dt.Columns.Add("Id",typeof(int));
+                       dt.Columns.Add("Name",typeof(string));
+
+                       DataRow dr = dt.NewRow();
+                       dr.ItemArray = new object[] {1,"Ofer"};
+
+                       dt.Rows.Add(dr);
+
+                       return dt;
+               }
+
+               [Test]
+               public void RowError()
+               {
+                       DataTable dt = new DataTable("myTable"); 
+                       DataRow dr = dt.NewRow();
+
+                       Assert.AreEqual(string.Empty , dr.RowError, "DRW137");
+
+                       dr.RowError = "Err";
+
+                       Assert.AreEqual("Err", dr.RowError , "DRW138" );
+
+                       DataTable dt1 = DataProvider.CreateUniqueConstraint();
+
+                       try
+                       {
+                               dt1.BeginLoadData();
+
+                               dr = dt1.NewRow();
+                               dr[0] = 3;
+                               dt1.Rows.Add(dr);
+                               dt1.EndLoadData();
+                               Assert.Fail("DRW139: failed to throw ConstraintException");
+                       }
+                       catch (ConstraintException) 
+                       {
+                               Assert.AreEqual(2,dt1.GetErrors().Length,"DRW141");
+                               Assert.AreEqual(true,dt1.GetErrors()[0].RowError.Length > 10,"DRW142");
+                               Assert.AreEqual(true,dt1.GetErrors()[1].RowError.Length > 10,"DRW143");
+                       }
+                       catch (AssertionException exc) {throw  exc;}
+                       catch (Exception exc)
+                       {
+                               Assert.Fail("DRW144: Wrong exception type. Got:" + exc);
+                       }
+
+
+                       DataSet ds=null;
+                       try
+                       {
+                               ds= DataProvider.CreateForigenConstraint();
+                               ds.Tables[0].BeginLoadData();
+                               ds.Tables[0].Rows[0][0] = 10; //Forigen constraint violation
+                               //ds.Tables[0].AcceptChanges();
+                               ds.Tables[0].EndLoadData();
+                               Assert.Fail("DRW139: failed to throw ConstraintException");
+                       }
+                       catch (ConstraintException) 
+                       {
+                               Assert.AreEqual(3,ds.Tables[1].GetErrors().Length,"DRW145");
+                               for(int index=0;index<3;index++)
+                               {
+                                       Assert.AreEqual(true,ds.Tables[1].GetErrors()[index].RowError.Length > 10,"RDW146");
+                               }
+                       }
+                       catch (AssertionException exc) {throw  exc;}
+                       catch (Exception exc)
+                       {
+                               Assert.Fail("DRW147: Wrong exception type. Got:" + exc);
+                       }
+               }
+
+               [Test]
+               public void bug78885 ()
+               {
+                       DataSet ds = new DataSet ();
+                       DataTable t = ds.Tables.Add ("table");
+                       DataColumn id;
+
+                       id = t.Columns.Add ("userID", Type.GetType ("System.Int32"));
+                       id.AutoIncrement = true;
+                       t.Columns.Add ("name", Type.GetType ("System.String"));
+                       t.Columns.Add ("address", Type.GetType ("System.String"));
+                       t.Columns.Add ("zipcode", Type.GetType ("System.Int32"));
+                       t.PrimaryKey = new DataColumn [] { id };
+
+                       DataRow tempRow;
+                       tempRow = t.NewRow ();
+                       tempRow ["name"] = "Joan";
+                       tempRow ["address"] = "Balmes 152";
+                       tempRow ["zipcode"] = "1";
+                       t.Rows.Add (tempRow);
+
+                       t.RowChanged += new DataRowChangeEventHandler (RowChangedHandler);
+
+                       /* neither of the calls to EndEdit below generate a RowChangedHandler on MS.  the first one does on mono */
+                       t.DefaultView [0].BeginEdit ();
+                       t.DefaultView [0].EndEdit (); /* this generates a call to the row changed handler */
+                       t.DefaultView [0].EndEdit (); /* this doesn't */
+
+                       Assert.IsFalse (_rowChanged);
+               }
+
+               private void RowChangedHandler (object sender, DataRowChangeEventArgs e)
+               {
+                       _rowChanged = true;
+               }
+
+#if NET_2_0
+               string SetAddedModified_ErrMsg = "SetAdded and SetModified can only be called on DataRows with Unchanged DataRowState.";
+               [Test]
+               public void SetAdded_test()
+               {
+                       DataTable table = new DataTable();
+
+                       DataRow row = table.NewRow();
+                       try {
+                               row.SetAdded();
+                               Assert.Fail ("#1");
+                       } catch (InvalidOperationException e) {
+                               // Never premise English.
+                               //Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
+                       }
+
+                       table.Columns.Add("col1", typeof(int));
+                       table.Columns.Add("col2", typeof(int));
+                       table.Columns.Add("col3", typeof(int));
+
+                       row = table.Rows.Add(new object[] { 1, 2, 3 });
+                       Assert.AreEqual(DataRowState.Added, row.RowState, "#1");
+                       try {
+                               row.SetAdded();
+                               Assert.Fail ("#2");
+                       } catch (InvalidOperationException e) {
+                               // Never premise English.
+                               //Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
+                       }
+                       Assert.AreEqual(DataRowState.Added, row.RowState, "#2");
+
+                       row.AcceptChanges();
+                       row[0] = 10;
+                       Assert.AreEqual(DataRowState.Modified, row.RowState, "#5");
+                       try {
+                               row.SetAdded();
+                               Assert.Fail ("#3");
+                       } catch (InvalidOperationException e) {
+                               // Never premise English.
+                               //Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
+                       }
+
+                       row.AcceptChanges();
+                       Assert.AreEqual(DataRowState.Unchanged, row.RowState, "#3");
+                       row.SetAdded();
+                       Assert.AreEqual(DataRowState.Added, row.RowState, "#4");
+               }
+
+               [Test]
+               public void setAdded_testRollback ()
+               {
+                       DataTable table = new DataTable ();
+                       table.Columns.Add ("col1", typeof (int));
+                       table.Columns.Add ("col2", typeof (int));
+
+                       table.Rows.Add (new object[] {1,1});
+                       table.AcceptChanges ();
+
+                       table.Rows [0].SetAdded ();
+                       table.RejectChanges ();
+                       Assert.AreEqual (0, table.Rows.Count, "#1");
+               }
+
+               [Test]
+               public void SetModified_test()
+               {
+                       DataTable table = new DataTable();
+
+                       DataRow row = table.NewRow();
+                       try {
+                               row.SetModified ();
+                       } catch (InvalidOperationException) {}
+
+                       table.Columns.Add("col1", typeof(int));
+                       table.Columns.Add("col2", typeof(int));
+                       table.Columns.Add("col3", typeof(int));
+
+                       row = table.Rows.Add(new object[] { 1, 2, 3 });
+                       Assert.AreEqual(DataRowState.Added, row.RowState, "#1");
+                       try {
+                               row.SetModified();
+                               Assert.Fail ("#1");
+                       } catch (InvalidOperationException e) {
+                               // Never premise English.
+                               //Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
+                       }
+
+                       row.AcceptChanges();
+                       row[0] = 10;
+                       Assert.AreEqual(DataRowState.Modified, row.RowState, "#5");
+                       try {
+                               row.SetModified ();
+                               Assert.Fail ("#2");
+                       } catch (InvalidOperationException e) {
+                               // Never premise English.
+                               //Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
+                       }
+
+                       row.AcceptChanges();
+                       Assert.AreEqual(DataRowState.Unchanged, row.RowState, "#3");
+                       row.SetModified ();
+                       Assert.AreEqual(DataRowState.Modified, row.RowState, "#4");
+               }
+
+               [Test]
+               public void setModified_testRollback()
+               {
+                       DataTable table = new DataTable();
+                       table.Columns.Add("col1", typeof(int));
+                       table.Columns.Add("col2", typeof(int));
+
+                       DataRow row = table.Rows.Add(new object[] { 1, 1 });
+                       table.AcceptChanges();
+
+                       row.SetModified ();
+                       Assert.AreEqual(row.RowState, DataRowState.Modified, "#0");
+                       Assert.AreEqual(1, row [0, DataRowVersion.Current], "#1");
+                       Assert.AreEqual(1, row [0, DataRowVersion.Original], "#2");
+                       table.RejectChanges ();
+                       Assert.AreEqual(row.RowState, DataRowState.Unchanged, "#3");
+               }
+#endif
+               [Test]
+               public void DataRowExpressionDefaultValueTest ()
+               {
+                       DataSet ds = new DataSet ();
+                       DataTable custTable = ds.Tables.Add ("CustTable");
+
+                       DataColumn column = new DataColumn ("units", typeof (int));
+                       column.AllowDBNull = false;
+                       column.Caption = "Units";
+                       column.DefaultValue = 1;
+                       custTable.Columns.Add (column);
+
+                       column = new DataColumn ("price", typeof (decimal));
+                       column.AllowDBNull = false;
+                       column.Caption = "Price";
+                       column.DefaultValue = 25;
+                       custTable.Columns.Add (column);
+
+                       column = new DataColumn ("total", typeof (string));
+                       column.Caption = "Total";
+                       column.Expression = "price*units";
+                       custTable.Columns.Add (column);
+
+                       DataRow row = custTable.NewRow ();
+
+                       Assert.AreEqual (DBNull.Value, row["Total"] , "#1 Should be System.DBNull");
+                       custTable.Rows.Add (row);
+
+                       Assert.AreEqual ("25", row["Total"] , "#2 Should not be emptry string");
+               }
+
+               class Person
+               {
+                       public Person (string name)
+                       {
+                               this.Name = name;
+                       }
+
+                       public string Name;
+                       public Address HomeAddress;
+               }
+
+               struct Address
+               {
+                       public Address (string street, int houseNumber)
+                       {
+                               Street = street;
+                               HouseNumber = houseNumber;
+                       }
+
+                       public override bool Equals (object o)
+                       {
+                               if (!(o is Address))
+                                       return false;
+
+                               Address address = (Address) o;
+                               if (address.HouseNumber != HouseNumber)
+                                       return false;
+                               if (address.Street != Street)
+                                       return false;
+                               return true;
+                       }
+
+                       public override int GetHashCode ()
+                       {
+                               if (Street == null)
+                                       return HouseNumber.GetHashCode ();
+                               return (Street.GetHashCode () ^ HouseNumber.GetHashCode ());
+                       }
+
+                       public string Street;
+                       public int HouseNumber;
                }
        }
 }