[asp.net] HtmlForum.Name rendering updates + test updates
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.HtmlControls / HtmlInputCheckBoxTest.cs
1 //
2 // HtmlInputCheckBoxTest.cs
3 //      - Unit tests for System.Web.UI.HtmlControls.HtmlInputCheckBox
4 //
5 // Author:
6 //      Dick Porter  <dick@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.IO;
32 using System.Web.UI;
33 using System.Web.UI.HtmlControls;
34 using MonoTests.stand_alone.WebHarness;
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Web.UI.HtmlControls {
38         public class TestHtmlInputCheckBox : HtmlInputCheckBox {
39                 public string Render ()
40                 {
41                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
42                         base.Render (writer);
43                         return writer.InnerWriter.ToString ();
44                 }
45         }
46
47         [TestFixture]
48         public class HtmlInputCheckBoxTest {
49
50                 [Test]
51                 public void DefaultProperties ()
52                 {
53                         HtmlInputCheckBox c = new HtmlInputCheckBox ();
54                 
55                         Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count");
56
57                         Assert.IsFalse (c.Checked, "Checked");
58                         
59                         Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count after");
60                 }
61
62                 [Test]
63                 public void NullProperties ()
64                 {
65                         HtmlInputCheckBox c = new HtmlInputCheckBox ();
66                         
67                         Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count");
68                         Assert.AreEqual ("checkbox", c.Attributes["type"], "Attributes[\"type\"]");
69                         
70                         c.Checked = true;
71                         Assert.IsTrue (c.Checked, "Checked");
72                         
73                         Assert.AreEqual (2, c.Attributes.Count, "Attributes.Count after");
74                         Assert.AreEqual ("checked", c.Attributes["checked"], "Attributes[\"checked\"]");
75                 }
76
77                 [Test]
78                 public void CleanProperties ()
79                 {
80                         HtmlInputCheckBox c = new HtmlInputCheckBox ();
81
82                         c.Checked = true;
83                         Assert.AreEqual (2, c.Attributes.Count, "Attributes.Count");
84
85                         c.Checked = false;
86                         Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count after");
87                 }
88
89                 [Test] 
90                 public void Render ()
91                 {
92                         TestHtmlInputCheckBox c = new TestHtmlInputCheckBox ();
93
94                         c.ID = "*1*";
95                         
96                         string s = c.Render ();
97
98                         Assert.IsTrue (s.IndexOf (" type=\"checkbox\"") > 0, "type");
99
100                         c.Checked = true;
101                         s = c.Render ();
102
103 #if NET_2_0
104                         HtmlDiff.AssertAreEqual ("<input name=\"*1*\" id=\"*1*\" type=\"checkbox\" checked=\"checked\" />", s, "Render fail");
105 #else
106                         HtmlDiff.AssertAreEqual ("<input name=\"*1*\" type=\"checkbox\" id=\"*1*\" checked=\"checked\" />", s, "Render fail");
107 #endif
108                 }
109         }
110 }