2 // Tests for System.Web.UI.WebControls.CheckBoxList.cs
5 // Jackson Harper (jackson@ximian.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;
34 using System.Globalization;
37 using System.Web.UI.WebControls;
39 using System.Collections;
40 using MonoTests.SystemWeb.Framework;
41 using MonoTests.stand_alone.WebHarness;
42 using System.Collections.Specialized;
44 namespace MonoTests.System.Web.UI.WebControls {
46 public class CheckBoxListPoker : CheckBoxList {
48 public Style CreateStyle ()
50 return CreateControlStyle ();
53 public Control FindControlPoke (string name, int offset)
55 return FindControl (name, offset);
58 public string Render ()
60 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
62 return writer.InnerWriter.ToString ();
66 public new bool HasFooter
70 return base.HasFooter;
74 public new bool HasHeader
78 return base.HasHeader;
82 public new bool HasSeparators
86 return base.HasSeparators;
90 public new int RepeatedItemCount
94 return base.RepeatedItemCount;
98 public new void RaisePostDataChangedEvent ()
100 base.RaisePostDataChangedEvent ();
103 protected override Style GetItemStyle (ListItemType itemType, int repeatIndex)
105 Style s = new Style();
106 s.BackColor = Color.Red;
107 s.BorderStyle = BorderStyle.Solid;
108 WebTest.CurrentTest.UserData = "GetItemStyle";
112 public Style DoGetItemStyle (ListItemType itemType, int repeatIndex)
114 return base.GetItemStyle (itemType, repeatIndex);
117 public new string RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo)
119 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
120 base.RenderItem(itemType,repeatIndex,repeatInfo,writer);
121 return writer.InnerWriter.ToString ();
126 public class CheckBoxListTest
132 WebTest.CopyResource (t, "CheckBoxList_Bug377703_1.aspx", "CheckBoxList_Bug377703_1.aspx");
133 WebTest.CopyResource (t, "CheckBoxList_Bug377703_2.aspx", "CheckBoxList_Bug377703_2.aspx");
134 WebTest.CopyResource (t, "CheckBoxList_Bug578770.aspx", "CheckBoxList_Bug578770.aspx");
135 WebTest.CopyResource (t, "CheckBoxList_Bug600415.aspx", "CheckBoxList_Bug600415.aspx");
139 public void Defaults ()
141 CheckBoxListPoker c = new CheckBoxListPoker ();
143 Assert.AreEqual (c.CellPadding, -1, "A1");
144 Assert.AreEqual (c.CellSpacing, -1, "A2");
145 Assert.AreEqual (c.RepeatColumns, 0, "A3");
146 Assert.AreEqual (c.RepeatDirection,
147 RepeatDirection.Vertical, "A4");
148 Assert.AreEqual (c.RepeatLayout,
149 RepeatLayout.Table, "A5");
150 Assert.AreEqual (c.TextAlign, TextAlign.Right, "A6");
151 Assert.AreEqual (false, c.HasFooter, "HasFooter");
152 Assert.AreEqual (false, c.HasHeader, "HasHeader");
153 Assert.AreEqual (false, c.HasSeparators, "HasSeparators");
154 Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount");
155 Assert.AreEqual (null, c.DoGetItemStyle (ListItemType.Item, 0), "GetItemStyle");
159 public void CheckBoxList_Bug377703_1 ()
161 WebTest t = new WebTest ("CheckBoxList_Bug377703_1.aspx");
162 t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_1_OnInit);
163 string origHtmlFirst = "<table id=\"cbxl1\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" value=\"x\" /><label for=\"cbxl1_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_1\" type=\"checkbox\" name=\"cbxl1$1\" value=\"y\" /><label for=\"cbxl1_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_2\" type=\"checkbox\" name=\"cbxl1$2\" value=\"z\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
164 string origHtmlSecond = "<table id=\"cbxl1\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" checked=\"checked\" value=\"x\" /><label for=\"cbxl1_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_1\" type=\"checkbox\" name=\"cbxl1$1\" value=\"y\" /><label for=\"cbxl1_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl1_2\" type=\"checkbox\" name=\"cbxl1$2\" value=\"z\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
165 string html = t.Run ();
166 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
168 HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
170 FormRequest fr = new FormRequest (t.Response, "form1");
171 fr.Controls.Add ("cbxl1$0");
172 fr.Controls ["cbxl1$0"].Value = "on";
174 fr.Controls.Add ("ctl01");
175 fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
180 fr = new FormRequest (t.Response, "form1");
181 fr.Controls.Add ("cbxl1$0");
182 fr.Controls ["cbxl1$0"].Value = "on";
184 fr.Controls.Add ("ctl01");
185 fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
190 listHtml = HtmlDiff.GetControlFromPageHtml (html);
191 HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
194 public static void CheckBoxList_Bug377703_1_OnInit (Page p)
196 CheckBoxList cbxl1 = p.FindControl ("cbxl1") as CheckBoxList;
198 cbxl1.DataSource = new[] {
199 new { ID = "x", Text = "X" },
200 new { ID = "y", Text = "Y" },
201 new { ID = "z", Text = "Z" },
203 cbxl1.DataValueField = "ID";
204 cbxl1.DataTextField = "ID";
209 public void CheckBoxList_Bug377703_2 ()
211 WebTest t = new WebTest ("CheckBoxList_Bug377703_2.aspx");
212 t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_2_OnInit);
213 string origHtmlFirst = "<table id=\"cbxl2\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" value=\"x\" /><label for=\"cbxl2_0\">x</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" value=\"y\" /><label for=\"cbxl2_1\">y</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" value=\"z\" /><label for=\"cbxl2_2\">z</label></td>\r\n\t</tr>\r\n</table>";
214 string origHtmlSecond = "<table id=\"cbxl2\" class=\"aspNetDisabled\">\r\n\t<tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" value=\"x\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" value=\"y\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" value=\"z\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
215 string origHtmlThird = "<table id=\"cbxl2\" class=\"aspNetDisabled\">\r\n\t<tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" value=\"x\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" value=\"y\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" value=\"z\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
216 string html = t.Run ();
217 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
219 HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
221 FormRequest fr = new FormRequest (t.Response, "form1");
222 fr.Controls.Add ("cbxl2$0");
223 fr.Controls ["cbxl2$0"].Value = "on";
225 fr.Controls.Add ("cbxl2$2");
226 fr.Controls ["cbxl2$2"].Value = "on";
228 fr.Controls.Add ("ctl01");
229 fr.Controls ["ctl01"].Value = "Click to toggle enable status above";
234 listHtml = HtmlDiff.GetControlFromPageHtml (html);
236 HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
238 fr = new FormRequest (t.Response, "form1");
239 fr.Controls.Add ("ctl02");
240 fr.Controls ["ctl02"].Value = "Click to refresh page";
245 listHtml = HtmlDiff.GetControlFromPageHtml (html);
246 HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
249 public static void CheckBoxList_Bug377703_2_OnInit (Page p)
251 CheckBoxList cbxl2 = p.FindControl ("cbxl2") as CheckBoxList;
253 cbxl2.DataSource = new[] {
254 new { ID = "x", Text = "X" },
255 new { ID = "y", Text = "Y" },
256 new { ID = "z", Text = "Z" },
258 cbxl2.DataValueField = "ID";
259 cbxl2.DataTextField = "ID";
264 public void CheckBoxList_Bug578770 ()
266 WebTest t = new WebTest ("CheckBoxList_Bug578770.aspx");
267 t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug578770_OnInit);
268 string origHtml = "<table id=\"test\">\r\n\t<tr>\r\n\t\t<td><span class=\"aspNetDisabled\"><input id=\"test_0\" type=\"checkbox\" name=\"test$0\" disabled=\"disabled\" value=\"Sun\" /><label for=\"test_0\">Sun</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_1\" type=\"checkbox\" name=\"test$1\" value=\"Mon\" /><label for=\"test_1\">Mon</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_2\" type=\"checkbox\" name=\"test$2\" value=\"Tue\" /><label for=\"test_2\">Tue</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_3\" type=\"checkbox\" name=\"test$3\" value=\"Wed\" /><label for=\"test_3\">Wed</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_4\" type=\"checkbox\" name=\"test$4\" value=\"Thu\" /><label for=\"test_4\">Thu</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_5\" type=\"checkbox\" name=\"test$5\" value=\"Fri\" /><label for=\"test_5\">Fri</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span><input id=\"test_6\" type=\"checkbox\" name=\"test$6\" value=\"Sat\" /><label for=\"test_6\">Sat</label></span></td>\r\n\t</tr>\r\n</table>";
269 string html = t.Run ();
270 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
272 HtmlDiff.AssertAreEqual (origHtml, listHtml, "#A1");
275 public static void CheckBoxList_Bug578770_OnInit (Page p)
277 CheckBoxList test = p.FindControl ("test") as CheckBoxList;
278 string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
279 test.DataSource = weekDays;
281 test.Items[0].Enabled = false;
285 public void CheckBoxList_Bug600415 ()
287 WebTest t = new WebTest ("CheckBoxList_Bug600415.aspx");
288 string origHtmlFirst = "<table id=\"checkBoxList\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" value=\"Item 1\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" value=\"Item 2\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" checked=\"checked\" value=\"Item 3\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" value=\"Item 4\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
289 string origHtmlSecond = "<table id=\"checkBoxList\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" value=\"Item 1\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" value=\"Item 2\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" value=\"Item 3\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" value=\"Item 4\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
290 string origHtmlThird = "<table id=\"checkBoxList\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" value=\"Item 1\" /><label for=\"checkBoxList_0\">Item 1</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_1\" type=\"checkbox\" name=\"checkBoxList$1\" checked=\"checked\" value=\"Item 2\" /><label for=\"checkBoxList_1\">Item 2</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_2\" type=\"checkbox\" name=\"checkBoxList$2\" checked=\"checked\" value=\"Item 3\" /><label for=\"checkBoxList_2\">Item 3</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"checkBoxList_3\" type=\"checkbox\" name=\"checkBoxList$3\" checked=\"checked\" value=\"Item 4\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
291 string html = t.Run ();
292 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
294 HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
296 FormRequest fr = new FormRequest (t.Response, "form1");
297 fr.Controls.Add ("cmdClick");
298 fr.Controls ["cmdClick"].Value = "Ok";
303 listHtml = HtmlDiff.GetControlFromPageHtml (html);
304 HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
306 fr = new FormRequest (t.Response, "form1");
307 fr.Controls.Add ("checkBoxList$0");
308 fr.Controls ["checkBoxList$0"].Value = "on";
309 fr.Controls.Add ("checkBoxList$1");
310 fr.Controls ["checkBoxList$1"].Value = "on";
311 fr.Controls.Add ("checkBoxList$2");
312 fr.Controls ["checkBoxList$2"].Value = "on";
313 fr.Controls.Add ("checkBoxList$3");
314 fr.Controls ["checkBoxList$3"].Value = "on";
318 listHtml = HtmlDiff.GetControlFromPageHtml (html);
319 HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
323 public void RaisePostDataChangedEvent ()
325 CheckBoxListPoker c = new CheckBoxListPoker ();
326 c.SelectedIndexChanged += new EventHandler (c_SelectedIndexChanged);
327 Assert.AreEqual (false, eventSelectedIndexChanged, "RaisePostDataChangedEvent#1");
328 c.RaisePostDataChangedEvent ();
329 Assert.AreEqual (true, eventSelectedIndexChanged, "RaisePostDataChangedEvent#2");
332 bool eventSelectedIndexChanged;
333 void c_SelectedIndexChanged (object sender, EventArgs e)
335 eventSelectedIndexChanged = true;
339 [Category("NunitWeb")]
340 public void GetItemStyle ()
342 WebTest t = new WebTest (PageInvoker.CreateOnLoad (GetItemStyle_Load));
343 string html = t.Run ();
344 string ctrl = HtmlDiff.GetControlFromPageHtml (html);
345 if (ctrl == string.Empty)
346 Assert.Fail ("CheckBoxList not created fail");
347 Assert.AreEqual ("GetItemStyle", (string) t.UserData, "GetItemStyle not done");
348 if ( ctrl.IndexOf("<td style=\"background-color:Red;border-style:Solid;\">") == -1)
349 Assert.Fail ("CheckBoxList style not rendered");
352 public static void GetItemStyle_Load (Page p)
354 CheckBoxListPoker c = new CheckBoxListPoker ();
355 ListItem l1 = new ListItem ("item1", "value1");
356 ListItem l2 = new ListItem ("item2", "value2");
360 p.Form.Controls.Add(new LiteralControl(HtmlDiff.BEGIN_TAG));
361 p.Form.Controls.Add (c);
362 p.Form.Controls.Add(new LiteralControl(HtmlDiff.END_TAG));
366 public void RenderItem ()
368 string origHtml1 = "<input id=\"0\" type=\"checkbox\" name=\"0\" value=\"value1\" /><label for=\"0\">item1</label>";
369 string origHtml2 = "<input id=\"1\" type=\"checkbox\" name=\"1\" value=\"value2\" /><label for=\"1\">item2</label>";
370 CheckBoxListPoker c = new CheckBoxListPoker ();
371 ListItem l1 = new ListItem ("item1", "value1");
372 ListItem l2 = new ListItem ("item2", "value2");
376 string html = c.RenderItem (ListItemType.Item, 0, null);
377 HtmlDiff.AssertAreEqual (origHtml1, html, "RenderItem#1");
378 html = c.RenderItem (ListItemType.Item, 1, null);
379 HtmlDiff.AssertAreEqual (origHtml2, html, "RenderItem#2");
383 public void RepeatedItemCount ()
385 CheckBoxListPoker c = new CheckBoxListPoker ();
386 ListItem l1 = new ListItem ("item1", "value1");
387 ListItem l2 = new ListItem ("item2", "value2");
388 Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount#1");
391 Assert.AreEqual (2, c.RepeatedItemCount, "RepeatedItemCount#2");
397 public void CleanProperties ()
399 CheckBoxList c = new CheckBoxList ();
401 c.CellPadding = Int32.MaxValue;
402 Assert.AreEqual (c.CellPadding, Int32.MaxValue, "A1");
404 c.CellSpacing = Int32.MaxValue;
405 Assert.AreEqual (c.CellSpacing, Int32.MaxValue, "A2");
407 c.RepeatColumns = Int32.MaxValue;
408 Assert.AreEqual (c.RepeatColumns, Int32.MaxValue, "A3");
410 foreach (RepeatDirection d in
411 Enum.GetValues (typeof (RepeatDirection))) {
412 c.RepeatDirection = d;
413 Assert.AreEqual (c.RepeatDirection, d, "A4-" + d);
416 foreach (RepeatLayout l in
417 Enum.GetValues (typeof (RepeatLayout))) {
419 Assert.AreEqual (c.RepeatLayout, l, "A5-" + l);
424 [ExpectedException (typeof (ArgumentOutOfRangeException))]
425 public void CellPaddingTooLow ()
427 CheckBoxList c = new CheckBoxList ();
432 [ExpectedException (typeof (ArgumentOutOfRangeException))]
433 public void CellSpacingTooLow ()
435 CheckBoxList c = new CheckBoxList ();
440 [ExpectedException (typeof (ArgumentOutOfRangeException))]
441 public void RepeatColumsTooLow ()
443 CheckBoxList c = new CheckBoxList ();
444 c.RepeatColumns = -1;
448 [ExpectedException (typeof (ArgumentOutOfRangeException))]
449 public void RepeatDirection_Invalid ()
451 CheckBoxList c = new CheckBoxList ();
452 c.RepeatDirection = (RepeatDirection) Int32.MaxValue;
456 [ExpectedException (typeof (ArgumentOutOfRangeException))]
457 public void RepeatLayout_Invalid ()
459 CheckBoxList c = new CheckBoxList ();
460 c.RepeatLayout = (RepeatLayout) Int32.MaxValue;
464 [ExpectedException (typeof (ArgumentOutOfRangeException))]
465 public void TextAlign_Invalid ()
467 CheckBoxList c = new CheckBoxList ();
468 c.TextAlign = (TextAlign) Int32.MaxValue;
472 public void ChildCheckBoxControl ()
474 CheckBoxList c = new CheckBoxList ();
475 Assert.AreEqual (c.Controls.Count, 1, "A1");
476 Assert.AreEqual (c.Controls [0].GetType (), typeof (CheckBox), "A2");
480 public void CreateStyle ()
482 CheckBoxListPoker c = new CheckBoxListPoker ();
483 Assert.AreEqual (c.CreateStyle ().GetType (), typeof (TableStyle), "A1");
487 public void RepeatInfoProperties ()
489 IRepeatInfoUser ri = new CheckBoxList ();
491 Assert.IsFalse (ri.HasFooter, "A1");
492 Assert.IsFalse (ri.HasHeader, "A2");
493 Assert.IsFalse (ri.HasSeparators, "A3");
494 Assert.AreEqual (ri.RepeatedItemCount, 0, "A4");
498 public void RepeatInfoCount ()
500 CheckBoxList c = new CheckBoxList ();
501 IRepeatInfoUser ri = (IRepeatInfoUser) c;
503 Assert.AreEqual (ri.RepeatedItemCount, 0, "A1");
507 c.Items.Add ("three");
508 Assert.AreEqual (ri.RepeatedItemCount, 3, "A2");
512 public void RepeatInfoStyle ()
514 IRepeatInfoUser ri = new CheckBoxList ();
516 foreach (ListItemType t in Enum.GetValues (typeof (ListItemType))) {
517 Assert.AreEqual (ri.GetItemStyle (t, 0), null, "A1-" + t);
518 Assert.AreEqual (ri.GetItemStyle (t, 1), null, "A2-" + t);
519 Assert.AreEqual (ri.GetItemStyle (t, 2), null, "A3-" + t);
520 Assert.AreEqual (ri.GetItemStyle (t, 3), null, "A4-" + t);
525 [ExpectedException (typeof (ArgumentOutOfRangeException))]
526 public void RepeatInfoRenderOutOfRange ()
528 StringWriter sw = new StringWriter ();
529 HtmlTextWriter tw = new HtmlTextWriter (sw);
530 IRepeatInfoUser ri = new CheckBoxList ();
532 ri.RenderItem (ListItemType.Item, -1, new RepeatInfo (), tw);
536 public void RepeatInfoRenderItem ()
538 string origHtml = "<input id=\"0\" type=\"checkbox\" name=\"0\" value=\"one\" /><label for=\"0\">one</label>";
539 StringWriter sw = new StringWriter ();
540 HtmlTextWriter tw = new HtmlTextWriter (sw);
541 CheckBoxList c = new CheckBoxList ();
542 IRepeatInfoUser ri = (IRepeatInfoUser) c;
543 RepeatInfo r = new RepeatInfo ();
548 ri.RenderItem (ListItemType.Item, 0, r, tw);
549 string html = sw.ToString ();
550 Assert.AreEqual (origHtml, html, "A1");
554 public void FindControl ()
556 CheckBoxListPoker p = new CheckBoxListPoker ();
561 p.Items.Add ("three");
563 // Everything seems to return this.
564 Assert.AreEqual (p.FindControlPoke (String.Empty, 0), p, "A1");
565 Assert.AreEqual (p.FindControlPoke ("id", 0), p, "A2");
566 Assert.AreEqual (p.FindControlPoke ("id_0", 0), p, "A3");
567 Assert.AreEqual (p.FindControlPoke ("id_1", 0), p, "A4");
568 Assert.AreEqual (p.FindControlPoke ("id_2", 0), p, "A5");
569 Assert.AreEqual (p.FindControlPoke ("id_3", 0), p, "A6");
570 Assert.AreEqual (p.FindControlPoke ("0", 0), p, "A7");
572 Assert.AreEqual (p.FindControlPoke (String.Empty, 10), p, "A1");
573 Assert.AreEqual (p.FindControlPoke ("id", 10), p, "A2");
574 Assert.AreEqual (p.FindControlPoke ("id_0", 10), p, "A3");
575 Assert.AreEqual (p.FindControlPoke ("id_1", 10), p, "A4");
576 Assert.AreEqual (p.FindControlPoke ("id_2", 10), p, "A5");
577 Assert.AreEqual (p.FindControlPoke ("id_3", 10), p, "A6");
578 Assert.AreEqual (p.FindControlPoke ("0", 10), p, "A7");
581 private void Render (CheckBoxList list, string expected, string test)
583 StringWriter sw = new StringWriter ();
584 HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
587 list.RenderControl (tw);
588 HtmlDiff.AssertAreEqual (expected, sw.ToString (), test);
592 public void RenderEmpty ()
594 CheckBoxList c = new CheckBoxList ();
596 Render (c, "", "A1");
598 Render (c, "", "A2");
600 c = new CheckBoxList ();
602 Render (c, "", "A3");
604 c = new CheckBoxList ();
605 c.TextAlign = TextAlign.Left;
606 Render (c, "", "A4");
610 [Category("NotDotNet")] // MS's implementation throws NRE's from these
611 public void Render ()
613 string origHtml1 = "<table>\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" value=\"foo\"/><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
614 string origHtml2 = "<table>\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" value=\"foo\"/><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
616 c = new CheckBoxList ();
619 Render (c, origHtml1, "A5");
621 c = new CheckBoxList ();
623 Render (c, origHtml2, "A6");
628 [Category("NotDotNet")] // MS's implementation throws NRE's from these
629 public void TestTabIndex ()
631 CheckBoxList c = new CheckBoxList ();
633 c.Items.Add ("Item1");
634 string exp = @"<table>
636 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></td>
639 Render (c, exp, "B1");
644 [Category("NotDotNet")] // MS's implementation throws NRE's from these
645 public void TestDisabled ()
647 CheckBoxList c = new CheckBoxList ();
649 c.Items.Add ("Item1");
650 string exp = @"<table class=""aspNetDisabled"">
652 <td><span class=""aspNetDisabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></span></td>
655 Render (c, exp, "C1");
657 class TestCheckBoxList : CheckBoxList
659 public void CallVerifyMultiSelect()
661 base.VerifyMultiSelect();
665 public void VerifyMultiSelectTest()
667 TestCheckBoxList list = new TestCheckBoxList();
668 list.CallVerifyMultiSelect();
670 [TestFixtureTearDown]
671 public void teardown ()