2 // Tests for System.Web.UI.WebControls.DataGridPagerStyle
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 {
42 public class DGTestClass : DataGrid {
48 public StateBag StateBag {
49 get { return base.ViewState; }
52 public string[] KeyValuePairs() {
57 e = ViewState.GetEnumerator();
58 result = new string[ViewState.Keys.Count];
61 while (e.MoveNext()) {
65 d = (DictionaryEntry)e.Current;
66 si = (StateItem)d.Value;
68 if (si.Value is String[]) {
71 values = (string[]) si.Value;
72 result[item] = d.Key.ToString() + "=";
73 if (values.Length > 0) {
74 result[item] += values[0];
76 for (int i = 1; i < values.Length; i++) {
77 result[item] += ", " + values[i];
81 result[item] = d.Key.ToString() + "=" + si.Value;
91 public class DataGridPagerStyleTest {
92 private static HtmlTextWriter GetWriter () {
93 StringWriter sw = new StringWriter ();
95 return new HtmlTextWriter (sw);
98 private bool IsEqual(object[] a1, object[] a2, string assertion) {
102 if (a1.Length != a2.Length) {
103 if (assertion != null) {
104 Assert.Fail(assertion + "( different length )");
110 notfound = new bool[a1.Length];
112 for (int i = 0; i < a1.Length; i++) {
113 for (int j = 0; j < a2.Length; j++) {
114 if (a1[i].Equals(a2[j])) {
119 if ((assertion != null) && (matches != i+1)) {
120 Assert.Fail(assertion + "( missing " + a1[i].ToString() + " )");
124 return matches == a1.Length;
128 public void DataGridPagerStyle_Defaults () {
130 DataGridPagerStyle s;
135 Assert.AreEqual (Color.Empty, s.BackColor, "D1");
136 Assert.AreEqual (Color.Empty, s.BorderColor, "D2");
137 Assert.AreEqual (BorderStyle.NotSet, s.BorderStyle, "D3");
138 Assert.AreEqual (Unit.Empty, s.BorderWidth, "D4");
139 Assert.AreEqual (string.Empty, s.CssClass, "D5");
140 Assert.AreEqual (Color.Empty, s.ForeColor, "D6");
141 Assert.AreEqual (Unit.Empty, s.Height, "D7");
142 Assert.AreEqual (Unit.Empty, s.Width, "D8");
144 Assert.AreEqual (PagerMode.NextPrev, s.Mode, "D9");
145 Assert.AreEqual (">", s.NextPageText, "D10");
146 Assert.AreEqual (10, s.PageButtonCount, "D11");
147 Assert.AreEqual (PagerPosition.Bottom, s.Position, "D12");
148 Assert.AreEqual ("<", s.PrevPageText, "D13");
149 Assert.AreEqual (true, s.Visible, "D14");
153 public void DataGridPagerStyle_Assignment () {
155 DataGridPagerStyle s;
161 s.Mode = PagerMode.NumericPages;
162 Assert.AreEqual (PagerMode.NumericPages, s.Mode, "A1");
164 s.NextPageText = "Next";
165 Assert.AreEqual ("Next", s.NextPageText, "A2");
167 s.PageButtonCount = 20;
168 Assert.AreEqual (20, s.PageButtonCount, "A3");
170 s.Position = PagerPosition.TopAndBottom;
171 Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "A4");
173 s.PrevPageText = "Prev";
174 Assert.AreEqual ("Prev", s.PrevPageText, "A5");
177 Assert.AreEqual (false, s.Visible, "A6");
181 public void DataGridPagerStyle_Copy () {
185 DataGridPagerStyle s;
186 DataGridPagerStyle copy;
192 copy = g2.PagerStyle;
194 s.Mode = PagerMode.NumericPages;
195 Assert.AreEqual (PagerMode.NumericPages, s.Mode, "C1");
197 s.NextPageText = "Next";
198 Assert.AreEqual ("Next", s.NextPageText, "C2");
200 s.PageButtonCount = 20;
201 Assert.AreEqual (20, s.PageButtonCount, "C3");
203 s.Position = PagerPosition.TopAndBottom;
204 Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "C4");
206 s.PrevPageText = "Prev";
207 Assert.AreEqual ("Prev", s.PrevPageText, "C5");
210 Assert.AreEqual (false, s.Visible, "C6");
212 // Now copy them over;
214 Assert.AreEqual (PagerMode.NumericPages, copy.Mode, "C7");
215 Assert.AreEqual ("Next", copy.NextPageText, "C8");
216 Assert.AreEqual (20, copy.PageButtonCount, "C9");
217 Assert.AreEqual (PagerPosition.TopAndBottom, copy.Position, "C10");
218 Assert.AreEqual ("Prev", copy.PrevPageText, "C11");
219 Assert.AreEqual (false, copy.Visible, "C12");
223 public void DataGridPagerStyle_Merge () {
227 DataGridPagerStyle s;
228 DataGridPagerStyle copy;
234 copy = g2.PagerStyle;
236 s.Mode = PagerMode.NumericPages;
237 Assert.AreEqual (PagerMode.NumericPages, s.Mode, "M1");
239 s.NextPageText = "Next";
240 Assert.AreEqual ("Next", s.NextPageText, "M2");
242 s.PageButtonCount = 20;
243 Assert.AreEqual (20, s.PageButtonCount, "M3");
245 copy.Position = PagerPosition.Top;
246 s.Position = PagerPosition.TopAndBottom;
247 Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "M4");
249 copy.PrevPageText = "Blah";
250 s.PrevPageText = "Prev";
251 Assert.AreEqual ("Prev", s.PrevPageText, "M5");
255 Assert.AreEqual (false, s.Visible, "M6");
260 Assert.AreEqual (PagerMode.NumericPages, copy.Mode, "M7");
261 Assert.AreEqual ("Next", copy.NextPageText, "M8");
262 Assert.AreEqual (20, copy.PageButtonCount, "M9");
263 Assert.AreEqual (PagerPosition.Top, copy.Position, "M10");
264 Assert.AreEqual ("Blah", copy.PrevPageText, "M11");
265 Assert.AreEqual (true, copy.Visible, "M12");
269 public void DataGridPagerStyle_Reset () {
272 DataGridPagerStyle s;
278 s.Mode = PagerMode.NumericPages;
279 Assert.AreEqual (PagerMode.NumericPages, s.Mode, "R1");
281 s.NextPageText = "Next";
282 Assert.AreEqual ("Next", s.NextPageText, "R2");
284 s.PageButtonCount = 20;
285 Assert.AreEqual (20, s.PageButtonCount, "R3");
287 s.Position = PagerPosition.TopAndBottom;
288 Assert.AreEqual (PagerPosition.TopAndBottom, s.Position, "R4");
290 s.PrevPageText = "Prev";
291 Assert.AreEqual ("Prev", s.PrevPageText, "R5");
294 Assert.AreEqual (false, s.Visible, "R6");
298 Assert.AreEqual (PagerMode.NextPrev, s.Mode, "D9");
299 Assert.AreEqual (">", s.NextPageText, "D10");
300 Assert.AreEqual (10, s.PageButtonCount, "D11");
301 Assert.AreEqual (PagerPosition.Bottom, s.Position, "D12");
302 Assert.AreEqual ("<", s.PrevPageText, "D13");
303 Assert.AreEqual (true, s.Visible, "D14");
307 [ExpectedException (typeof (ArgumentOutOfRangeException))]
308 public void PageButtonCount_Neg ()
314 d.PagerStyle.PageButtonCount = -2;
318 [ExpectedException (typeof (ArgumentOutOfRangeException))]
319 public void PageButtonCount_Zero ()
324 d.PagerStyle.PageButtonCount = 0;