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);
164 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>";
165 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>";
167 string origHtmlFirst = "<table id=\"cbxl1\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" /><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\" /><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\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
168 string origHtmlSecond = "<table id=\"cbxl1\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl1_0\" type=\"checkbox\" name=\"cbxl1$0\" checked=\"checked\" /><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\" /><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\" /><label for=\"cbxl1_2\">z</label></td>\r\n\t</tr>\r\n</table>";
170 string html = t.Run ();
171 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
173 HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
175 FormRequest fr = new FormRequest (t.Response, "form1");
176 fr.Controls.Add ("cbxl1$0");
177 fr.Controls ["cbxl1$0"].Value = "on";
179 fr.Controls.Add ("ctl01");
180 fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
185 fr = new FormRequest (t.Response, "form1");
186 fr.Controls.Add ("cbxl1$0");
187 fr.Controls ["cbxl1$0"].Value = "on";
189 fr.Controls.Add ("ctl01");
190 fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
195 listHtml = HtmlDiff.GetControlFromPageHtml (html);
196 HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
199 public static void CheckBoxList_Bug377703_1_OnInit (Page p)
201 CheckBoxList cbxl1 = p.FindControl ("cbxl1") as CheckBoxList;
203 cbxl1.DataSource = new[] {
204 new { ID = "x", Text = "X" },
205 new { ID = "y", Text = "Y" },
206 new { ID = "z", Text = "Z" },
208 cbxl1.DataValueField = "ID";
209 cbxl1.DataTextField = "ID";
214 public void CheckBoxList_Bug377703_2 ()
216 WebTest t = new WebTest ("CheckBoxList_Bug377703_2.aspx");
217 t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_2_OnInit);
219 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>";
220 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>";
221 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>";
223 string origHtmlFirst = "<table id=\"cbxl2\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" /><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\" /><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\" /><label for=\"cbxl2_2\">z</label></td>\r\n\t</tr>\r\n</table>";
224 string origHtmlSecond = "<table id=\"cbxl2\" disabled=\"disabled\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
225 string origHtmlThird = "<table id=\"cbxl2\" disabled=\"disabled\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_0\" type=\"checkbox\" name=\"cbxl2$0\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_0\">x</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_1\" type=\"checkbox\" name=\"cbxl2$1\" disabled=\"disabled\" /><label for=\"cbxl2_1\">y</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"cbxl2_2\" type=\"checkbox\" name=\"cbxl2$2\" checked=\"checked\" disabled=\"disabled\" /><label for=\"cbxl2_2\">z</label></span></td>\r\n\t</tr>\r\n</table>";
227 string html = t.Run ();
228 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
230 HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
232 FormRequest fr = new FormRequest (t.Response, "form1");
233 fr.Controls.Add ("cbxl2$0");
234 fr.Controls ["cbxl2$0"].Value = "on";
236 fr.Controls.Add ("cbxl2$2");
237 fr.Controls ["cbxl2$2"].Value = "on";
239 fr.Controls.Add ("ctl01");
240 fr.Controls ["ctl01"].Value = "Click to toggle enable status above";
245 listHtml = HtmlDiff.GetControlFromPageHtml (html);
247 HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
249 fr = new FormRequest (t.Response, "form1");
250 fr.Controls.Add ("ctl02");
251 fr.Controls ["ctl02"].Value = "Click to refresh page";
256 listHtml = HtmlDiff.GetControlFromPageHtml (html);
257 HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
260 public static void CheckBoxList_Bug377703_2_OnInit (Page p)
262 CheckBoxList cbxl2 = p.FindControl ("cbxl2") as CheckBoxList;
264 cbxl2.DataSource = new[] {
265 new { ID = "x", Text = "X" },
266 new { ID = "y", Text = "Y" },
267 new { ID = "z", Text = "Z" },
269 cbxl2.DataValueField = "ID";
270 cbxl2.DataTextField = "ID";
275 public void CheckBoxList_Bug578770 ()
277 WebTest t = new WebTest ("CheckBoxList_Bug578770.aspx");
278 t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug578770_OnInit);
280 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>";
282 string origHtml = "<table id=\"test\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><span disabled=\"disabled\"><input id=\"test_0\" type=\"checkbox\" name=\"test$0\" disabled=\"disabled\" /><label for=\"test_0\">Sun</label></span></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_1\" type=\"checkbox\" name=\"test$1\" /><label for=\"test_1\">Mon</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_2\" type=\"checkbox\" name=\"test$2\" /><label for=\"test_2\">Tue</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_3\" type=\"checkbox\" name=\"test$3\" /><label for=\"test_3\">Wed</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_4\" type=\"checkbox\" name=\"test$4\" /><label for=\"test_4\">Thu</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_5\" type=\"checkbox\" name=\"test$5\" /><label for=\"test_5\">Fri</label></td>\r\n\t</tr><tr>\r\n\t\t<td><input id=\"test_6\" type=\"checkbox\" name=\"test$6\" /><label for=\"test_6\">Sat</label></td>\r\n\t</tr>\r\n</table>";
284 string html = t.Run ();
285 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
287 HtmlDiff.AssertAreEqual (origHtml, listHtml, "#A1");
290 public static void CheckBoxList_Bug578770_OnInit (Page p)
292 CheckBoxList test = p.FindControl ("test") as CheckBoxList;
293 string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
294 test.DataSource = weekDays;
296 test.Items[0].Enabled = false;
300 public void CheckBoxList_Bug600415 ()
302 WebTest t = new WebTest ("CheckBoxList_Bug600415.aspx");
304 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>";
305 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>";
306 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>";
308 string origHtmlFirst = "<table id=\"checkBoxList\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" /><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\" /><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\" /><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\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
309 string origHtmlSecond = "<table id=\"checkBoxList\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" /><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\" /><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\" /><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\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
310 string origHtmlThird = "<table id=\"checkBoxList\" border=\"0\">\r\n\t<tr>\r\n\t\t<td><input id=\"checkBoxList_0\" type=\"checkbox\" name=\"checkBoxList$0\" checked=\"checked\" /><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\" /><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\" /><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\" /><label for=\"checkBoxList_3\">Item 4</label></td>\r\n\t</tr>\r\n</table>";
312 string html = t.Run ();
313 string listHtml = HtmlDiff.GetControlFromPageHtml (html);
315 HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
317 FormRequest fr = new FormRequest (t.Response, "form1");
318 fr.Controls.Add ("cmdClick");
319 fr.Controls ["cmdClick"].Value = "Ok";
324 listHtml = HtmlDiff.GetControlFromPageHtml (html);
325 HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
327 fr = new FormRequest (t.Response, "form1");
328 fr.Controls.Add ("checkBoxList$0");
329 fr.Controls ["checkBoxList$0"].Value = "on";
330 fr.Controls.Add ("checkBoxList$1");
331 fr.Controls ["checkBoxList$1"].Value = "on";
332 fr.Controls.Add ("checkBoxList$2");
333 fr.Controls ["checkBoxList$2"].Value = "on";
334 fr.Controls.Add ("checkBoxList$3");
335 fr.Controls ["checkBoxList$3"].Value = "on";
339 listHtml = HtmlDiff.GetControlFromPageHtml (html);
340 HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
344 public void RaisePostDataChangedEvent ()
346 CheckBoxListPoker c = new CheckBoxListPoker ();
347 c.SelectedIndexChanged += new EventHandler (c_SelectedIndexChanged);
348 Assert.AreEqual (false, eventSelectedIndexChanged, "RaisePostDataChangedEvent#1");
349 c.RaisePostDataChangedEvent ();
350 Assert.AreEqual (true, eventSelectedIndexChanged, "RaisePostDataChangedEvent#2");
353 bool eventSelectedIndexChanged;
354 void c_SelectedIndexChanged (object sender, EventArgs e)
356 eventSelectedIndexChanged = true;
360 [Category("NunitWeb")]
361 public void GetItemStyle ()
363 WebTest t = new WebTest (PageInvoker.CreateOnLoad (GetItemStyle_Load));
364 string html = t.Run ();
365 string ctrl = HtmlDiff.GetControlFromPageHtml (html);
366 if (ctrl == string.Empty)
367 Assert.Fail ("CheckBoxList not created fail");
368 Assert.AreEqual ("GetItemStyle", (string) t.UserData, "GetItemStyle not done");
369 if ( ctrl.IndexOf("<td style=\"background-color:Red;border-style:Solid;\">") == -1)
370 Assert.Fail ("CheckBoxList style not rendered");
373 public static void GetItemStyle_Load (Page p)
375 CheckBoxListPoker c = new CheckBoxListPoker ();
376 ListItem l1 = new ListItem ("item1", "value1");
377 ListItem l2 = new ListItem ("item2", "value2");
381 p.Form.Controls.Add(new LiteralControl(HtmlDiff.BEGIN_TAG));
382 p.Form.Controls.Add (c);
383 p.Form.Controls.Add(new LiteralControl(HtmlDiff.END_TAG));
387 public void RenderItem ()
390 string origHtml1 = "<input id=\"0\" type=\"checkbox\" name=\"0\" value=\"value1\" /><label for=\"0\">item1</label>";
391 string origHtml2 = "<input id=\"1\" type=\"checkbox\" name=\"1\" value=\"value2\" /><label for=\"1\">item2</label>";
393 string origHtml1 = "<input id=\"0\" type=\"checkbox\" name=\"0\" /><label for=\"0\">item1</label>";
394 string origHtml2 = "<input id=\"1\" type=\"checkbox\" name=\"1\" /><label for=\"1\">item2</label>";
396 CheckBoxListPoker c = new CheckBoxListPoker ();
397 ListItem l1 = new ListItem ("item1", "value1");
398 ListItem l2 = new ListItem ("item2", "value2");
402 string html = c.RenderItem (ListItemType.Item, 0, null);
403 HtmlDiff.AssertAreEqual (origHtml1, html, "RenderItem#1");
404 html = c.RenderItem (ListItemType.Item, 1, null);
405 HtmlDiff.AssertAreEqual (origHtml2, html, "RenderItem#2");
409 public void RepeatedItemCount ()
411 CheckBoxListPoker c = new CheckBoxListPoker ();
412 ListItem l1 = new ListItem ("item1", "value1");
413 ListItem l2 = new ListItem ("item2", "value2");
414 Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount#1");
417 Assert.AreEqual (2, c.RepeatedItemCount, "RepeatedItemCount#2");
423 public void CleanProperties ()
425 CheckBoxList c = new CheckBoxList ();
427 c.CellPadding = Int32.MaxValue;
428 Assert.AreEqual (c.CellPadding, Int32.MaxValue, "A1");
430 c.CellSpacing = Int32.MaxValue;
431 Assert.AreEqual (c.CellSpacing, Int32.MaxValue, "A2");
433 c.RepeatColumns = Int32.MaxValue;
434 Assert.AreEqual (c.RepeatColumns, Int32.MaxValue, "A3");
436 foreach (RepeatDirection d in
437 Enum.GetValues (typeof (RepeatDirection))) {
438 c.RepeatDirection = d;
439 Assert.AreEqual (c.RepeatDirection, d, "A4-" + d);
442 foreach (RepeatLayout l in
443 Enum.GetValues (typeof (RepeatLayout))) {
445 Assert.AreEqual (c.RepeatLayout, l, "A5-" + l);
450 [ExpectedException (typeof (ArgumentOutOfRangeException))]
451 public void CellPaddingTooLow ()
453 CheckBoxList c = new CheckBoxList ();
458 [ExpectedException (typeof (ArgumentOutOfRangeException))]
459 public void CellSpacingTooLow ()
461 CheckBoxList c = new CheckBoxList ();
466 [ExpectedException (typeof (ArgumentOutOfRangeException))]
467 public void RepeatColumsTooLow ()
469 CheckBoxList c = new CheckBoxList ();
470 c.RepeatColumns = -1;
474 [ExpectedException (typeof (ArgumentOutOfRangeException))]
475 public void RepeatDirection_Invalid ()
477 CheckBoxList c = new CheckBoxList ();
478 c.RepeatDirection = (RepeatDirection) Int32.MaxValue;
482 [ExpectedException (typeof (ArgumentOutOfRangeException))]
483 public void RepeatLayout_Invalid ()
485 CheckBoxList c = new CheckBoxList ();
486 c.RepeatLayout = (RepeatLayout) Int32.MaxValue;
490 [ExpectedException (typeof (ArgumentOutOfRangeException))]
491 public void TextAlign_Invalid ()
493 CheckBoxList c = new CheckBoxList ();
494 c.TextAlign = (TextAlign) Int32.MaxValue;
498 public void ChildCheckBoxControl ()
500 CheckBoxList c = new CheckBoxList ();
501 Assert.AreEqual (c.Controls.Count, 1, "A1");
502 Assert.AreEqual (c.Controls [0].GetType (), typeof (CheckBox), "A2");
506 public void CreateStyle ()
508 CheckBoxListPoker c = new CheckBoxListPoker ();
509 Assert.AreEqual (c.CreateStyle ().GetType (), typeof (TableStyle), "A1");
513 public void RepeatInfoProperties ()
515 IRepeatInfoUser ri = new CheckBoxList ();
517 Assert.IsFalse (ri.HasFooter, "A1");
518 Assert.IsFalse (ri.HasHeader, "A2");
519 Assert.IsFalse (ri.HasSeparators, "A3");
520 Assert.AreEqual (ri.RepeatedItemCount, 0, "A4");
524 public void RepeatInfoCount ()
526 CheckBoxList c = new CheckBoxList ();
527 IRepeatInfoUser ri = (IRepeatInfoUser) c;
529 Assert.AreEqual (ri.RepeatedItemCount, 0, "A1");
533 c.Items.Add ("three");
534 Assert.AreEqual (ri.RepeatedItemCount, 3, "A2");
538 public void RepeatInfoStyle ()
540 IRepeatInfoUser ri = new CheckBoxList ();
542 foreach (ListItemType t in Enum.GetValues (typeof (ListItemType))) {
543 Assert.AreEqual (ri.GetItemStyle (t, 0), null, "A1-" + t);
544 Assert.AreEqual (ri.GetItemStyle (t, 1), null, "A2-" + t);
545 Assert.AreEqual (ri.GetItemStyle (t, 2), null, "A3-" + t);
546 Assert.AreEqual (ri.GetItemStyle (t, 3), null, "A4-" + t);
551 [ExpectedException (typeof (ArgumentOutOfRangeException))]
552 public void RepeatInfoRenderOutOfRange ()
554 StringWriter sw = new StringWriter ();
555 HtmlTextWriter tw = new HtmlTextWriter (sw);
556 IRepeatInfoUser ri = new CheckBoxList ();
558 ri.RenderItem (ListItemType.Item, -1, new RepeatInfo (), tw);
562 public void RepeatInfoRenderItem ()
565 string origHtml = "<input id=\"0\" type=\"checkbox\" name=\"0\" value=\"one\" /><label for=\"0\">one</label>";
567 string origHtml = "<input id=\"0\" type=\"checkbox\" name=\"0\" /><label for=\"0\">one</label>";
569 StringWriter sw = new StringWriter ();
570 HtmlTextWriter tw = new HtmlTextWriter (sw);
571 CheckBoxList c = new CheckBoxList ();
572 IRepeatInfoUser ri = (IRepeatInfoUser) c;
573 RepeatInfo r = new RepeatInfo ();
578 ri.RenderItem (ListItemType.Item, 0, r, tw);
579 string html = sw.ToString ();
580 Assert.AreEqual (origHtml, html, "A1");
584 public void FindControl ()
586 CheckBoxListPoker p = new CheckBoxListPoker ();
591 p.Items.Add ("three");
593 // Everything seems to return this.
594 Assert.AreEqual (p.FindControlPoke (String.Empty, 0), p, "A1");
595 Assert.AreEqual (p.FindControlPoke ("id", 0), p, "A2");
596 Assert.AreEqual (p.FindControlPoke ("id_0", 0), p, "A3");
597 Assert.AreEqual (p.FindControlPoke ("id_1", 0), p, "A4");
598 Assert.AreEqual (p.FindControlPoke ("id_2", 0), p, "A5");
599 Assert.AreEqual (p.FindControlPoke ("id_3", 0), p, "A6");
600 Assert.AreEqual (p.FindControlPoke ("0", 0), p, "A7");
602 Assert.AreEqual (p.FindControlPoke (String.Empty, 10), p, "A1");
603 Assert.AreEqual (p.FindControlPoke ("id", 10), p, "A2");
604 Assert.AreEqual (p.FindControlPoke ("id_0", 10), p, "A3");
605 Assert.AreEqual (p.FindControlPoke ("id_1", 10), p, "A4");
606 Assert.AreEqual (p.FindControlPoke ("id_2", 10), p, "A5");
607 Assert.AreEqual (p.FindControlPoke ("id_3", 10), p, "A6");
608 Assert.AreEqual (p.FindControlPoke ("0", 10), p, "A7");
611 private void Render (CheckBoxList list, string expected, string test)
613 StringWriter sw = new StringWriter ();
614 HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
617 list.RenderControl (tw);
618 HtmlDiff.AssertAreEqual (expected, sw.ToString (), test);
622 public void RenderEmpty ()
624 CheckBoxList c = new CheckBoxList ();
626 Render (c, "", "A1");
628 Render (c, "", "A2");
630 c = new CheckBoxList ();
632 Render (c, "", "A3");
634 c = new CheckBoxList ();
635 c.TextAlign = TextAlign.Left;
636 Render (c, "", "A4");
640 [Category("NotDotNet")] // MS's implementation throws NRE's from these
641 public void Render ()
644 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>";
645 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>";
647 string origHtml1 = "<table border=\"0\">\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" /><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
648 string origHtml2 = "<table border=\"0\">\n\t<tr>\n\t\t<td><input id=\"0\" name=\"0\" type=\"checkbox\" /><label for=\"0\">foo</label></td>\n\t</tr>\n</table>";
651 c = new CheckBoxList ();
654 Render (c, origHtml1, "A5");
656 c = new CheckBoxList ();
658 Render (c, origHtml2, "A6");
663 [Category("NotDotNet")] // MS's implementation throws NRE's from these
664 public void TestTabIndex ()
666 CheckBoxList c = new CheckBoxList ();
668 c.Items.Add ("Item1");
670 string exp = @"<table>
672 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></td>
676 string exp = @"<table border=""0"">
678 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" /><label for=""0"">Item1</label></td>
682 Render (c, exp, "B1");
687 [Category("NotDotNet")] // MS's implementation throws NRE's from these
688 public void TestDisabled ()
690 CheckBoxList c = new CheckBoxList ();
692 c.Items.Add ("Item1");
694 string exp = @"<table class=""aspNetDisabled"">
696 <td><span class=""aspNetDisabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></span></td>
700 string exp = @"<table border=""0"" disabled=""disabled"">
702 <td><span disabled=""disabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" /><label for=""0"">Item1</label></span></td>
706 Render (c, exp, "C1");
708 class TestCheckBoxList : CheckBoxList
710 public void CallVerifyMultiSelect()
712 base.VerifyMultiSelect();
716 public void VerifyMultiSelectTest()
718 TestCheckBoxList list = new TestCheckBoxList();
719 list.CallVerifyMultiSelect();
721 [TestFixtureTearDown]
722 public void teardown ()