2 // Tests for System.Web.UI.WebControls.DataGridItemCollection
5 // Peter Dennis Bartok (pbartok@novell.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using NUnit.Framework;
33 using System.Collections;
36 using System.Globalization;
39 using System.Web.UI.WebControls;
41 namespace MonoTests.System.Web.UI.WebControls
44 public class DataGridItemCollectionTest {
46 public void Defaults ()
48 DataGridItemCollection c;
52 list = new ArrayList();
53 item = new DataGridItem(0, 0, ListItemType.Item);
55 c = new DataGridItemCollection(list);
57 Assert.AreEqual(1, c.Count, "D1");
58 Assert.AreEqual(item, c[0], "D2");
61 item = new DataGridItem(1, 1, ListItemType.Header);
63 Assert.AreEqual(2, c.Count, "D3");
64 Assert.AreEqual(ListItemType.Header, c[1].ItemType, "D4");
69 DataGridItemCollection c;
74 list = new ArrayList();
75 item = new DataGridItem(0, 0, ListItemType.Item);
77 item = new DataGridItem(1, 1, ListItemType.Header);
79 item = new DataGridItem(2, 2, ListItemType.Footer);
82 c = new DataGridItemCollection(list);
84 copy = new DataGridItem[3];
85 Assert.AreEqual(3, c.Count, "C1");
87 Assert.AreEqual(3, copy.Length, "C2");
89 copy = new DataGridItem[4];
91 Assert.AreEqual(4, copy.Length, "C3");
95 [ExpectedException(typeof(IndexOutOfRangeException))]
96 public void OutOfBounds () {
97 DataGridItemCollection c;
102 list = new ArrayList();
103 item = new DataGridItem(0, 0, ListItemType.Item);
105 item = new DataGridItem(1, 1, ListItemType.Header);
107 item = new DataGridItem(2, 2, ListItemType.Footer);
110 c = new DataGridItemCollection(list);
112 copy = new DataGridItem[2];
117 [ExpectedException(typeof(IndexOutOfRangeException))]
118 public void OutOfBounds2 () {
119 DataGridItemCollection c;
124 list = new ArrayList();
125 item = new DataGridItem(0, 0, ListItemType.Item);
127 item = new DataGridItem(1, 1, ListItemType.Header);
129 item = new DataGridItem(2, 2, ListItemType.Footer);
132 c = new DataGridItemCollection(list);
134 copy = new DataGridItem[3];
139 [ExpectedException(typeof(InvalidCastException))]
140 public void BadTypeCopy () {
141 DataGridItemCollection c;
146 list = new ArrayList();
147 item = new DataGridItem(0, 0, ListItemType.Item);
149 item = new DataGridItem(1, 1, ListItemType.Header);
151 item = new DataGridItem(2, 2, ListItemType.Footer);
154 c = new DataGridItemCollection(list);
161 [ExpectedException(typeof(InvalidCastException))]
162 public void BadTypeCopy2 () {
163 DataGridItemCollection c;
168 list = new ArrayList();
169 item = new DataGridItem(0, 0, ListItemType.Item);
171 item = new DataGridItem(1, 1, ListItemType.Header);
173 item = new DataGridItem(2, 2, ListItemType.Footer);
176 c = new DataGridItemCollection(list);
178 copy = new string[2];
183 [ExpectedException(typeof(InvalidCastException))]
184 public void WrongType () {
185 DataGridItemCollection c;
188 list = new ArrayList();
192 c = new DataGridItemCollection(list);
194 Assert.AreEqual("blah", c[0], "E1");
198 [ExpectedException(typeof(ArgumentOutOfRangeException))]
199 public void BadIndex () {
200 DataGridItemCollection c;
203 list = new ArrayList();
207 c = new DataGridItemCollection(list);
209 Assert.AreEqual("blah", c[3], "E2");