Merge pull request #1899 from saper/resgencond
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / CheckBoxListTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.CheckBoxList.cs 
3 //
4 // Author:
5 //      Jackson Harper (jackson@ximian.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.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.Drawing;
39 using System.Collections;
40 using MonoTests.SystemWeb.Framework;
41 using MonoTests.stand_alone.WebHarness;
42 using System.Collections.Specialized;
43
44 namespace MonoTests.System.Web.UI.WebControls {
45
46         public class CheckBoxListPoker : CheckBoxList {
47
48                 public Style CreateStyle ()
49                 {
50                         return CreateControlStyle ();
51                 }
52
53                 public Control FindControlPoke (string name, int offset)
54                 {
55                         return FindControl (name, offset);
56                 }
57
58                 public string Render ()
59                 {
60                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
61                         base.Render (writer);
62                         return writer.InnerWriter.ToString ();
63                 }
64
65                 
66                 public new bool HasFooter
67                 {
68                         get
69                         {
70                                 return base.HasFooter;
71                         }
72                 }
73
74                 public new bool HasHeader
75                 {
76                         get
77                         {
78                                 return base.HasHeader;
79                         }
80                 }
81
82                 public new bool HasSeparators
83                 {
84                         get
85                         {
86                                 return base.HasSeparators;
87                         }
88                 }
89
90                 public new int RepeatedItemCount
91                 {
92                         get
93                         {
94                                 return base.RepeatedItemCount;
95                         }
96                 }
97
98                 public new void RaisePostDataChangedEvent ()
99                 {
100                         base.RaisePostDataChangedEvent ();
101                 }
102
103                 protected override Style GetItemStyle (ListItemType itemType, int repeatIndex)
104                 {
105                         Style s = new Style();
106                         s.BackColor = Color.Red;
107                         s.BorderStyle = BorderStyle.Solid;
108                         WebTest.CurrentTest.UserData = "GetItemStyle";
109                         return s;
110                 }
111
112                 public Style DoGetItemStyle (ListItemType itemType, int repeatIndex)
113                 {
114                         return base.GetItemStyle (itemType, repeatIndex);
115                 }
116
117                 public new string RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo)
118                 {
119                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
120                         base.RenderItem(itemType,repeatIndex,repeatInfo,writer);
121                         return writer.InnerWriter.ToString ();
122                 }
123         }
124
125         [TestFixture]
126         public class CheckBoxListTest
127         {
128                 [TestFixtureSetUp]
129                 public void SetUp ()
130                 {
131                         Type t = GetType ();
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");
136                 }
137                 
138                 [Test]
139                 public void Defaults ()
140                 {
141                         CheckBoxListPoker c = new CheckBoxListPoker ();
142
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");
156                 }
157
158                 [Test]
159                 public void CheckBoxList_Bug377703_1 ()
160                 {
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);
167
168                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
169
170                         FormRequest fr = new FormRequest (t.Response, "form1");
171                         fr.Controls.Add ("cbxl1$0");
172                         fr.Controls ["cbxl1$0"].Value = "on";
173
174                         fr.Controls.Add ("ctl01");
175                         fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
176
177                         t.Request = fr;
178                         html = t.Run ();
179
180                         fr = new FormRequest (t.Response, "form1");
181                         fr.Controls.Add ("cbxl1$0");
182                         fr.Controls ["cbxl1$0"].Value = "on";
183
184                         fr.Controls.Add ("ctl01");
185                         fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";
186
187                         t.Request = fr;
188                         html = t.Run ();
189
190                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
191                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
192                 }
193
194                 public static void CheckBoxList_Bug377703_1_OnInit (Page p)
195                 {
196                         CheckBoxList cbxl1 = p.FindControl ("cbxl1") as CheckBoxList;
197                         
198                         cbxl1.DataSource = new[] {
199                                 new { ID = "x", Text = "X" },
200                                 new { ID = "y", Text = "Y" },
201                                 new { ID = "z", Text = "Z" },
202                         };
203                         cbxl1.DataValueField = "ID";
204                         cbxl1.DataTextField = "ID";
205                         cbxl1.DataBind();
206                 }
207
208                 [Test]
209                 public void CheckBoxList_Bug377703_2 ()
210                 {
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);
218
219                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
220
221                         FormRequest fr = new FormRequest (t.Response, "form1");
222                         fr.Controls.Add ("cbxl2$0");
223                         fr.Controls ["cbxl2$0"].Value = "on";
224
225                         fr.Controls.Add ("cbxl2$2");
226                         fr.Controls ["cbxl2$2"].Value = "on";
227                         
228                         fr.Controls.Add ("ctl01");
229                         fr.Controls ["ctl01"].Value = "Click to toggle enable status above";
230
231                         t.Request = fr;
232                         html = t.Run ();
233
234                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
235
236                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
237                         
238                         fr = new FormRequest (t.Response, "form1");
239                         fr.Controls.Add ("ctl02");
240                         fr.Controls ["ctl02"].Value = "Click to refresh page";
241
242                         t.Request = fr;
243                         html = t.Run ();
244
245                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
246                         HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
247                 }
248
249                 public static void CheckBoxList_Bug377703_2_OnInit (Page p)
250                 {
251                         CheckBoxList cbxl2 = p.FindControl ("cbxl2") as CheckBoxList;
252                         
253                         cbxl2.DataSource = new[] {
254                                 new { ID = "x", Text = "X" },
255                                 new { ID = "y", Text = "Y" },
256                                 new { ID = "z", Text = "Z" },
257                         };
258                         cbxl2.DataValueField = "ID";
259                         cbxl2.DataTextField = "ID";
260                         cbxl2.DataBind();
261                 }
262
263                 [Test]
264                 public void CheckBoxList_Bug578770 ()
265                 {
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);
271
272                         HtmlDiff.AssertAreEqual (origHtml, listHtml, "#A1");
273                 }
274
275                 public static void CheckBoxList_Bug578770_OnInit (Page p)
276                 {
277                         CheckBoxList test = p.FindControl ("test") as CheckBoxList;
278                         string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
279                         test.DataSource = weekDays;
280                         test.DataBind();
281                         test.Items[0].Enabled = false;
282                 }
283
284                 [Test]
285                 public void CheckBoxList_Bug600415 ()
286                 {
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);
293
294                         HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");
295
296                         FormRequest fr = new FormRequest (t.Response, "form1");
297                         fr.Controls.Add ("cmdClick");
298                         fr.Controls ["cmdClick"].Value = "Ok";
299
300                         t.Request = fr;
301                         html = t.Run ();
302                         
303                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
304                         HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
305
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";
315
316                         t.Request = fr;
317                         html = t.Run ();
318                         listHtml = HtmlDiff.GetControlFromPageHtml (html);
319                         HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
320                 }
321                 
322                 [Test]
323                 public void RaisePostDataChangedEvent ()
324                 {
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");
330                 }
331
332                 bool eventSelectedIndexChanged;
333                 void c_SelectedIndexChanged (object sender, EventArgs e)
334                 {
335                         eventSelectedIndexChanged = true;
336                 }
337
338                 [Test]
339                 [Category("NunitWeb")]
340                 public void GetItemStyle ()
341                 {
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");
350                 }
351
352                 public static void GetItemStyle_Load (Page p)
353                 {
354                         CheckBoxListPoker c = new CheckBoxListPoker ();
355                         ListItem l1 = new ListItem ("item1", "value1");
356                         ListItem l2 = new ListItem ("item2", "value2");
357
358                         c.Items.Add (l1);
359                         c.Items.Add (l2);
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));
363                 }
364
365                 [Test]
366                 public void RenderItem ()
367                 {
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");
373
374                         c.Items.Add (l1);
375                         c.Items.Add (l2);
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");
380                 }
381
382                 [Test]
383                 public void RepeatedItemCount ()
384                 {
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");
389                         c.Items.Add (l1);
390                         c.Items.Add (l2);
391                         Assert.AreEqual (2, c.RepeatedItemCount, "RepeatedItemCount#2");
392                 }
393
394
395
396                 [Test]
397                 public void CleanProperties ()
398                 {
399                         CheckBoxList c = new CheckBoxList ();
400
401                         c.CellPadding = Int32.MaxValue;
402                         Assert.AreEqual (c.CellPadding, Int32.MaxValue, "A1");
403
404                         c.CellSpacing = Int32.MaxValue;
405                         Assert.AreEqual (c.CellSpacing, Int32.MaxValue, "A2");
406
407                         c.RepeatColumns = Int32.MaxValue;
408                         Assert.AreEqual (c.RepeatColumns, Int32.MaxValue, "A3");
409
410                         foreach (RepeatDirection d in
411                                         Enum.GetValues (typeof (RepeatDirection))) {
412                                 c.RepeatDirection = d;
413                                 Assert.AreEqual (c.RepeatDirection, d, "A4-" + d);
414                         }
415
416                         foreach (RepeatLayout l in
417                                         Enum.GetValues (typeof (RepeatLayout))) {
418                                 c.RepeatLayout = l;
419                                 Assert.AreEqual (c.RepeatLayout, l, "A5-" + l);
420                         }
421                 }
422
423                 [Test]
424                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
425                 public void CellPaddingTooLow ()
426                 {
427                         CheckBoxList c = new CheckBoxList ();
428                         c.CellPadding = -2;
429                 }
430
431                 [Test]
432                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
433                 public void CellSpacingTooLow ()
434                 {
435                         CheckBoxList c = new CheckBoxList ();
436                         c.CellSpacing = -2;
437                 }
438
439                 [Test]
440                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
441                 public void RepeatColumsTooLow ()
442                 {
443                         CheckBoxList c = new CheckBoxList ();
444                         c.RepeatColumns = -1;
445                 }
446
447                 [Test]
448                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
449                 public void RepeatDirection_Invalid ()
450                 {
451                         CheckBoxList c = new CheckBoxList ();
452                         c.RepeatDirection = (RepeatDirection) Int32.MaxValue;
453                 }
454
455                 [Test]
456                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
457                 public void RepeatLayout_Invalid ()
458                 {
459                         CheckBoxList c = new CheckBoxList ();
460                         c.RepeatLayout = (RepeatLayout) Int32.MaxValue;
461                 }
462
463                 [Test]
464                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
465                 public void TextAlign_Invalid ()
466                 {
467                         CheckBoxList c = new CheckBoxList ();
468                         c.TextAlign = (TextAlign) Int32.MaxValue;
469                 }
470
471                 [Test]
472                 public void ChildCheckBoxControl ()
473                 {
474                         CheckBoxList c = new CheckBoxList ();
475                         Assert.AreEqual (c.Controls.Count, 1, "A1");
476                         Assert.AreEqual (c.Controls [0].GetType (), typeof (CheckBox), "A2");
477                 }
478
479                 [Test]
480                 public void CreateStyle ()
481                 {
482                         CheckBoxListPoker c = new CheckBoxListPoker ();
483                         Assert.AreEqual (c.CreateStyle ().GetType (), typeof (TableStyle), "A1");
484                 }
485
486                 [Test]
487                 public void RepeatInfoProperties ()
488                 {
489                         IRepeatInfoUser ri = new CheckBoxList ();
490
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");
495                 }
496
497                 [Test]
498                 public void RepeatInfoCount ()
499                 {
500                         CheckBoxList c = new CheckBoxList ();
501                         IRepeatInfoUser ri = (IRepeatInfoUser) c;
502
503                         Assert.AreEqual (ri.RepeatedItemCount, 0, "A1");
504
505                         c.Items.Add ("one");
506                         c.Items.Add ("two");
507                         c.Items.Add ("three");
508                         Assert.AreEqual (ri.RepeatedItemCount, 3, "A2");
509                 }
510
511                 [Test]
512                 public void RepeatInfoStyle ()
513                 {
514                         IRepeatInfoUser ri = new CheckBoxList ();
515
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);
521                         }
522                 }
523
524                 [Test]
525                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
526                 public void RepeatInfoRenderOutOfRange ()
527                 {
528                         StringWriter sw = new StringWriter ();
529                         HtmlTextWriter tw = new HtmlTextWriter (sw);
530                         IRepeatInfoUser ri = new CheckBoxList ();
531
532                         ri.RenderItem (ListItemType.Item, -1, new RepeatInfo (), tw); 
533                 }
534
535                 [Test]
536                 public void RepeatInfoRenderItem ()
537                 {
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 ();
544
545                         c.Items.Add ("one");
546                         c.Items.Add ("two");
547
548                         ri.RenderItem (ListItemType.Item, 0, r, tw);
549                         string html = sw.ToString ();
550                         Assert.AreEqual (origHtml, html, "A1");
551                 }
552
553                 [Test]
554                 public void FindControl ()
555                 {
556                         CheckBoxListPoker p = new CheckBoxListPoker ();
557
558                         p.ID = "id";
559                         p.Items.Add ("one");
560                         p.Items.Add ("two");
561                         p.Items.Add ("three");
562
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");
571
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");
579                 }
580
581                 private void Render (CheckBoxList list, string expected, string test)
582                 {
583                         StringWriter sw = new StringWriter ();
584                         HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
585                         sw.NewLine = "\n";
586
587                         list.RenderControl (tw);
588                         HtmlDiff.AssertAreEqual (expected, sw.ToString (), test);
589                 }
590
591                 [Test]
592                 public void RenderEmpty ()
593                 {
594                         CheckBoxList c = new CheckBoxList ();
595
596                         Render (c, "", "A1");
597                         c.CellPadding = 1;
598                         Render (c, "", "A2");
599
600                         c = new CheckBoxList ();
601                         c.CellPadding = 1;
602                         Render (c, "", "A3");
603
604                         c = new CheckBoxList ();
605                         c.TextAlign = TextAlign.Left;
606                         Render (c, "", "A4");
607                 }
608
609                 [Test]
610                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
611                 public void Render ()
612                 {
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>";
615                         CheckBoxList c;
616                         c = new CheckBoxList ();
617                         c.Items.Add ("foo");
618
619                         Render (c, origHtml1, "A5");
620
621                         c = new CheckBoxList ();
622                         c.Items.Add ("foo");
623                         Render (c, origHtml2, "A6");
624                 }
625
626                 // bug 51648
627                 [Test]
628                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
629                 public void TestTabIndex ()
630                 {
631                         CheckBoxList c = new CheckBoxList ();
632                         c.TabIndex = 5;
633                         c.Items.Add ("Item1");
634                         string exp = @"<table>
635         <tr>
636                 <td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></td>
637         </tr>
638 </table>";
639                         Render (c, exp, "B1");
640                 }
641
642                 // bug 48802
643                 [Test]
644                 [Category("NotDotNet")] // MS's implementation throws NRE's from these
645                 public void TestDisabled ()
646                 {
647                         CheckBoxList c = new CheckBoxList ();
648                         c.Enabled = false;
649                         c.Items.Add ("Item1");
650                         string exp = @"<table class=""aspNetDisabled"">
651         <tr>
652                 <td><span class=""aspNetDisabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" value=""Item1""/><label for=""0"">Item1</label></span></td>
653         </tr>
654 </table>";
655                         Render (c, exp, "C1");
656                 }       
657         class TestCheckBoxList : CheckBoxList
658         {
659             public void CallVerifyMultiSelect()
660             {
661                 base.VerifyMultiSelect();
662             }
663         }
664         [Test]
665         public void VerifyMultiSelectTest()
666         {
667             TestCheckBoxList list = new TestCheckBoxList();
668             list.CallVerifyMultiSelect();
669         }
670         [TestFixtureTearDown]
671                 public void teardown ()
672                 {
673                         WebTest.Unload ();
674                 }
675         }
676 }
677
678