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>
29 using System.Collections;
30 using System.ComponentModel;
32 using System.Windows.Forms;
34 using NUnit.Framework;
36 namespace MonoTests.System.Windows.Forms
39 class GridTableStylesCollectionTests : Assertion
41 private bool eventhandled;
42 private object Element;
43 private CollectionChangeAction Action;
46 public void Clean() {}
49 public void GetReady ()
54 public void TestDefaultValues ()
56 DataGrid grid = new DataGrid ();
57 GridTableStylesCollection sc = grid.TableStyles;
59 AssertEquals ("IsSynchronized property", false, sc.IsSynchronized);
60 AssertEquals ("SyncRoot property", false, sc.IsSynchronized);
61 AssertEquals ("IsReadOnly property", false, sc.IsSynchronized);
65 public void TestAdd ()
67 DataGrid grid = new DataGrid ();
68 GridTableStylesCollection sc = grid.TableStyles;
69 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
73 DataGridTableStyle ts = new DataGridTableStyle ();
74 ts.MappingName = "Table1";
76 AssertEquals (true, eventhandled);
77 AssertEquals (ts, Element);
78 AssertEquals (CollectionChangeAction.Add, Action);
82 sc.AddRange (new DataGridTableStyle [] {new DataGridTableStyle (), new DataGridTableStyle ()});
83 AssertEquals (true, eventhandled);
84 AssertEquals (null, Element);
85 AssertEquals (CollectionChangeAction.Refresh, Action);
89 public void TestRemove ()
91 DataGrid grid = new DataGrid ();
92 GridTableStylesCollection sc = grid.TableStyles;
93 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
96 DataGridTableStyle ts1 = new DataGridTableStyle ();
97 ts1.MappingName = "Table1";
100 DataGridTableStyle ts2 = new DataGridTableStyle ();
101 ts2.MappingName = "Table2";
104 DataGridTableStyle ts3 = new DataGridTableStyle ();
105 ts3.MappingName = "Table3";
110 AssertEquals (true, eventhandled);
111 AssertEquals (ts2, Element);
112 AssertEquals (CollectionChangeAction.Remove, Action);
113 AssertEquals (2, sc.Count);
117 AssertEquals (true, eventhandled);
118 AssertEquals (ts1, Element);
119 AssertEquals (CollectionChangeAction.Remove, Action);
120 AssertEquals (1, sc.Count);
124 AssertEquals (null, Element);
125 AssertEquals (CollectionChangeAction.Refresh, Action);
130 public void TestIndexContains ()
132 DataGrid grid = new DataGrid ();
133 GridTableStylesCollection sc = grid.TableStyles;
134 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
137 DataGridTableStyle ts1 = new DataGridTableStyle ();
138 ts1.MappingName = "Table1";
141 DataGridTableStyle ts2 = new DataGridTableStyle ();
142 ts2.MappingName = "Table2";
145 DataGridTableStyle ts3 = new DataGridTableStyle ();
146 ts3.MappingName = "Table3";
150 IList ilist = (IList) sc;
151 AssertEquals (1, ilist.IndexOf (ts2));
152 AssertEquals (false, sc.Contains ("nothing"));
153 AssertEquals (true, sc.Contains (ts3));
156 private void ResetEventData ()
158 eventhandled = false;
160 Action = (CollectionChangeAction) 0;
163 private void OnEventHandler (object sender, EventArgs e)
\r
165 eventhandled = true;
\r
168 private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)
\r
172 Action = e.Action;
\r