2 // Tests for System.Web.UI.WebControls.DataControlFieldCollectionTest.cs
5 // Yoni Klein (yonik@mainsoft.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections.Generic;
36 using System.Web.UI.WebControls;
38 using System.Collections;
39 using System.Collections.Specialized;
40 using NUnit.Framework;
45 namespace MonoTests.System.Web.UI.WebControls
48 public class DataControlFieldCollectionTest
50 private bool _fieldsChanged;
53 get { return _fieldsChanged; }
54 set { _fieldsChanged = value; }
57 private void ResetEvent()
59 _fieldsChanged = false;
63 public void DataControlFieldCollection_DefaultProperty ()
65 DataControlFieldCollection collection = new DataControlFieldCollection ();
66 Assert.AreEqual (0, collection.Count, "Count");
70 public void DataControlFieldCollection_Add ()
72 DataControlFieldCollection collection = new DataControlFieldCollection ();
73 collection.Add (new BoundField());
74 Assert.AreEqual (1, collection.Count, "Add");
78 public void DataControlFieldCollection_Clear ()
80 DataControlFieldCollection collection = new DataControlFieldCollection ();
81 collection.Add (new BoundField ());
82 Assert.AreEqual (1, collection.Count, "Add");
84 Assert.AreEqual (0, collection.Count, "Clear");
88 public void DataControlFieldCollection_Clone ()
90 DataControlFieldCollection collection = new DataControlFieldCollection ();
91 collection.Add (new BoundField ());
92 Assert.AreEqual (1, collection.Count, "Add");
93 DataControlFieldCollection clone = collection.CloneFields ();
94 Assert.AreEqual (1, clone.Count, "Clone");
98 public void DataControlFieldCollection_Contains ()
100 DataControlFieldCollection collection = new DataControlFieldCollection ();
101 BoundField field = new BoundField ();
102 collection.Add (field);
103 bool result = collection.Contains (field);
104 Assert.AreEqual (true, result, "Contains");
108 public void DataControlFieldCollection_CopyTo ()
110 DataControlFieldCollection collection = new DataControlFieldCollection ();
111 collection.Add (new BoundField ());
112 DataControlField[] fields = new DataControlField[collection.Count];
113 Array array = new DataControlField[collection.Count];
114 collection.CopyTo (fields, 0);
115 Assert.AreEqual (1, fields.Length, "CopyToDataControlField");
116 collection.CopyTo (array, 0);
117 Assert.AreEqual (1, array.Length, "CopyToArray");
121 public void DataControlFieldCollection_GetEnumerator ()
123 DataControlFieldCollection collection = new DataControlFieldCollection ();
124 collection.Add (new BoundField ());
125 IEnumerator numerator = collection.GetEnumerator ();
126 Assert.IsNotNull (numerator, "GetEnumerator");
127 if (!(numerator is IEnumerator))
128 Assert.Fail ("IEnumerator not been created");
132 public void DataControlFieldCollection_IndexOf ()
134 DataControlFieldCollection collection = new DataControlFieldCollection ();
135 BoundField field = new BoundField ();
137 result = collection.IndexOf (field);
138 Assert.AreEqual (-1, result, "NotExistFieldIndex");
139 collection.Add (field);
140 result = collection.IndexOf (field);
141 Assert.AreEqual (0, result, "ExistFieldIndex");
145 public void DataControlFieldCollection_Insert ()
147 DataControlFieldCollection collection = new DataControlFieldCollection ();
148 BoundField field = new BoundField ();
149 collection.Add (new BoundField ());
150 collection.Add (new BoundField ());
151 Assert.AreEqual (2, collection.Count, "CollectionCount");
152 collection.Insert (0, field);
153 int result = collection.IndexOf (field);
154 Assert.AreEqual (0, result, "Insert");
158 public void DataControlFieldCollection_Remove ()
160 DataControlFieldCollection collection = new DataControlFieldCollection ();
161 BoundField field = new BoundField ();
162 collection.Add (field);
163 Assert.AreEqual (1, collection.Count, "CollectionCount");
164 collection.Remove(null);
165 Assert.AreEqual (1, collection.Count, "RemoveNotExistField");
166 collection.Remove (field);
167 Assert.AreEqual (0, collection.Count, "RemoveExistField");
171 public void DataControlFieldCollection_RemoveAt ()
173 DataControlFieldCollection collection = new DataControlFieldCollection ();
174 collection.Add (new BoundField ());
175 Assert.AreEqual (1, collection.Count, "CollectionCount");
176 collection.RemoveAt (0);
177 Assert.AreEqual (0, collection.Count, "RemoveAtIndex");
181 public void DataControlFieldCollection_FieldsChangedEvent ()
183 DataControlFieldCollection collection = new DataControlFieldCollection ();
184 collection.FieldsChanged += new EventHandler (collection_FieldsChanged);
185 BoundField field = new BoundField ();
186 collection.Add (field);
187 Assert.AreEqual (true, EventDone, "FieldsChangedEvenAdd");
190 Assert.AreEqual (true, EventDone, "FieldsChangedEvenClear");
192 collection.Insert (0, field);
193 Assert.AreEqual (true, EventDone, "FieldsChangedEvenInsert");
195 collection.Remove (field);
196 Assert.AreEqual (true, EventDone, "FieldsChangedEvenRemove");
199 private void collection_FieldsChanged (Object sender, EventArgs e)
205 [ExpectedException (typeof (ArgumentOutOfRangeException))]
206 public void DataControlFieldCollection_RemoveAtException ()
208 DataControlFieldCollection collection = new DataControlFieldCollection ();
209 collection.RemoveAt (0);