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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Jordi Mas i Hernandez <jordi@ximian.com>
28 using System.Collections;
29 using System.ComponentModel;
31 using System.Windows.Forms;
33 using NUnit.Framework;
35 namespace MonoTests.System.Windows.Forms
38 public class GridTableStylesCollectionTest
40 private bool eventhandled;
41 private object Element;
42 private CollectionChangeAction Action;
46 public void TestDefaultValues ()
48 DataGrid grid = new DataGrid ();
49 GridTableStylesCollection sc = grid.TableStyles;
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");
59 public void TestMappingNameChanged ()
61 DataGrid grid = new DataGrid ();
62 GridTableStylesCollection sc = grid.TableStyles;
63 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
66 DataGridTableStyle ts = new DataGridTableStyle ();
67 ts.MappingName = "Table1";
70 ts.MappingName = "Table2";
72 Assert.AreEqual (true, eventhandled, "A1");
73 Assert.AreEqual (null, Element, "A2");
74 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
78 public void TestAdd ()
80 DataGrid grid = new DataGrid ();
81 GridTableStylesCollection sc = grid.TableStyles;
82 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
86 DataGridTableStyle ts = new DataGridTableStyle ();
87 ts.MappingName = "Table1";
89 Assert.AreEqual (true, eventhandled, "A1");
90 Assert.AreEqual (ts, Element, "A2");
91 Assert.AreEqual (CollectionChangeAction.Add, Action, "A3");
95 sc.AddRange (new DataGridTableStyle [] {new DataGridTableStyle (), new DataGridTableStyle ()});
96 Assert.AreEqual (true, eventhandled, "A4");
97 Assert.AreEqual (null, Element, "A5");
98 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A6");
102 public void TestAddRange ()
104 DataGrid grid = new DataGrid ();
105 GridTableStylesCollection sc = grid.TableStyles;
106 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
109 DataGridTableStyle ts1 = new DataGridTableStyle ();
110 ts1.MappingName = "Table1";
112 DataGridTableStyle ts2 = new DataGridTableStyle ();
113 ts2.MappingName = "Table2";
114 sc.AddRange (new DataGridTableStyle[] {ts1, ts2});
116 Assert.AreEqual (true, eventhandled, "A1");
117 Assert.AreEqual (null, Element, "A2");
118 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
119 Assert.AreEqual (1, times, "A4");
123 public void TestRemove ()
125 DataGrid grid = new DataGrid ();
126 GridTableStylesCollection sc = grid.TableStyles;
127 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
130 DataGridTableStyle ts1 = new DataGridTableStyle ();
131 ts1.MappingName = "Table1";
134 DataGridTableStyle ts2 = new DataGridTableStyle ();
135 ts2.MappingName = "Table2";
138 DataGridTableStyle ts3 = new DataGridTableStyle ();
139 ts3.MappingName = "Table3";
144 Assert.AreEqual (true, eventhandled, "A1");
145 Assert.AreEqual (ts2, Element, "A2");
146 Assert.AreEqual (CollectionChangeAction.Remove, Action, "A3");
147 Assert.AreEqual (2, sc.Count, "A4");
151 Assert.AreEqual (true, eventhandled, "A5");
152 Assert.AreEqual (ts1, Element, "A6");
153 Assert.AreEqual (CollectionChangeAction.Remove, Action, "A7");
154 Assert.AreEqual (1, sc.Count, "A8");
158 Assert.AreEqual (null, Element, "A9");
159 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A10");
164 public void TestIndexContains ()
166 DataGrid grid = new DataGrid ();
167 GridTableStylesCollection sc = grid.TableStyles;
168 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
171 DataGridTableStyle ts1 = new DataGridTableStyle ();
172 ts1.MappingName = "Table1";
175 DataGridTableStyle ts2 = new DataGridTableStyle ();
176 ts2.MappingName = "Table2";
179 DataGridTableStyle ts3 = new DataGridTableStyle ();
180 ts3.MappingName = "Table3";
184 IList ilist = (IList) sc;
185 Assert.AreEqual (1, ilist.IndexOf (ts2), "A1");
186 Assert.AreEqual (false, sc.Contains ("nothing"), "A2");
187 Assert.AreEqual (true, sc.Contains (ts3), "A3");
190 private void ResetEventData ()
193 eventhandled = false;
195 Action = (CollectionChangeAction) 0;
198 private void OnEventHandler (object sender, EventArgs e)
203 private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)