File: CheckBoxListTest.cs

package info (click to toggle)
mono 2.6.7-5.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 327,344 kB
  • ctags: 413,649
  • sloc: cs: 2,471,883; xml: 1,768,594; ansic: 350,665; sh: 13,644; makefile: 8,640; perl: 1,784; asm: 717; cpp: 209; python: 146; sql: 81; sed: 16
file content (808 lines) | stat: -rw-r--r-- 25,322 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
//
// Tests for System.Web.UI.WebControls.CheckBoxList.cs 
//
// Author:
//	Jackson Harper (jackson@ximian.com)
//

//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using NUnit.Framework;
using System;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Collections;
using MonoTests.SystemWeb.Framework;
using MonoTests.stand_alone.WebHarness;
using System.Collections.Specialized;

namespace MonoTests.System.Web.UI.WebControls {

	public class CheckBoxListPoker : CheckBoxList {

		public Style CreateStyle ()
		{
			return CreateControlStyle ();
		}

		public Control FindControlPoke (string name, int offset)
		{
			return FindControl (name, offset);
		}

		public string Render ()
		{
			HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
			base.Render (writer);
			return writer.InnerWriter.ToString ();
		}

		
#if NET_2_0
		public new bool HasFooter
		{
			get
			{
				return base.HasFooter;
			}
		}

		public new bool HasHeader
		{
			get
			{
				return base.HasHeader;
			}
		}

		public new bool HasSeparators
		{
			get
			{
				return base.HasSeparators;
			}
		}

		public new int RepeatedItemCount
		{
			get
			{
				return base.RepeatedItemCount;
			}
		}

		public new void RaisePostDataChangedEvent ()
		{
			base.RaisePostDataChangedEvent ();
		}

		protected override Style GetItemStyle (ListItemType itemType, int repeatIndex)
		{
			Style s = new Style();
			s.BackColor = Color.Red;
			s.BorderStyle = BorderStyle.Solid;
			WebTest.CurrentTest.UserData = "GetItemStyle";
			return s;
		}

		public Style DoGetItemStyle (ListItemType itemType, int repeatIndex)
		{
			return base.GetItemStyle (itemType, repeatIndex);
		}

		public new string RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo)
		{
			HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
			base.RenderItem(itemType,repeatIndex,repeatInfo,writer);
			return writer.InnerWriter.ToString ();
		}
#endif
	}

	[TestFixture]
	public class CheckBoxListTest
	{
		[TestFixtureSetUp]
		public void SetUp ()
		{
			Type t = GetType ();
			WebTest.CopyResource (t, "CheckBoxList_Bug377703_1.aspx", "CheckBoxList_Bug377703_1.aspx");
			WebTest.CopyResource (t, "CheckBoxList_Bug377703_2.aspx", "CheckBoxList_Bug377703_2.aspx");
			WebTest.CopyResource (t, "CheckBoxList_Bug578770.aspx", "CheckBoxList_Bug578770.aspx");
			WebTest.CopyResource (t, "CheckBoxList_Bug600415.aspx", "CheckBoxList_Bug600415.aspx");
		}
		
		[Test]
		public void Defaults ()
		{
			CheckBoxListPoker c = new CheckBoxListPoker ();

			Assert.AreEqual (c.CellPadding, -1, "A1");
			Assert.AreEqual (c.CellSpacing, -1, "A2");
			Assert.AreEqual (c.RepeatColumns, 0, "A3");
			Assert.AreEqual (c.RepeatDirection,
					RepeatDirection.Vertical, "A4");
			Assert.AreEqual (c.RepeatLayout,
					RepeatLayout.Table, "A5");
			Assert.AreEqual (c.TextAlign, TextAlign.Right, "A6");
#if NET_2_0
			Assert.AreEqual (false, c.HasFooter, "HasFooter");
			Assert.AreEqual (false, c.HasHeader, "HasHeader");
			Assert.AreEqual (false, c.HasSeparators, "HasSeparators");
			Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount");
			Assert.AreEqual (null, c.DoGetItemStyle (ListItemType.Item, 0), "GetItemStyle");
#endif
		}

#if NET_2_0
		[Test]
		public void CheckBoxList_Bug377703_1 ()
		{
			WebTest t = new WebTest ("CheckBoxList_Bug377703_1.aspx");
			t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_1_OnInit);
			string origHtmlFirst = @"<table id=""cbxl1"" border=""0"">
	<tr>
		<td><input id=""cbxl1_0"" type=""checkbox"" name=""cbxl1$0"" /><label for=""cbxl1_0"">x</label></td>

	</tr><tr>
		<td><input id=""cbxl1_1"" type=""checkbox"" name=""cbxl1$1"" /><label for=""cbxl1_1"">y</label></td>
	</tr><tr>
		<td><input id=""cbxl1_2"" type=""checkbox"" name=""cbxl1$2"" /><label for=""cbxl1_2"">z</label></td>
	</tr>
</table>";
			string origHtmlSecond = @"<table id=""cbxl1"" border=""0"">
	<tr>
		<td><input id=""cbxl1_0"" type=""checkbox"" name=""cbxl1$0"" checked=""checked"" /><label for=""cbxl1_0"">x</label></td>

	</tr><tr>
		<td><input id=""cbxl1_1"" type=""checkbox"" name=""cbxl1$1"" /><label for=""cbxl1_1"">y</label></td>
	</tr><tr>
		<td><input id=""cbxl1_2"" type=""checkbox"" name=""cbxl1$2"" /><label for=""cbxl1_2"">z</label></td>
	</tr>
</table>";
			string html = t.Run ();
			string listHtml = HtmlDiff.GetControlFromPageHtml (html);

			HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");

			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("cbxl1$0");
			fr.Controls ["cbxl1$0"].Value = "on";

			fr.Controls.Add ("ctl01");
			fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";

			t.Request = fr;
			html = t.Run ();

			fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("cbxl1$0");
			fr.Controls ["cbxl1$0"].Value = "on";

			fr.Controls.Add ("ctl01");
			fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty";

			t.Request = fr;
			html = t.Run ();

			listHtml = HtmlDiff.GetControlFromPageHtml (html);
			HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
		}

		public static void CheckBoxList_Bug377703_1_OnInit (Page p)
		{
			CheckBoxList cbxl1 = p.FindControl ("cbxl1") as CheckBoxList;
			
			cbxl1.DataSource = new[] {
				new { ID = "x", Text = "X" },
				new { ID = "y", Text = "Y" },
				new { ID = "z", Text = "Z" },
			};
			cbxl1.DataValueField = "ID";
			cbxl1.DataTextField = "ID";
			cbxl1.DataBind();
		}

		[Test]
		public void CheckBoxList_Bug377703_2 ()
		{
			WebTest t = new WebTest ("CheckBoxList_Bug377703_2.aspx");
			t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug377703_2_OnInit);
			string origHtmlFirst = @"<table id=""cbxl2"" border=""0"">
	<tr>
		<td><input id=""cbxl2_0"" type=""checkbox"" name=""cbxl2$0"" /><label for=""cbxl2_0"">x</label></td>

	</tr><tr>
		<td><input id=""cbxl2_1"" type=""checkbox"" name=""cbxl2$1"" /><label for=""cbxl2_1"">y</label></td>
	</tr><tr>
		<td><input id=""cbxl2_2"" type=""checkbox"" name=""cbxl2$2"" /><label for=""cbxl2_2"">z</label></td>
	</tr>
</table>";
			string origHtmlSecond = @"<table id=""cbxl2"" disabled=""disabled"" border=""0"">
	<tr>
		<td><span disabled=""disabled""><input id=""cbxl2_0"" type=""checkbox"" name=""cbxl2$0"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_0"">x</label></span></td>

	</tr><tr>
		<td><span disabled=""disabled""><input id=""cbxl2_1"" type=""checkbox"" name=""cbxl2$1"" disabled=""disabled"" /><label for=""cbxl2_1"">y</label></span></td>
	</tr><tr>
		<td><span disabled=""disabled""><input id=""cbxl2_2"" type=""checkbox"" name=""cbxl2$2"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_2"">z</label></span></td>
	</tr>
</table>";
			string origHtmlThird = @"<table id=""cbxl2"" disabled=""disabled"" border=""0"">
	<tr>
		<td><span disabled=""disabled""><input id=""cbxl2_0"" type=""checkbox"" name=""cbxl2$0"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_0"">x</label></span></td>

	</tr><tr>
		<td><span disabled=""disabled""><input id=""cbxl2_1"" type=""checkbox"" name=""cbxl2$1"" disabled=""disabled"" /><label for=""cbxl2_1"">y</label></span></td>
	</tr><tr>
		<td><span disabled=""disabled""><input id=""cbxl2_2"" type=""checkbox"" name=""cbxl2$2"" disabled=""disabled"" checked=""checked"" /><label for=""cbxl2_2"">z</label></span></td>
	</tr>
</table>";
			string html = t.Run ();
			string listHtml = HtmlDiff.GetControlFromPageHtml (html);

			HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");

			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("cbxl2$0");
			fr.Controls ["cbxl2$0"].Value = "on";

			fr.Controls.Add ("cbxl2$2");
			fr.Controls ["cbxl2$2"].Value = "on";
			
			fr.Controls.Add ("ctl01");
			fr.Controls ["ctl01"].Value = "Click to toggle enable status above";

			t.Request = fr;
			html = t.Run ();

			listHtml = HtmlDiff.GetControlFromPageHtml (html);

			HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");
			
			fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("ctl02");
			fr.Controls ["ctl02"].Value = "Click to refresh page";

			t.Request = fr;
			html = t.Run ();

			listHtml = HtmlDiff.GetControlFromPageHtml (html);
			HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
		}

		public static void CheckBoxList_Bug377703_2_OnInit (Page p)
		{
			CheckBoxList cbxl2 = p.FindControl ("cbxl2") as CheckBoxList;
			
			cbxl2.DataSource = new[] {
				new { ID = "x", Text = "X" },
				new { ID = "y", Text = "Y" },
				new { ID = "z", Text = "Z" },
			};
			cbxl2.DataValueField = "ID";
			cbxl2.DataTextField = "ID";
			cbxl2.DataBind();
		}

		[Test]
		public void CheckBoxList_Bug578770 ()
		{
			WebTest t = new WebTest ("CheckBoxList_Bug578770.aspx");
			t.Invoker = PageInvoker.CreateOnInit (CheckBoxList_Bug578770_OnInit);
			string origHtml = @"<table id=""test"" border=""0"">

	<tr>
		<td><span disabled=""disabled""><input id=""test_0"" type=""checkbox"" name=""test$0"" disabled=""disabled"" /><label for=""test_0"">Sun</label></span></td>
	</tr><tr>
		<td><input id=""test_1"" type=""checkbox"" name=""test$1"" /><label for=""test_1"">Mon</label></td>
	</tr><tr>
		<td><input id=""test_2"" type=""checkbox"" name=""test$2"" /><label for=""test_2"">Tue</label></td>
	</tr><tr>

		<td><input id=""test_3"" type=""checkbox"" name=""test$3"" /><label for=""test_3"">Wed</label></td>
	</tr><tr>
		<td><input id=""test_4"" type=""checkbox"" name=""test$4"" /><label for=""test_4"">Thu</label></td>
	</tr><tr>
		<td><input id=""test_5"" type=""checkbox"" name=""test$5"" /><label for=""test_5"">Fri</label></td>
	</tr><tr>
		<td><input id=""test_6"" type=""checkbox"" name=""test$6"" /><label for=""test_6"">Sat</label></td>

	</tr>
</table>";
			string html = t.Run ();
			string listHtml = HtmlDiff.GetControlFromPageHtml (html);

			HtmlDiff.AssertAreEqual (origHtml, listHtml, "#A1");
		}

		public static void CheckBoxList_Bug578770_OnInit (Page p)
		{
			CheckBoxList test = p.FindControl ("test") as CheckBoxList;
			string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
			test.DataSource = weekDays;
			test.DataBind();
			test.Items[0].Enabled = false;
		}

		[Test]
		public void CheckBoxList_Bug600415 ()
		{
			WebTest t = new WebTest ("CheckBoxList_Bug600415.aspx");
			string origHtmlFirst = @"<table id=""checkBoxList"" border=""0"">
	<tr>

		<td><input id=""checkBoxList_0"" type=""checkbox"" name=""checkBoxList$0"" checked=""checked"" /><label for=""checkBoxList_0"">Item 1</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_1"" type=""checkbox"" name=""checkBoxList$1"" /><label for=""checkBoxList_1"">Item 2</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_2"" type=""checkbox"" name=""checkBoxList$2"" checked=""checked"" /><label for=""checkBoxList_2"">Item 3</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_3"" type=""checkbox"" name=""checkBoxList$3"" /><label for=""checkBoxList_3"">Item 4</label></td>

	</tr>
</table>";
			string origHtmlSecond = @"<table id=""checkBoxList"" border=""0"">
	<tr>

		<td><input id=""checkBoxList_0"" type=""checkbox"" name=""checkBoxList$0"" /><label for=""checkBoxList_0"">Item 1</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_1"" type=""checkbox"" name=""checkBoxList$1"" /><label for=""checkBoxList_1"">Item 2</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_2"" type=""checkbox"" name=""checkBoxList$2"" /><label for=""checkBoxList_2"">Item 3</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_3"" type=""checkbox"" name=""checkBoxList$3"" /><label for=""checkBoxList_3"">Item 4</label></td>

	</tr>
</table>";
			string origHtmlThird = @"<table id=""checkBoxList"" border=""0"">
	<tr>

		<td><input id=""checkBoxList_0"" type=""checkbox"" name=""checkBoxList$0"" checked=""checked"" /><label for=""checkBoxList_0"">Item 1</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_1"" type=""checkbox"" name=""checkBoxList$1"" checked=""checked"" /><label for=""checkBoxList_1"">Item 2</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_2"" type=""checkbox"" name=""checkBoxList$2"" checked=""checked"" /><label for=""checkBoxList_2"">Item 3</label></td>
	</tr><tr>
		<td><input id=""checkBoxList_3"" type=""checkbox"" name=""checkBoxList$3"" checked=""checked"" /><label for=""checkBoxList_3"">Item 4</label></td>

	</tr>
</table>";
			string html = t.Run ();
			string listHtml = HtmlDiff.GetControlFromPageHtml (html);

			HtmlDiff.AssertAreEqual (origHtmlFirst, listHtml, "#A1");

			FormRequest fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("cmdClick");
			fr.Controls ["cmdClick"].Value = "Ok";

			t.Request = fr;
			html = t.Run ();
			
			listHtml = HtmlDiff.GetControlFromPageHtml (html);
			HtmlDiff.AssertAreEqual (origHtmlSecond, listHtml, "#A2");

			fr = new FormRequest (t.Response, "form1");
			fr.Controls.Add ("checkBoxList$0");
			fr.Controls ["checkBoxList$0"].Value = "on";
			fr.Controls.Add ("checkBoxList$1");
			fr.Controls ["checkBoxList$1"].Value = "on";
			fr.Controls.Add ("checkBoxList$2");
			fr.Controls ["checkBoxList$2"].Value = "on";
			fr.Controls.Add ("checkBoxList$3");
			fr.Controls ["checkBoxList$3"].Value = "on";

			t.Request = fr;
			html = t.Run ();
			listHtml = HtmlDiff.GetControlFromPageHtml (html);
			HtmlDiff.AssertAreEqual (origHtmlThird, listHtml, "#A3");
		}
		
		[Test]
		public void RaisePostDataChangedEvent ()
		{
			CheckBoxListPoker c = new CheckBoxListPoker ();
			c.SelectedIndexChanged += new EventHandler (c_SelectedIndexChanged);
			Assert.AreEqual (false, eventSelectedIndexChanged, "RaisePostDataChangedEvent#1");
			c.RaisePostDataChangedEvent ();
			Assert.AreEqual (true, eventSelectedIndexChanged, "RaisePostDataChangedEvent#2");
		}

		bool eventSelectedIndexChanged;
		void c_SelectedIndexChanged (object sender, EventArgs e)
		{
			eventSelectedIndexChanged = true;
		}

		[Test]
		[Category("NunitWeb")]
		public void GetItemStyle ()
		{
			WebTest t = new WebTest (PageInvoker.CreateOnLoad (GetItemStyle_Load));
			string html = t.Run ();
			string ctrl = HtmlDiff.GetControlFromPageHtml (html);
			if (ctrl == string.Empty)
				Assert.Fail ("CheckBoxList not created fail");
			Assert.AreEqual ("GetItemStyle", (string) t.UserData, "GetItemStyle not done");
			if ( ctrl.IndexOf("<td style=\"background-color:Red;border-style:Solid;\">") == -1)
				Assert.Fail ("CheckBoxList style not rendered");
		}

		public static void GetItemStyle_Load (Page p)
		{
			CheckBoxListPoker c = new CheckBoxListPoker ();
			ListItem l1 = new ListItem ("item1", "value1");
			ListItem l2 = new ListItem ("item2", "value2");

			c.Items.Add (l1);
			c.Items.Add (l2);
			p.Form.Controls.Add(new LiteralControl(HtmlDiff.BEGIN_TAG));
			p.Form.Controls.Add (c);
			p.Form.Controls.Add(new LiteralControl(HtmlDiff.END_TAG));
		}

		[Test]
		public void RenderItem ()
		{
			CheckBoxListPoker c = new CheckBoxListPoker ();
			ListItem l1 = new ListItem ("item1", "value1");
			ListItem l2 = new ListItem ("item2", "value2");

			c.Items.Add (l1);
			c.Items.Add (l2);
			string html = c.RenderItem (ListItemType.Item, 0, null);
			HtmlDiff.AssertAreEqual ("<input id=\"0\" type=\"checkbox\" name=\"0\" /><label for=\"0\">item1</label>", html, "RenderItem#1");
			html = c.RenderItem (ListItemType.Item, 1, null);
			HtmlDiff.AssertAreEqual ("<input id=\"1\" type=\"checkbox\" name=\"1\" /><label for=\"1\">item2</label>", html, "RenderItem#2");
		}

		[Test]
		public void RepeatedItemCount ()
		{
			CheckBoxListPoker c = new CheckBoxListPoker ();
			ListItem l1 = new ListItem ("item1", "value1");
			ListItem l2 = new ListItem ("item2", "value2");
			Assert.AreEqual (0, c.RepeatedItemCount, "RepeatedItemCount#1");
			c.Items.Add (l1);
			c.Items.Add (l2);
			Assert.AreEqual (2, c.RepeatedItemCount, "RepeatedItemCount#2");
		}

#endif


		[Test]
		public void CleanProperties ()
		{
			CheckBoxList c = new CheckBoxList ();

			c.CellPadding = Int32.MaxValue;
			Assert.AreEqual (c.CellPadding, Int32.MaxValue, "A1");

			c.CellSpacing = Int32.MaxValue;
			Assert.AreEqual (c.CellSpacing, Int32.MaxValue, "A2");

			c.RepeatColumns = Int32.MaxValue;
			Assert.AreEqual (c.RepeatColumns, Int32.MaxValue, "A3");

			foreach (RepeatDirection d in
					Enum.GetValues (typeof (RepeatDirection))) {
				c.RepeatDirection = d;
				Assert.AreEqual (c.RepeatDirection, d, "A4-" + d);
			}

			foreach (RepeatLayout l in
					Enum.GetValues (typeof (RepeatLayout))) {
				c.RepeatLayout = l;
				Assert.AreEqual (c.RepeatLayout, l, "A5-" + l);
			}
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void CellPaddingTooLow ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.CellPadding = -2;
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void CellSpacingTooLow ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.CellSpacing = -2;
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void RepeatColumsTooLow ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.RepeatColumns = -1;
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void RepeatDirection_Invalid ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.RepeatDirection = (RepeatDirection) Int32.MaxValue;
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void RepeatLayout_Invalid ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.RepeatLayout = (RepeatLayout) Int32.MaxValue;
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void TextAlign_Invalid ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.TextAlign = (TextAlign) Int32.MaxValue;
		}

		[Test]
		public void ChildCheckBoxControl ()
		{
			CheckBoxList c = new CheckBoxList ();
			Assert.AreEqual (c.Controls.Count, 1, "A1");
			Assert.AreEqual (c.Controls [0].GetType (), typeof (CheckBox), "A2");
		}

		[Test]
		public void CreateStyle ()
		{
			CheckBoxListPoker c = new CheckBoxListPoker ();
			Assert.AreEqual (c.CreateStyle ().GetType (), typeof (TableStyle), "A1");
		}

		[Test]
		public void RepeatInfoProperties ()
		{
			IRepeatInfoUser ri = new CheckBoxList ();

			Assert.IsFalse (ri.HasFooter, "A1");
			Assert.IsFalse (ri.HasHeader, "A2");
			Assert.IsFalse (ri.HasSeparators, "A3");
			Assert.AreEqual (ri.RepeatedItemCount, 0, "A4");
		}

		[Test]
		public void RepeatInfoCount ()
		{
			CheckBoxList c = new CheckBoxList ();
			IRepeatInfoUser ri = (IRepeatInfoUser) c;

			Assert.AreEqual (ri.RepeatedItemCount, 0, "A1");

			c.Items.Add ("one");
			c.Items.Add ("two");
			c.Items.Add ("three");
			Assert.AreEqual (ri.RepeatedItemCount, 3, "A2");
		}

		[Test]
		public void RepeatInfoStyle ()
		{
			IRepeatInfoUser ri = new CheckBoxList ();

			foreach (ListItemType t in Enum.GetValues (typeof (ListItemType))) {
				Assert.AreEqual (ri.GetItemStyle (t, 0), null, "A1-" + t);
				Assert.AreEqual (ri.GetItemStyle (t, 1), null, "A2-" + t);
				Assert.AreEqual (ri.GetItemStyle (t, 2), null, "A3-" + t);
				Assert.AreEqual (ri.GetItemStyle (t, 3), null, "A4-" + t);
			}
		}

		[Test]
		[ExpectedException (typeof (ArgumentOutOfRangeException))]
		public void RepeatInfoRenderOutOfRange ()
		{
			StringWriter sw = new StringWriter ();
			HtmlTextWriter tw = new HtmlTextWriter (sw);
			IRepeatInfoUser ri = new CheckBoxList ();

			ri.RenderItem (ListItemType.Item, -1, new RepeatInfo (), tw); 
		}

		[Test]
		public void RepeatInfoRenderItem ()
		{
			StringWriter sw = new StringWriter ();
			HtmlTextWriter tw = new HtmlTextWriter (sw);
			CheckBoxList c = new CheckBoxList ();
			IRepeatInfoUser ri = (IRepeatInfoUser) c;
			RepeatInfo r = new RepeatInfo ();

			c.Items.Add ("one");
			c.Items.Add ("two");

			ri.RenderItem (ListItemType.Item, 0, r, tw); 
			Assert.AreEqual ("<input id=\"0\" type=\"checkbox\" name=\"0\" />" +
					"<label for=\"0\">one</label>", sw.ToString (), "A1");
		}

		[Test]
		public void FindControl ()
		{
			CheckBoxListPoker p = new CheckBoxListPoker ();

			p.ID = "id";
			p.Items.Add ("one");
			p.Items.Add ("two");
			p.Items.Add ("three");

			// Everything seems to return this.
			Assert.AreEqual (p.FindControlPoke (String.Empty, 0), p, "A1");
			Assert.AreEqual (p.FindControlPoke ("id", 0), p, "A2");
			Assert.AreEqual (p.FindControlPoke ("id_0", 0), p, "A3");
			Assert.AreEqual (p.FindControlPoke ("id_1", 0), p, "A4");
			Assert.AreEqual (p.FindControlPoke ("id_2", 0), p, "A5");
			Assert.AreEqual (p.FindControlPoke ("id_3", 0), p, "A6");
			Assert.AreEqual (p.FindControlPoke ("0", 0), p, "A7");

			Assert.AreEqual (p.FindControlPoke (String.Empty, 10), p, "A1");
			Assert.AreEqual (p.FindControlPoke ("id", 10), p, "A2");
			Assert.AreEqual (p.FindControlPoke ("id_0", 10), p, "A3");
			Assert.AreEqual (p.FindControlPoke ("id_1", 10), p, "A4");
			Assert.AreEqual (p.FindControlPoke ("id_2", 10), p, "A5");
			Assert.AreEqual (p.FindControlPoke ("id_3", 10), p, "A6");
			Assert.AreEqual (p.FindControlPoke ("0", 10), p, "A7");
		}

		private void Render (CheckBoxList list, string expected, string test)
		{
			StringWriter sw = new StringWriter ();
			HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
			sw.NewLine = "\n";

			list.RenderControl (tw);
			HtmlDiff.AssertAreEqual (expected, sw.ToString (), test);
		}

		[Test]
		public void RenderEmpty ()
		{
			CheckBoxList c = new CheckBoxList ();

#if NET_2_0
			Render (c, "", "A1");
#else
			Render (c, "<table border=\"0\">\n\n</table>", "A1");
#endif
			c.CellPadding = 1;
#if NET_2_0
			Render (c, "", "A2");
#else
			Render (c, "<table border=\"0\" cellpadding=\"1\">\n\n</table>", "A2");
#endif

			c = new CheckBoxList ();
			c.CellPadding = 1;
#if NET_2_0
			Render (c, "", "A3");
#else
			Render (c, "<table border=\"0\" cellpadding=\"1\">\n\n</table>", "A3");
#endif

			c = new CheckBoxList ();
			c.TextAlign = TextAlign.Left;
#if NET_2_0
			Render (c, "", "A4");
#else
			Render (c, "<table border=\"0\">\n\n</table>", "A4");
#endif
		}

		[Test]
#if NET_2_0
		[Category("NotDotNet")] // MS's implementation throws NRE's from these
#endif
		public void Render ()
		{
			CheckBoxList c;
			c = new CheckBoxList ();
			c.Items.Add ("foo");
			Render (c, "<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>", "A5");

			c = new CheckBoxList ();
			c.Items.Add ("foo");
			Render (c, "<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>", "A6");
		}

		// bug 51648
		[Test]
#if NET_2_0
		[Category("NotDotNet")] // MS's implementation throws NRE's from these
#endif
		public void TestTabIndex ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.TabIndex = 5;
			c.Items.Add ("Item1");
			string exp = @"<table border=""0"">
	<tr>
		<td><input id=""0"" name=""0"" tabindex=""5"" type=""checkbox"" /><label for=""0"">Item1</label></td>
	</tr>
</table>";
			Render (c, exp, "B1");
		}

		// bug 48802
		[Test]
#if NET_2_0
		[Category("NotDotNet")] // MS's implementation throws NRE's from these
#endif
		public void TestDisabled ()
		{
			CheckBoxList c = new CheckBoxList ();
			c.Enabled = false;
			c.Items.Add ("Item1");
			string exp = @"<table border=""0"" disabled=""disabled"">
	<tr>
		<td><span disabled=""disabled""><input disabled=""disabled"" id=""0"" name=""0"" type=""checkbox"" /><label for=""0"">Item1</label></span></td>
	</tr>
</table>";
			Render (c, exp, "C1");
		}	
#if NET_2_0
        class TestCheckBoxList : CheckBoxList
        {
            public new virtual void VerifyMultiSelect()
            {
                base.VerifyMultiSelect();
            }
        }
        [Test]
        public void VerifyMultiSelectTest()
        {
            TestCheckBoxList list = new TestCheckBoxList();
            list.VerifyMultiSelect();
        }
        [TestFixtureTearDown]
		public void teardown ()
		{
			WebTest.Unload ();
		}
#endif
	}
}