* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / WizardStepCollectionTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.WizardStepCollectionTest.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 #if NET_2_0
31
32 using System;
33 using System.Web;
34 using System.Web.UI;
35 using System.Web.UI.WebControls;
36 using NUnit.Framework;
37 using System.Collections;
38
39 namespace MonoTests.System.Web.UI.WebControls
40 {
41         [TestFixture]
42         public class WizardStepCollectionTest
43         {
44                 
45                 [Test]
46                 public void WizardStepCollection_DefaultProperty ()
47                 {
48                         Wizard w = new Wizard();
49                         Assert.AreEqual (typeof (WizardStepCollection), w.WizardSteps.GetType (), "WizardStepCollection");
50                         Assert.AreEqual (0,w.WizardSteps.Count, "Count");
51                         Assert.AreEqual (false, w.WizardSteps.IsReadOnly, "IsReadOnly");
52                         Assert.AreEqual (false, w.WizardSteps.IsSynchronized, "IsSynchronized");
53                         Assert.AreEqual (w.WizardSteps, w.WizardSteps.SyncRoot, "SyncRoot");
54                 }
55
56                 [Test]
57                 public void WizardStepCollection_Add ()
58                 {
59                         Wizard w = new Wizard ();
60                         WizardStep step1 = new WizardStep ();
61                         try {
62                                 w.WizardSteps.Add (step1);
63                         }
64                         catch (Exception e) {
65                                 Assert.Fail (e.Message);
66                         }
67                         Assert.AreEqual (1, w.WizardSteps.Count, "Add step fail");
68                 }
69
70                 [Test]
71                 public void WizardStepCollection_AddAt ()
72                 {
73                         Wizard w = new Wizard ();
74                         WizardStep step1 = new WizardStep ();
75                         WizardStep step2 = new WizardStep ();
76
77                         try {
78                                 w.WizardSteps.Add (step1);
79                                 w.WizardSteps.AddAt (0, step2);
80                         }
81                         catch (Exception e) {
82                                 Assert.Fail (e.Message);
83                         }
84                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count fail");
85                         Assert.AreEqual (step2, w.WizardSteps[0], "Step index fail");
86                 }
87
88                 public void WizardStepCollection_Clear ()
89                 {
90                         Wizard w = new Wizard ();
91                         WizardStep step1 = new WizardStep ();
92                         WizardStep step2 = new WizardStep ();
93
94                         try {
95                                 w.WizardSteps.Add (step1);
96                                 w.WizardSteps.Add (step2);
97                         }
98                         catch (Exception e) {
99                                 Assert.Fail (e.Message);
100                         }
101                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count fail");
102                         w.WizardSteps.Clear ();
103                         Assert.AreEqual (0, w.WizardSteps.Count, "Step clear fail");
104                 }
105
106                 [Test]
107                 public void WizardStepCollection_Contains ()
108                 {
109                         Wizard w = new Wizard ();
110                         WizardStep step1 = new WizardStep ();
111                         WizardStep step2 = new WizardStep ();
112
113                         try {
114                                 w.WizardSteps.Add (step1);
115                         }
116                         catch (Exception e) {
117                                 Assert.Fail (e.Message);
118                         }
119                         Assert.AreEqual (1, w.WizardSteps.Count, "Step count fail");
120                         Assert.AreEqual (true, w.WizardSteps.Contains (step1), "Step contains fail#1");
121                         Assert.AreEqual (false, w.WizardSteps.Contains (step2), "Step contains fail#2");
122                 }
123
124                 [Test]
125                 public void WizardStepCollection_CopyTo ()
126                 {
127                         Wizard w = new Wizard ();
128                         WizardStep step1 = new WizardStep ();
129                         WizardStep step2 = new WizardStep ();
130                         
131
132                         try {
133                                 w.WizardSteps.Add (step1);
134                                 w.WizardSteps.Add (step2);
135                         }
136                         catch (Exception e) {
137                                 Assert.Fail (e.Message);
138                         }
139                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count fail");
140                         WizardStep[] steps = new WizardStep [w.WizardSteps.Count] ;
141                         w.WizardSteps.CopyTo (steps, 0);
142                         Assert.AreEqual (2, steps.GetLength (0), "Copyto elements count");
143                         Assert.AreEqual (step1, steps[0], "Copyto elements equal#1");
144                         Assert.AreEqual (step2, steps[1], "Copyto elements equal#2");
145                 }
146
147                 [Test]
148                 public void WizardStepCollection_GetEnumerator ()
149                 {
150                         Wizard w = new Wizard ();
151                         WizardStep step1 = new WizardStep ();
152                         WizardStep step2 = new WizardStep ();
153
154
155                         try {
156                                 w.WizardSteps.Add (step1);
157                                 w.WizardSteps.Add (step2);
158                         }
159                         catch (Exception e) {
160                                 Assert.Fail (e.Message);
161                         }
162                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count fail");
163                         IEnumerator numerator = w.WizardSteps.GetEnumerator ();
164                         numerator.Reset();
165                         numerator.MoveNext ();
166                         Assert.AreEqual (step1, numerator.Current, "Enumerator item value#1");
167                         numerator.MoveNext ();
168                         Assert.AreEqual (step2, numerator.Current, "Enumerator item value#2");
169                 }
170
171                 [Test]
172                 public void WizardStepCollection_Insert ()
173                 {
174                         Wizard w = new Wizard ();
175                         WizardStep step1 = new WizardStep ();
176                         WizardStep step2 = new WizardStep ();
177
178                         try {
179                                 w.WizardSteps.Add (step1);
180                                 w.WizardSteps.Insert (0, step2);
181                         }
182                         catch (Exception e) {
183                                 Assert.Fail (e.Message);
184                         }
185                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count fail");
186                         Assert.AreEqual (step2, w.WizardSteps[0], "Step index fail");
187                 }
188
189                 [Test]
190                 public void WizardStepCollection_Remove ()
191                 {
192                         Wizard w = new Wizard ();
193                         WizardStep step1 = new WizardStep ();
194                         WizardStep step2 = new WizardStep ();
195
196                         try {
197                                 w.WizardSteps.Add (step1);
198                                 w.WizardSteps.Add (step2);
199                         }
200                         catch (Exception e) {
201                                 Assert.Fail (e.Message);
202                         }
203                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count before remove fail");
204                         try {
205                                 w.WizardSteps.Remove (step1);
206                                 w.WizardSteps.Remove (step2);
207                         }
208                         catch (Exception e) {
209                                 Assert.Fail (e.Message);
210                         }
211                         Assert.AreEqual (0, w.WizardSteps.Count, "Step count after remove fail");
212                 }
213
214                 [Test]
215                 public void WizardStepCollection_RemoveAt ()
216                 {
217                         Wizard w = new Wizard ();
218                         WizardStep step1 = new WizardStep ();
219                         WizardStep step2 = new WizardStep ();
220
221                         try {
222                                 w.WizardSteps.Add (step1);
223                                 w.WizardSteps.Add (step2);
224                         }
225                         catch (Exception e) {
226                                 Assert.Fail (e.Message);
227                         }
228                         Assert.AreEqual (2, w.WizardSteps.Count, "Step count before removeat fail");
229                         try {
230                                 w.WizardSteps.RemoveAt (0);
231                                 
232                         }
233                         catch (Exception e) {
234                                 Assert.Fail (e.Message);
235                         }
236                         Assert.AreEqual (1, w.WizardSteps.Count, "Step count after removeat fail");
237                         Assert.AreEqual (step2, w.WizardSteps[0], "Item value after remove");
238                 }
239         }
240 }
241 #endif