[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Data / Test / System.Data / DataViewTest_IBindingListView.cs
1 // DataViewTest_IBindingListView.cs - Nunit Test Cases for for testing the DataView
2 // class for IBindingListView Implementation
3 //
4 // Authors:
5 //      Senganal T <tsenganal@novell.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27 //
28
29
30 using System;
31 using System.IO;
32 using System.Data;
33 using System.ComponentModel;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Data
37 {       
38         [TestFixture]
39         public class DataViewTest_IBindingListView
40         {
41                 DataTable table = null;
42                 
43                 [TestFixtureSetUp]
44                 public void TestFixtureSetUp ()
45                 {
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));
50                         
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 });
61                 }
62                 
63                 [Test]
64                 public void FilterTest()
65                 {
66                         IBindingListView view = (IBindingListView) new DataView (table);
67                         
68                         view.Filter = "";
69                         Assert.AreEqual (table.Rows.Count, view.Count, "#1");
70                         
71                         view.Filter = null;
72                         Assert.AreEqual (table.Rows.Count, view.Count, "#2");
73                         
74                         view.Filter = "col1 <> 1";
75                         Assert.AreEqual (view.Filter, ((DataView)view).RowFilter, "#4");
76                         Assert.AreEqual (6, view.Count, "#5");
77                         
78                         //RemoveFilter Test
79                         view.RemoveFilter ();
80                         Assert.AreEqual ("", view.Filter, "#6");
81                         Assert.AreEqual ("", ((DataView)view).RowFilter, "#7");
82                         Assert.AreEqual (table.Rows.Count, view.Count, "#8");
83                 }
84                 
85                 [Test]
86                 public void SortDescriptionTest()
87                 {
88                         IBindingListView view = (IBindingListView)new DataView (table);
89                         
90                         ListSortDescriptionCollection col = view.SortDescriptions;
91                         
92                         ((DataView)view).Sort = "";
93                         col = view.SortDescriptions;
94                         Assert.AreEqual (0, col.Count, "#1");
95                         
96                         ((DataView)view).Sort = null;
97                         col = view.SortDescriptions;
98                         Assert.AreEqual (0, col.Count, "#2");
99                         
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");
107                         
108                         //ApplySort Test
109                         IBindingListView view1 = (IBindingListView)new DataView (table);
110                         
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);      
116                 }
117                 
118                 [Test]
119                 public void ReadOnlyPropTest()
120                 {
121                         IBindingListView view = (IBindingListView)new DataView (table);
122                         Assert.IsTrue (view.SupportsAdvancedSorting, "#1");
123                         Assert.IsTrue (view.SupportsFiltering, "#2");
124                 }
125         }
126 }