2007-01-30 Adar Wesley <adarw@mainsofot.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / DataGridItemCollectionTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.DataGridItemCollection
3 //
4 // Author:
5 //      Peter Dennis Bartok (pbartok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.Collections;
34 using System.Drawing;
35 using System.IO;
36 using System.Globalization;
37 using System.Web;
38 using System.Web.UI;
39 using System.Web.UI.WebControls;
40
41 namespace MonoTests.System.Web.UI.WebControls
42 {
43         [TestFixture]   
44         public class DataGridItemCollectionTest {
45                 [Test]
46                 public void Defaults ()
47                 {
48                         DataGridItemCollection  c;
49                         ArrayList               list;
50                         DataGridItem            item;
51
52                         list = new ArrayList();
53                         item = new DataGridItem(0, 0, ListItemType.Item);
54                         list.Add(item);
55                         c = new DataGridItemCollection(list);
56
57                         Assert.AreEqual(1, c.Count, "D1");
58                         Assert.AreEqual(item, c[0], "D2");
59
60                         // Copy or ref?
61                         item = new DataGridItem(1, 1, ListItemType.Header);
62                         list.Add(item);
63                         Assert.AreEqual(2, c.Count, "D3");
64                         Assert.AreEqual(ListItemType.Header, c[1].ItemType, "D4");
65                 }
66
67                 [Test]
68                 public void Copy () {
69                         DataGridItemCollection  c;
70                         ArrayList               list;
71                         DataGridItem[]          copy;
72                         DataGridItem            item;
73
74                         list = new ArrayList();
75                         item = new DataGridItem(0, 0, ListItemType.Item);
76                         list.Add(item);
77                         item = new DataGridItem(1, 1, ListItemType.Header);
78                         list.Add(item);
79                         item = new DataGridItem(2, 2, ListItemType.Footer);
80                         list.Add(item);
81
82                         c = new DataGridItemCollection(list);
83
84                         copy = new DataGridItem[3];
85                         Assert.AreEqual(3, c.Count, "C1");
86                         c.CopyTo(copy, 0);
87                         Assert.AreEqual(3, copy.Length, "C2");
88
89                         copy = new DataGridItem[4];
90                         c.CopyTo(copy, 1);
91                         Assert.AreEqual(4, copy.Length, "C3");
92                 }
93
94                 [Test]
95                 [ExpectedException(typeof(IndexOutOfRangeException))]
96                 public void OutOfBounds () {
97                         DataGridItemCollection  c;
98                         ArrayList               list;
99                         DataGridItem[]          copy;
100                         DataGridItem            item;
101
102                         list = new ArrayList();
103                         item = new DataGridItem(0, 0, ListItemType.Item);
104                         list.Add(item);
105                         item = new DataGridItem(1, 1, ListItemType.Header);
106                         list.Add(item);
107                         item = new DataGridItem(2, 2, ListItemType.Footer);
108                         list.Add(item);
109
110                         c = new DataGridItemCollection(list);
111
112                         copy = new DataGridItem[2];
113                         c.CopyTo(copy, 0);
114                 }
115
116                 [Test]
117                 [ExpectedException(typeof(IndexOutOfRangeException))]
118                 public void OutOfBounds2 () {
119                         DataGridItemCollection  c;
120                         ArrayList               list;
121                         DataGridItem[]          copy;
122                         DataGridItem            item;
123
124                         list = new ArrayList();
125                         item = new DataGridItem(0, 0, ListItemType.Item);
126                         list.Add(item);
127                         item = new DataGridItem(1, 1, ListItemType.Header);
128                         list.Add(item);
129                         item = new DataGridItem(2, 2, ListItemType.Footer);
130                         list.Add(item);
131
132                         c = new DataGridItemCollection(list);
133
134                         copy = new DataGridItem[3];
135                         c.CopyTo(copy, 1);
136                 }
137
138                 [Test]
139                 [ExpectedException(typeof(InvalidCastException))]
140                 public void BadTypeCopy () {
141                         DataGridItemCollection  c;
142                         ArrayList               list;
143                         Array                   copy;
144                         DataGridItem            item;
145
146                         list = new ArrayList();
147                         item = new DataGridItem(0, 0, ListItemType.Item);
148                         list.Add(item);
149                         item = new DataGridItem(1, 1, ListItemType.Header);
150                         list.Add(item);
151                         item = new DataGridItem(2, 2, ListItemType.Footer);
152                         list.Add(item);
153
154                         c = new DataGridItemCollection(list);
155
156                         copy = new Array[2];
157                         c.CopyTo(copy, 0);
158                 }
159
160                 [Test]
161                 [ExpectedException(typeof(InvalidCastException))]
162                 public void BadTypeCopy2 () {
163                         DataGridItemCollection  c;
164                         ArrayList               list;
165                         string[]                copy;
166                         DataGridItem            item;
167
168                         list = new ArrayList();
169                         item = new DataGridItem(0, 0, ListItemType.Item);
170                         list.Add(item);
171                         item = new DataGridItem(1, 1, ListItemType.Header);
172                         list.Add(item);
173                         item = new DataGridItem(2, 2, ListItemType.Footer);
174                         list.Add(item);
175
176                         c = new DataGridItemCollection(list);
177
178                         copy = new string[2];
179                         c.CopyTo(copy, 0);
180                 }
181
182                 [Test]
183                 [ExpectedException(typeof(InvalidCastException))]
184                 public void WrongType () {
185                         DataGridItemCollection  c;
186                         ArrayList               list;
187
188                         list = new ArrayList();
189                         list.Add("blah");
190                         list.Add("argl");
191
192                         c = new DataGridItemCollection(list);
193
194                         Assert.AreEqual("blah", c[0], "E1");
195                 }
196
197                 [Test]
198                 [ExpectedException(typeof(ArgumentOutOfRangeException))]
199                 public void BadIndex () {
200                         DataGridItemCollection  c;
201                         ArrayList               list;
202
203                         list = new ArrayList();
204                         list.Add("blah");
205                         list.Add("argl");
206
207                         c = new DataGridItemCollection(list);
208
209                         Assert.AreEqual("blah", c[3], "E2");
210                 }
211         }
212 }