diff options
author | Sureshkumar T <suresh@mono-cvs.ximian.com> | 2005-09-20 16:19:28 +0400 |
---|---|---|
committer | Sureshkumar T <suresh@mono-cvs.ximian.com> | 2005-09-20 16:19:28 +0400 |
commit | afef6566bc920952c6a977ee03a650fad1aca644 (patch) | |
tree | bd9512d49c68a037eddf2336584c628de6eb2c10 /mcs/class/System.Data/Test | |
parent | 4233916a25d03ddc5eaa8d95cf8cab6833c0ed97 (diff) |
In Test/System.Data:
(SortTests): Added cases for sorting order. TestCase from Marc
In System.Data:
* DataView.cs (Sort): Apply default Sorting Order if Sort property
is reset to null. Sort property handles this. Patch from Marc.
svn path=/trunk/mcs/; revision=50292
Diffstat (limited to 'mcs/class/System.Data/Test')
-rw-r--r-- | mcs/class/System.Data/Test/System.Data/ChangeLog | 1 | ||||
-rw-r--r-- | mcs/class/System.Data/Test/System.Data/DataViewTest.cs | 49 |
2 files changed, 49 insertions, 1 deletions
diff --git a/mcs/class/System.Data/Test/System.Data/ChangeLog b/mcs/class/System.Data/Test/System.Data/ChangeLog index 02f85d517c3..c7ea1072250 100644 --- a/mcs/class/System.Data/Test/System.Data/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data/ChangeLog @@ -2,6 +2,7 @@ * DataViewTest.cs: Added a case for Sort to accept columns with '[' & ']'. + (SortTests): Added cases for sorting order. TestCase from Marc 2005-08-02 Sureshkumar T <tsureshkumar@novell.com> diff --git a/mcs/class/System.Data/Test/System.Data/DataViewTest.cs b/mcs/class/System.Data/Test/System.Data/DataViewTest.cs index 730a110434f..713470a12cf 100644 --- a/mcs/class/System.Data/Test/System.Data/DataViewTest.cs +++ b/mcs/class/System.Data/Test/System.Data/DataViewTest.cs @@ -228,7 +228,7 @@ namespace MonoTests.System.Data #region Sort Tests [Test] - public void SortTest () + public void SortListChangedTest () { dataView.Sort = "itemName DESC"; AssertEquals ("test#01",ListChangedType.Reset,listChangedArgs.ListChangedType); @@ -254,6 +254,53 @@ namespace MonoTests.System.Data dv.Sort = "[[id] ASC"; } + + [Test] + public void SortTests () + { + DataTable dataTable = new DataTable ("itemTable"); + DataColumn dc1 = new DataColumn ("itemId", typeof(int)); + DataColumn dc2 = new DataColumn ("itemName", typeof(string)); + + dataTable.Columns.Add (dc1); + dataTable.Columns.Add (dc2); + + dataTable.Rows.Add (new object[2] { 1, "First entry" }); + dataTable.Rows.Add (new object[2] { 0, "Second entry" }); + dataTable.Rows.Add (new object[2] { 3, "Third entry" }); + dataTable.Rows.Add (new object[2] { 2, "Fourth entry" }); + + DataView dataView = dataTable.DefaultView; + + string s = "Default sorting: "; + AssertEquals (s + "First entry has wrong item", 1, dataView[0][0]); + AssertEquals (s + "Second entry has wrong item", 0, dataView[1][0]); + AssertEquals (s + "Third entry has wrong item", 3, dataView[2][0]); + AssertEquals (s + "Fourth entry has wrong item", 2, dataView[3][0]); + + s = "Ascending sorting: "; + dataView.Sort = "itemId ASC"; + AssertEquals (s + "First entry has wrong item", 0, dataView[0][0]); + AssertEquals (s + "Second entry has wrong item", 1, dataView[1][0]); + AssertEquals (s + "Third entry has wrong item", 2, dataView[2][0]); + AssertEquals (s + "Fourth entry has wrong item", 3, dataView[3][0]); + + s = "Descending sorting: "; + dataView.Sort = "itemId DESC"; + AssertEquals (s + "First entry has wrong item", 3, dataView[0][0]); + AssertEquals (s + "Second entry has wrong item", 2, dataView[1][0]); + AssertEquals (s + "Third entry has wrong item", 1, dataView[2][0]); + AssertEquals (s + "Fourth entry has wrong item", 0, dataView[3][0]); + + s = "Reverted to default sorting: "; + dataView.Sort = null; + AssertEquals (s + "First entry has wrong item", 1, dataView[0][0]); + AssertEquals (s + "Second entry has wrong item", 0, dataView[1][0]); + AssertEquals (s + "Third entry has wrong item", 3, dataView[2][0]); + AssertEquals (s + "Fourth entry has wrong item", 2, dataView[3][0]); + + } + #endregion // Sort Tests [Test] |