[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / DataControlFieldCollectionTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.DataControlFieldCollectionTest.cs
3 //
4 // Author:
5 //      Yoni Klein (yonik@mainsoft.com)
6 //
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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.
28
29
30
31 using System;
32 using System.Collections.Generic;
33 using System.Text;
34 using System.Web;
35 using System.Web.UI;
36 using System.Web.UI.WebControls;
37 using System.IO;
38 using System.Collections;
39 using System.Collections.Specialized;
40 using NUnit.Framework;
41 using System.Data;
42
43
44
45 namespace MonoTests.System.Web.UI.WebControls
46 {
47         [TestFixture]
48         public class DataControlFieldCollectionTest
49         {
50                 private bool _fieldsChanged;
51                 public bool EventDone
52                 {
53                         get { return _fieldsChanged; }
54                         set { _fieldsChanged = value; }
55                 }
56
57                 private void ResetEvent()
58                 {
59                          _fieldsChanged = false;
60                 }
61
62                 [Test]
63                 public void DataControlFieldCollection_DefaultProperty ()
64                 {
65                         DataControlFieldCollection collection = new DataControlFieldCollection ();
66                         Assert.AreEqual (0, collection.Count, "Count");
67                 }
68
69                 [Test]
70                 public void DataControlFieldCollection_Add ()
71                 {
72                         DataControlFieldCollection collection = new DataControlFieldCollection ();
73                         collection.Add (new BoundField());
74                         Assert.AreEqual (1, collection.Count, "Add");
75                 }
76
77                 [Test]
78                 public void DataControlFieldCollection_Clear ()
79                 {
80                         DataControlFieldCollection collection = new DataControlFieldCollection ();
81                         collection.Add (new BoundField ());
82                         Assert.AreEqual (1, collection.Count, "Add");
83                         collection.Clear ();
84                         Assert.AreEqual (0, collection.Count, "Clear");
85                 }
86
87                 [Test]
88                 public void DataControlFieldCollection_Clone ()
89                 {
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");
95                 }
96
97                 [Test]
98                 public void DataControlFieldCollection_Contains ()
99                 {
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");
105                 }
106
107                 [Test]
108                 public void DataControlFieldCollection_CopyTo ()
109                 {
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");
118                 }
119
120                 [Test]
121                 public void DataControlFieldCollection_GetEnumerator ()
122                 {
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");
129                 }
130
131                 [Test]
132                 public void DataControlFieldCollection_IndexOf ()
133                 {
134                         DataControlFieldCollection collection = new DataControlFieldCollection ();
135                         BoundField field = new BoundField ();
136                         int result;
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");
142                 }
143
144                 [Test]
145                 public void DataControlFieldCollection_Insert ()
146                 {
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");
155                 }
156
157                 [Test]
158                 public void DataControlFieldCollection_Remove ()
159                 {
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");
168                 }
169
170                 [Test]
171                 public void DataControlFieldCollection_RemoveAt ()
172                 {
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");
178                 }
179
180                 [Test]
181                 public void DataControlFieldCollection_FieldsChangedEvent ()
182                 {
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");
188                         ResetEvent ();
189                         collection.Clear ();
190                         Assert.AreEqual (true, EventDone, "FieldsChangedEvenClear");
191                         ResetEvent ();
192                         collection.Insert (0, field);
193                         Assert.AreEqual (true, EventDone, "FieldsChangedEvenInsert");
194                         ResetEvent ();
195                         collection.Remove (field);
196                         Assert.AreEqual (true, EventDone, "FieldsChangedEvenRemove");
197                 }
198
199                 private void collection_FieldsChanged (Object sender, EventArgs e)
200                 {
201                         EventDone = true;
202                 }
203
204                 [Test]
205                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
206                 public void DataControlFieldCollection_RemoveAtException ()
207                 {
208                         DataControlFieldCollection collection = new DataControlFieldCollection ();
209                         collection.RemoveAt (0);
210                 }
211         }
212 }