System.Data/DataRow.cs: AcceptChanges: raise row changing & row changed events.
authorSureshkumar T <suresh@mono-cvs.ximian.com>
Wed, 4 May 2005 10:53:00 +0000 (10:53 -0000)
committerSureshkumar T <suresh@mono-cvs.ximian.com>
Wed, 4 May 2005 10:53:00 +0000 (10:53 -0000)
Test/System.Data/DataTableTest.cs: Added a test to check whether Commit RowChanging & RowChanged event is fired.

svn path=/trunk/mcs/; revision=44016

mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/DataRow.cs
mcs/class/System.Data/Test/System.Data/ChangeLog
mcs/class/System.Data/Test/System.Data/DataTableTest.cs

index c3a8fb1a72390c63b8a09a16f090f92baf4d198c..bb06a5f31f493dd16818ee2019408df198290c2a 100644 (file)
@@ -1,5 +1,8 @@
 2005-05-04  Sureshkumar T  <tsureshkumar@novell.com>
 
+       * DataRow.cs: AcceptChanges: raise row changing & row changed
+       events.
+
        * DataRowCollection.cs: Clear : remove rows from indexes
 
 2005-05-02  Atsushi Enomoto  <atsushi@ximian.com>
index cbc95c861ae1b5836f75fb6277d032ffd4e338ab..c24beb6600f17252b594168f5aa8c74ec5e31852 100644 (file)
@@ -590,6 +590,8 @@ namespace System.Data {
                public void AcceptChanges () 
                {
                        EndEdit(); // in case it hasn't been called
+
+                        _table.ChangingDataRow (this, DataRowAction.Commit);
                        switch (rowState) {
                                case DataRowState.Unchanged:
                                        return;
@@ -607,6 +609,8 @@ namespace System.Data {
                        // Accept from detached
                        if (_original != _current)
                                Original = Current;
+
+                        _table.ChangedDataRow (this, DataRowAction.Commit);
                }
 
                /// <summary>
index 3f8adf9bfb0499bd7aa53ebcbbee44ae5973775c..247b0237dcc945a7eed680b6bfddc57345efe8ee 100644 (file)
@@ -1,8 +1,10 @@
 2005-05-04  Sureshkumar T  <tsureshkumar@novell.com>
 
-       * DataTableTest.cs: Added a test for DataTable. Should clear rows
-       from indexes as well. Simplified table creation for ClearReset
-       test.
+       * DataTableTest.cs: 
+       - Added a test for DataTable. Should clear rows from indexes as
+       well. Simplified table creation for ClearReset test.
+       - Added a test to check whether Commit RowChanging & RowChanged
+       event is fired.
 
 2005-04-29  Sureshkumar T  <tsureshkumar@novell.com>
 
index ed3ea11ff559d2b152b69f0a91045c2f034ca638..748275977aab3104c21cc1a70912b24de6c62c59 100644 (file)
@@ -1341,6 +1341,47 @@ namespace MonoTests.System.Data
                         MyDataTable dt = (MyDataTable)(dt1.Clone());
                         AssertEquals("A#01",2,MyDataTable.count);
                 }
+
+                DataRowAction rowActionChanging = DataRowAction.Nothing;
+                DataRowAction rowActionChanged  = DataRowAction.Nothing;
+                [Test]
+                public void AcceptChangesTest ()
+                {
+                        DataTable dt = new DataTable ("test");
+                        dt.Columns.Add ("id", typeof (int));
+                        dt.Columns.Add ("name", typeof (string));
+                        
+                        dt.Rows.Add (new object [] { 1, "mono 1" });
+
+                        dt.RowChanged  += new DataRowChangeEventHandler (OnRowChanged);
+                        dt.RowChanging += new DataRowChangeEventHandler (OnRowChanging);
+
+                        try {
+                                rowActionChanged = rowActionChanging = DataRowAction.Nothing;
+                                dt.AcceptChanges ();
+
+                                AssertEquals ("#1 should have fired event and set action to commit",
+                                              DataRowAction.Commit, rowActionChanging);
+                                AssertEquals ("#2 should have fired event and set action to commit",
+                                              DataRowAction.Commit, rowActionChanged);
+
+                        } finally {
+                                dt.RowChanged  -= new DataRowChangeEventHandler (OnRowChanged);
+                                dt.RowChanging -= new DataRowChangeEventHandler (OnRowChanging);
+
+                        }
+                }
+
+                public void OnRowChanging (object src, DataRowChangeEventArgs args)
+                {
+                        rowActionChanging = args.Action;
+                }
+                
+                public void OnRowChanged (object src, DataRowChangeEventArgs args)
+                {
+                        rowActionChanged = args.Action;
+                }
+                
                                                                                                     
         }