1 // DataViewTest_IBindingListView.cs - Nunit Test Cases for for testing the DataView
2 // class for IBindingListView Implementation
5 // Senganal T <tsenganal@novell.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.ComponentModel;
34 using NUnit.Framework;
36 namespace MonoTests.System.Data
39 public class DataViewTest_IBindingListView
41 DataTable table = null;
44 public void TestFixtureSetUp ()
46 table = new DataTable ("table");
47 table.Columns.Add ("col1", typeof(int));
48 table.Columns.Add ("col2", typeof(int));
49 table.Columns.Add ("col3", typeof(int));
51 table.Rows.Add (new object[] { 1, 1, 1 });
52 table.Rows.Add (new object[] { 1, 1, 2 });
53 table.Rows.Add (new object[] { 1, 2, 1 });
54 table.Rows.Add (new object[] { 1, 2, 2 });
55 table.Rows.Add (new object[] { 2, 0, 0 });
56 table.Rows.Add (new object[] { 2, 1, 0 });
57 table.Rows.Add (new object[] { 2, 1, 1 });
58 table.Rows.Add (new object[] { 2, 1, 2 });
59 table.Rows.Add (new object[] { 2, 2, 1 });
60 table.Rows.Add (new object[] { 2, 2, 2 });
64 public void FilterTest()
66 IBindingListView view = (IBindingListView) new DataView (table);
69 Assert.AreEqual (table.Rows.Count, view.Count, "#1");
72 Assert.AreEqual (table.Rows.Count, view.Count, "#2");
74 view.Filter = "col1 <> 1";
75 Assert.AreEqual (view.Filter, ((DataView)view).RowFilter, "#4");
76 Assert.AreEqual (6, view.Count, "#5");
80 Assert.AreEqual ("", view.Filter, "#6");
81 Assert.AreEqual ("", ((DataView)view).RowFilter, "#7");
82 Assert.AreEqual (table.Rows.Count, view.Count, "#8");
86 public void SortDescriptionTest()
88 IBindingListView view = (IBindingListView)new DataView (table);
90 ListSortDescriptionCollection col = view.SortDescriptions;
92 ((DataView)view).Sort = "";
93 col = view.SortDescriptions;
94 Assert.AreEqual (0, col.Count, "#1");
96 ((DataView)view).Sort = null;
97 col = view.SortDescriptions;
98 Assert.AreEqual (0, col.Count, "#2");
100 ((DataView)view).Sort = "col1 DESC, col2 ASC";
101 col = view.SortDescriptions;
102 Assert.AreEqual (2, col.Count, "#3");
103 Assert.AreEqual ("col1", col[0].PropertyDescriptor.Name, "#4");
104 Assert.AreEqual (ListSortDirection.Descending, col[0].SortDirection, "#5");
105 Assert.AreEqual ("col2", col[1].PropertyDescriptor.Name, "#6");
106 Assert.AreEqual (ListSortDirection.Ascending, col[1].SortDirection, "#7");
109 IBindingListView view1 = (IBindingListView)new DataView (table);
111 Assert.IsFalse (view.Equals(view1), "#8");
112 view1.ApplySort (col);
113 Assert.AreEqual ("[col1] DESC,[col2]", ((DataView)view1).Sort, "#9");
114 for (int i = 0; i < view.Count; ++i)
115 Assert.AreEqual (((DataView)view)[i].Row, ((DataView)view1)[i].Row, "#10"+i);
119 public void ReadOnlyPropTest()
121 IBindingListView view = (IBindingListView)new DataView (table);
122 Assert.IsTrue (view.SupportsAdvancedSorting, "#1");
123 Assert.IsTrue (view.SupportsFiltering, "#2");