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 class GridColumnStylesCollectionTest
40 private bool eventhandled
;
41 private object Element
;
42 private CollectionChangeAction Action
;
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");
60 public void TestAdd ()
62 DataGridTableStyle ts
= new DataGridTableStyle ();
63 GridColumnStylesCollection sc
= ts
.GridColumnStyles
;
64 sc
.CollectionChanged
+= new CollectionChangeEventHandler (OnCollectionEventHandler
);
68 DataGridTextBoxColumn col1
= new DataGridTextBoxColumn ();
69 col1
.MappingName
= "Column1";
71 Assert
.AreEqual (true, eventhandled
);
72 Assert
.AreEqual (col1
, Element
);
73 Assert
.AreEqual (CollectionChangeAction
.Add
, Action
);
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");
87 public void TestAddRange ()
89 DataGridTableStyle ts
= new DataGridTableStyle ();
90 GridColumnStylesCollection sc
= ts
.GridColumnStyles
;
91 sc
.CollectionChanged
+= new CollectionChangeEventHandler (OnCollectionEventHandler
);
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");
108 public void TestRemove ()
110 DataGridTableStyle ts
= new DataGridTableStyle ();
111 GridColumnStylesCollection sc
= ts
.GridColumnStyles
;
112 sc
.CollectionChanged
+= new CollectionChangeEventHandler (OnCollectionEventHandler
);
115 DataGridTextBoxColumn col1
= new DataGridTextBoxColumn ();
116 col1
.MappingName
= "Column1";
119 DataGridTextBoxColumn col2
= new DataGridTextBoxColumn ();
120 col2
.MappingName
= "Column2";
123 DataGridTextBoxColumn col3
= new DataGridTextBoxColumn ();
124 col3
.MappingName
= "Column3";
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");
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");
143 Assert
.AreEqual (null, Element
, "A8");
144 Assert
.AreEqual (CollectionChangeAction
.Refresh
, Action
, "A9");
149 public void TestIndexContains ()
151 DataGridTableStyle ts
= new DataGridTableStyle ();
152 GridColumnStylesCollection sc
= ts
.GridColumnStyles
;
153 sc
.CollectionChanged
+= new CollectionChangeEventHandler (OnCollectionEventHandler
);
156 DataGridTextBoxColumn col1
= new DataGridTextBoxColumn ();
157 col1
.MappingName
= "Column1";
160 DataGridTextBoxColumn col2
= new DataGridTextBoxColumn ();
161 col2
.MappingName
= "Column2";
164 DataGridTextBoxColumn col3
= new DataGridTextBoxColumn ();
165 col3
.MappingName
= "Column3";
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 ()
178 eventhandled
= false;
180 Action
= (CollectionChangeAction
) 0;
183 private void OnEventHandler (object sender
, EventArgs e
)
188 private void OnCollectionEventHandler (object sender
, CollectionChangeEventArgs e
)