diff options
author | Senganal T <senga@mono-cvs.ximian.com> | 2006-02-11 14:11:48 +0300 |
---|---|---|
committer | Senganal T <senga@mono-cvs.ximian.com> | 2006-02-11 14:11:48 +0300 |
commit | 16a08b18be152162b3216d5899360262fdbbc958 (patch) | |
tree | 7c00ed837e882e599284002874d85b73a196d2a3 /mcs/class/System.Data/Test | |
parent | b3c23ed2150f499aa2cda370176a60a1f1cd794b (diff) |
2006-02-11 Senganal T <tsenganal@novell.com>
* Test/System.Data/DataTableTest.cs : Check AllowDBNull is set to false for PrimaryKey cols.
* Test/System.Data/DataTableTest2.cs : added testcases for bug #77404
* System.Data/UniqueConstraint.cs :
- PostAddRange : Check PrimaryKey is not already set for the table
* System.Data/DataTable.cs :
- PrimaryKey : follow ms.net behavior when BeginInit , EndInit is used.
- Add new priamry key only when EndInit is called.
- Incase of an error, retain old primarykey
- EndInit :
- Add Constraints after columns are added.
- If both PrimaryKey Property and PrimaryKey Constraint are set,
then the Constraint takes precedence.
fixes bug #77404
svn path=/branches/mono-1-1-13/mcs/; revision=56791
Diffstat (limited to 'mcs/class/System.Data/Test')
-rw-r--r-- | mcs/class/System.Data/Test/System.Data/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/class/System.Data/Test/System.Data/DataTableTest.cs | 9 | ||||
-rw-r--r-- | mcs/class/System.Data/Test/System.Data/DataTableTest2.cs | 85 |
3 files changed, 96 insertions, 3 deletions
diff --git a/mcs/class/System.Data/Test/System.Data/ChangeLog b/mcs/class/System.Data/Test/System.Data/ChangeLog index f4630c6af3f..a7f16add0c7 100644 --- a/mcs/class/System.Data/Test/System.Data/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data/ChangeLog @@ -1,3 +1,8 @@ +2006-02-11 Senganal T <tsenganal@novell.com> + + * DataTableTest.cs : Check AllowDBNull is set to false for PrimaryKey cols. + * DataTableTest2.cs : added testcases for bug #77404 + 2006-02-03 Senganal T <tsenganal@novell.com> * DataTableCollectionTest2.cs,EvaluateExceptionTest.cs, diff --git a/mcs/class/System.Data/Test/System.Data/DataTableTest.cs b/mcs/class/System.Data/Test/System.Data/DataTableTest.cs index aac0a0ba72c..c432b539409 100644 --- a/mcs/class/System.Data/Test/System.Data/DataTableTest.cs +++ b/mcs/class/System.Data/Test/System.Data/DataTableTest.cs @@ -1427,10 +1427,15 @@ namespace MonoTests.System.Data AssertEquals ("#1" , true, col1.AllowDBNull); AssertEquals ("#2" , true, col2.AllowDBNull); + AssertEquals ("#3" , false, col2.Unique); + AssertEquals ("#4" , false, col2.Unique); table.PrimaryKey = new DataColumn[] {col1,col2}; - AssertEquals ("#1" , false, col1.AllowDBNull); - AssertEquals ("#2" , false, col2.AllowDBNull); + AssertEquals ("#5" , false, col1.AllowDBNull); + AssertEquals ("#6" , false, col2.AllowDBNull); + // LAMESPEC or bug ?? + AssertEquals ("#7" , false, col1.Unique); + AssertEquals ("#8" , false, col2.Unique); } void RowChanging (object o, DataRowChangeEventArgs e) diff --git a/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs b/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs index d5c83326c5a..368101ddb69 100644 --- a/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs +++ b/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs @@ -1865,7 +1865,90 @@ namespace MonoTests_System.Data }
dt.RowDeleting -= new DataRowChangeEventHandler(OnRowDeleting_Handler);
}
-
+ + [Test] + public void BeginInit_PrimaryKey_1 () + { + DataTable table = new DataTable (); + DataColumn col = table.Columns.Add ("col", typeof (int)); + table.PrimaryKey = new DataColumn[] {col}; + table.AcceptChanges (); + Assert.AreEqual (1, table.PrimaryKey.Length, "#1"); + + table.BeginInit (); + DataColumn col2 = new DataColumn ("col2", typeof (int)); + table.Columns.AddRange (new DataColumn[] {col2}); + table.PrimaryKey = new DataColumn[] {col2}; + table.EndInit (); + Assert.AreEqual (1, table.PrimaryKey.Length, "#2"); + Assert.AreEqual ("col2", table.PrimaryKey[0].ColumnName, "#3"); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void BeginInit_PrimaryKey_2() + { + DataTable table = new DataTable (); + DataColumn col = table.Columns.Add ("col", typeof (int)); + table.PrimaryKey = new DataColumn[] {col}; + table.AcceptChanges (); + + // ms.net behavior. + table.BeginInit (); + DataColumn col1 = new DataColumn ("col1", typeof (int)); + table.Columns.AddRange (new DataColumn[] {col1}); + UniqueConstraint uc = new UniqueConstraint ("", new String[] {"col1"}, true); + table.Constraints.AddRange (new Constraint[] {uc}); + table.EndInit (); + } + + [Test] + public void BeginInit_PrimaryKey_3 () + { + DataTable table = new DataTable (); + DataColumn col1 = table.Columns.Add ("col1", typeof (int)); + DataColumn col2 = table.Columns.Add ("col2", typeof (int)); + + // ms.net behavior + table.BeginInit (); + UniqueConstraint uc = new UniqueConstraint ("", new String[] {"col1"}, true); + table.Constraints.AddRange (new Constraint[] {uc}); + table.PrimaryKey = new DataColumn [] {col2}; + table.EndInit (); + + Assert.AreEqual ("col1", table.PrimaryKey[0].ColumnName, "#1"); + } + + [Test] + public void PrimaryKey_OnFailing () + { + DataTable table = new DataTable (); + DataColumn col1 = table.Columns.Add ("col1", typeof (int)); + table.PrimaryKey = new DataColumn[] {col1}; + try { + table.PrimaryKey = new DataColumn[] { new DataColumn ("col2", typeof (int))}; + } catch (Exception e) {} + Assert.AreEqual ("col1", table.PrimaryKey[0].ColumnName, "#1"); + } + + [Test] + public void BeginInit_Cols_Constraints () + { + DataTable table = new DataTable (); + + // if both cols and constraints are added after BeginInit, the cols + // should be added, before the constraints are added/validated + table.BeginInit (); + DataColumn col1 = new DataColumn ("col1", typeof (int)); + table.Columns.AddRange (new DataColumn[] {col1}); + UniqueConstraint uc = new UniqueConstraint ("", new String[] {"col1"}, false); + table.Constraints.AddRange (new Constraint[] {uc}); + // no exception shud be thrown + table.EndInit (); + + Assert.AreEqual (1, table.Constraints.Count, "#1"); + } + private void OnRowDeleting_Handler(Object sender,DataRowChangeEventArgs e)
{
|