2007-01-10 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / GridColumnStylesCollectionTest.cs
blobfe4ef0189a409afc62ff0e4a4cdeb655ce8347cb
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.
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)
22 // Author:
23 // Jordi Mas i Hernandez <jordi@ximian.com>
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;
35 namespace MonoTests.System.Windows.Forms
37 [TestFixture]
38 class GridColumnStylesCollectionTest
40 private bool eventhandled;
41 private object Element;
42 private CollectionChangeAction Action;
43 private int times;
46 [Test]
47 public void TestDefaultValues ()
49 DataGridTableStyle ts = new DataGridTableStyle ();
50 GridColumnStylesCollection sc = ts.GridColumnStyles;
52 Assert.AreEqual (false, sc.IsSynchronized, "IsSynchronized property");
53 Assert.AreEqual (0, sc.Count, "Count");
54 Assert.AreEqual (sc, sc.SyncRoot, "SyncRoot property");
55 Assert.AreEqual (false, ((IList)sc).IsFixedSize, "IsFixedSize property");
56 Assert.AreEqual (false, sc.IsReadOnly, "IsReadOnly property");
59 [Test]
60 public void TestAdd ()
62 DataGridTableStyle ts = new DataGridTableStyle ();
63 GridColumnStylesCollection sc = ts.GridColumnStyles;
64 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
66 // Add single
67 ResetEventData ();
68 DataGridTextBoxColumn col1 = new DataGridTextBoxColumn ();
69 col1.MappingName = "Column1";
70 sc.Add (col1);
71 Assert.AreEqual (true, eventhandled);
72 Assert.AreEqual (col1, Element);
73 Assert.AreEqual (CollectionChangeAction.Add, Action);
75 // Add multiple
76 ResetEventData ();
77 DataGridTextBoxColumn elem1 = new DataGridTextBoxColumn ();
78 DataGridTextBoxColumn elem2 = new DataGridTextBoxColumn ();
79 sc.AddRange (new DataGridTextBoxColumn [] {elem1, elem2});
80 Assert.AreEqual (true, eventhandled, "A1");
81 Assert.AreEqual (CollectionChangeAction.Add, Action, "A2");
82 Assert.AreEqual (elem2, Element, "A3");
86 [Test]
87 public void TestAddRange ()
89 DataGridTableStyle ts = new DataGridTableStyle ();
90 GridColumnStylesCollection sc = ts.GridColumnStyles;
91 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
93 ResetEventData ();
94 DataGridTextBoxColumn col1 = new DataGridTextBoxColumn ();
95 col1.MappingName = "Column1";
97 DataGridTextBoxColumn col2 = new DataGridTextBoxColumn ();
98 col2.MappingName = "Column2";
99 sc.AddRange (new DataGridColumnStyle[] {col1, col2});
101 Assert.AreEqual (true, eventhandled, "A1");
102 Assert.AreEqual (col2, Element, "A2");
103 Assert.AreEqual (CollectionChangeAction.Add, Action, "A3");
104 Assert.AreEqual (2, times, "A4");
107 [Test]
108 public void TestRemove ()
110 DataGridTableStyle ts = new DataGridTableStyle ();
111 GridColumnStylesCollection sc = ts.GridColumnStyles;
112 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
114 // Add single
115 DataGridTextBoxColumn col1 = new DataGridTextBoxColumn ();
116 col1.MappingName = "Column1";
117 sc.Add (col1);
119 DataGridTextBoxColumn col2 = new DataGridTextBoxColumn ();
120 col2.MappingName = "Column2";
121 sc.Add (col2);
123 DataGridTextBoxColumn col3 = new DataGridTextBoxColumn ();
124 col3.MappingName = "Column3";
125 sc.Add (col3);
127 ResetEventData ();
128 sc.Remove (col2);
129 Assert.AreEqual (true, eventhandled, "A1");
130 Assert.AreEqual (col2, Element, "A2");
131 Assert.AreEqual (CollectionChangeAction.Remove, Action, "A3");
132 Assert.AreEqual (2, sc.Count, "A4");
134 ResetEventData ();
135 sc.RemoveAt (0);
136 Assert.AreEqual (true, eventhandled, "A5");
137 Assert.AreEqual (col1, Element, "A6");
138 Assert.AreEqual (CollectionChangeAction.Remove, Action, "A6");
139 Assert.AreEqual (1, sc.Count, "A7");
141 ResetEventData ();
142 sc.Clear ();
143 Assert.AreEqual (null, Element, "A8");
144 Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A9");
148 [Test]
149 public void TestIndexContains ()
151 DataGridTableStyle ts = new DataGridTableStyle ();
152 GridColumnStylesCollection sc = ts.GridColumnStyles;
153 sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
155 // Add single
156 DataGridTextBoxColumn col1 = new DataGridTextBoxColumn ();
157 col1.MappingName = "Column1";
158 sc.Add (col1);
160 DataGridTextBoxColumn col2 = new DataGridTextBoxColumn ();
161 col2.MappingName = "Column2";
162 sc.Add (col2);
164 DataGridTextBoxColumn col3 = new DataGridTextBoxColumn ();
165 col3.MappingName = "Column3";
166 sc.Add (col3);
168 ResetEventData ();
169 IList ilist = (IList) sc;
170 Assert.AreEqual (1, ilist.IndexOf (col2), "A1");
171 Assert.AreEqual (false, sc.Contains ("nothing"), "A2");
172 Assert.AreEqual (true, sc.Contains (col3), "A3");
175 private void ResetEventData ()
177 times = 0;
178 eventhandled = false;
179 Element = null;
180 Action = (CollectionChangeAction) 0;
183 private void OnEventHandler (object sender, EventArgs e)
185 eventhandled = true;
188 private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)
190 eventhandled = true;
191 Element = e.Element;
192 Action = e.Action;
193 times++;