Grasshopper now uses csproj instead of vmwcsproj
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / GridTableStylesCollectionTest.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Jordi Mas i Hernandez <jordi@ximian.com>
24 //
25 //
26
27 using System;
28 using System.Collections;
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Windows.Forms;
32 using System.Xml;
33 using NUnit.Framework;
34
35 namespace MonoTests.System.Windows.Forms
36 {
37         [TestFixture]
38         public class GridTableStylesCollectionTest
39         {
40                 private bool eventhandled;
41                 private object Element;
42                 private CollectionChangeAction Action;
43                 private int times;
44
45                 [Test]
46                 public void TestDefaultValues ()
47                 {
48                         DataGrid grid = new DataGrid ();
49                         GridTableStylesCollection sc = grid.TableStyles;
50
51                         Assert.AreEqual (false, sc.IsSynchronized, "IsSynchronized property");
52                         Assert.AreEqual (0, sc.Count, "Count");
53                         Assert.AreEqual (sc, sc.SyncRoot, "SyncRoot property");
54                         Assert.AreEqual (false, ((IList)sc).IsFixedSize, "IsFixedSize property");
55                         Assert.AreEqual (false, sc.IsReadOnly, "IsReadOnly property");
56                 }
57
58                 [Test]
59                 public void TestMappingNameChanged ()
60                 {
61                         DataGrid grid = new DataGrid ();
62                         GridTableStylesCollection sc = grid.TableStyles;
63                         sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
64
65                         // Add single
66                         DataGridTableStyle ts = new DataGridTableStyle ();
67                         ts.MappingName = "Table1";
68                         sc.Add (ts);
69                         ResetEventData ();
70                         ts.MappingName = "Table2";
71
72                         Assert.AreEqual (true, eventhandled, "A1");
73                         Assert.AreEqual (null, Element, "A2");
74                         Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
75                 }
76
77                 // Fails due to:
78                 // "The TableStyles collection already has a TableStyle with this mapping name"
79                 // There is a TODO in DataGrid about allowing TableStyles to have the same mapping name.
80                 [Test]
81                 [NUnit.Framework.Category ("NotWorking")]
82                 public void TestAdd ()
83                 {                       
84                         DataGrid grid = new DataGrid ();
85                         GridTableStylesCollection sc = grid.TableStyles;
86                         sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
87
88                         // Add single
89                         ResetEventData ();
90                         DataGridTableStyle ts = new DataGridTableStyle ();
91                         ts.MappingName = "Table1";
92                         sc.Add (ts);
93                         Assert.AreEqual (true, eventhandled, "A1");
94                         Assert.AreEqual (ts, Element, "A2");
95                         Assert.AreEqual (CollectionChangeAction.Add, Action, "A3");
96
97                         // Add multiple
98                         ResetEventData ();
99                         sc.AddRange (new DataGridTableStyle [] {new DataGridTableStyle (), new DataGridTableStyle ()});
100                         Assert.AreEqual (true, eventhandled, "A4");
101                         Assert.AreEqual (null, Element, "A5");
102                         Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A6");
103                 }
104
105                 [Test]
106                 public void TestAddRange ()
107                 {
108                         DataGrid grid = new DataGrid ();
109                         GridTableStylesCollection sc = grid.TableStyles;                
110                         sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
111
112                         ResetEventData ();
113                         DataGridTableStyle ts1 = new DataGridTableStyle ();
114                         ts1.MappingName = "Table1";
115
116                         DataGridTableStyle ts2 = new DataGridTableStyle ();
117                         ts2.MappingName = "Table2";
118                         sc.AddRange (new DataGridTableStyle[] {ts1, ts2});
119
120                         Assert.AreEqual (true, eventhandled, "A1");
121                         Assert.AreEqual (null, Element, "A2");
122                         Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
123                         Assert.AreEqual (1, times, "A4");
124                 }
125
126                 [Test]
127                 public void TestRemove ()
128                 {
129                         DataGrid grid = new DataGrid ();
130                         GridTableStylesCollection sc = grid.TableStyles;
131                         sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
132
133                         // Add single
134                         DataGridTableStyle ts1 = new DataGridTableStyle ();
135                         ts1.MappingName = "Table1";
136                         sc.Add (ts1);
137
138                         DataGridTableStyle ts2 = new DataGridTableStyle ();
139                         ts2.MappingName = "Table2";
140                         sc.Add (ts2);
141
142                         DataGridTableStyle ts3 = new DataGridTableStyle ();
143                         ts3.MappingName = "Table3";
144                         sc.Add (ts3);
145
146                         ResetEventData ();
147                         sc.Remove (ts2);
148                         Assert.AreEqual (true, eventhandled, "A1");
149                         Assert.AreEqual (ts2, Element, "A2");
150                         Assert.AreEqual (CollectionChangeAction.Remove, Action, "A3");
151                         Assert.AreEqual (2, sc.Count, "A4");
152
153                         ResetEventData ();
154                         sc.RemoveAt (0);
155                         Assert.AreEqual (true, eventhandled, "A5");
156                         Assert.AreEqual (ts1, Element, "A6");
157                         Assert.AreEqual (CollectionChangeAction.Remove, Action, "A7");
158                         Assert.AreEqual (1, sc.Count, "A8");
159
160                         ResetEventData ();
161                         sc.Clear ();
162                         Assert.AreEqual (null, Element, "A9");
163                         Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A10");
164
165                 }
166
167                 [Test]
168                 public void TestIndexContains ()
169                 {
170                         DataGrid grid = new DataGrid ();
171                         GridTableStylesCollection sc = grid.TableStyles;
172                         sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
173
174                         // Add single
175                         DataGridTableStyle ts1 = new DataGridTableStyle ();
176                         ts1.MappingName = "Table1";
177                         sc.Add (ts1);
178
179                         DataGridTableStyle ts2 = new DataGridTableStyle ();
180                         ts2.MappingName = "Table2";
181                         sc.Add (ts2);
182
183                         DataGridTableStyle ts3 = new DataGridTableStyle ();
184                         ts3.MappingName = "Table3";
185                         sc.Add (ts3);
186
187                         ResetEventData ();
188                         IList ilist = (IList) sc;
189                         Assert.AreEqual (1, ilist.IndexOf (ts2), "A1");
190                         Assert.AreEqual (false, sc.Contains ("nothing"), "A2");
191                         Assert.AreEqual (true, sc.Contains (ts3), "A3");
192                 }
193
194                 private void ResetEventData ()
195                 {
196                         times = 0;
197                         eventhandled = false;
198                         Element = null;
199                         Action = (CollectionChangeAction) 0;
200                 }
201
202                 //private void OnEventHandler (object sender, EventArgs e)
203                 //{
204                 //        eventhandled = true;
205                 //}
206
207                 private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)
208                 {
209                         times++;
210                         eventhandled = true;
211                         Element = e.Element;
212                         Action = e.Action;
213                 }
214
215         }
216 }