2 // TableHeaderCellTest.cs
3 // - Unit tests for System.Web.UI.WebControls.TableHeaderCell
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
34 using System.Web.UI.WebControls;
36 using NUnit.Framework;
38 namespace MonoTests.System.Web.UI.WebControls {
40 public class TestTableHeaderCell : TableHeaderCell {
43 get { return base.TagName; }
46 public StateBag StateBag {
47 get { return base.ViewState; }
50 public string Render ()
52 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
54 return writer.InnerWriter.ToString ();
59 public class TableHeaderCellTest {
62 public void DefaultProperties ()
64 TestTableHeaderCell th = new TestTableHeaderCell ();
65 Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
66 Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count");
68 Assert.AreEqual (String.Empty, th.AbbreviatedText, "AbbreviatedText");
69 Assert.AreEqual (0, th.CategoryText.Length, "CategoryText");
70 Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "Scope");
72 Assert.AreEqual ("th", th.Tag, "TagName");
73 Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count-2");
74 Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-2");
78 public void NullProperties ()
80 TestTableHeaderCell th = new TestTableHeaderCell ();
82 th.AbbreviatedText = null;
83 Assert.AreEqual (String.Empty, th.AbbreviatedText, "AbbreviatedText");
85 th.CategoryText = new string[0];
86 Assert.AreEqual (0, th.CategoryText.Length, "CategoryText");
87 Assert.AreEqual (1, th.StateBag.Count, "ViewState.Count-1");
89 th.Scope = TableHeaderScope.NotSet;
90 Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "Scope");
91 Assert.AreEqual (2, th.StateBag.Count, "ViewState.Count-2");
93 Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
95 Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
99 public void CleanProperties ()
101 TestTableHeaderCell th = new TestTableHeaderCell ();
103 th.AbbreviatedText = "header";
104 Assert.AreEqual ("header", th.AbbreviatedText, "AbbreviatedText");
105 th.AbbreviatedText = null;
106 Assert.AreEqual (String.Empty, th.AbbreviatedText, "-AbbreviatedText");
107 Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
109 th.CategoryText = new string[1] { "mono" };
110 Assert.AreEqual (1, th.CategoryText.Length, "CategoryText");
111 th.CategoryText = new string[0];
112 Assert.AreEqual (0, th.CategoryText.Length, "-CategoryText");
113 Assert.AreEqual (1, th.StateBag.Count, "ViewState.Count-1");
115 th.Scope = TableHeaderScope.Row;
116 Assert.AreEqual (TableHeaderScope.Row, th.Scope, "Scope");
117 th.Scope = TableHeaderScope.NotSet;
118 Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "-Scope");
119 Assert.AreEqual (2, th.StateBag.Count, "ViewState.Count-2");
121 Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
123 Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
126 private string AdjustLineEndings (string s)
128 return s.Replace ("\r\n", Environment.NewLine);
132 public void Render ()
134 TestTableHeaderCell th = new TestTableHeaderCell ();
135 string s = th.Render ();
136 Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "empty/default");
138 th.AbbreviatedText = "header";
140 Assert.AreEqual (AdjustLineEndings ("<th abbr=\"header\"></th>"), s, "AbbreviatedText");
141 th.AbbreviatedText = null;
143 th.CategoryText = new string[1] { "mono" };
145 Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono\"></th>"), s, "CategoryText-1");
146 th.CategoryText = new string[2] { "mono", "http://www.mono-project.com" };
148 Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono,http://www.mono-project.com\"></th>"), s, "CategoryText-2");
149 th.CategoryText = new string[3] { "mono", "http://www.mono-project.com", "," };
151 Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono,http://www.mono-project.com,,\"></th>"), s, "CategoryText-2");
152 th.CategoryText = new string[0];
154 Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "CategoryText-2");
156 th.Scope = TableHeaderScope.Row;
158 Assert.AreEqual (AdjustLineEndings ("<th scope=\"row\"></th>"), s, "Row");
159 th.Scope = TableHeaderScope.Column;
161 Assert.AreEqual (AdjustLineEndings ("<th scope=\"column\"></th>"), s, "Column");
162 th.Scope = TableHeaderScope.NotSet;
164 Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "NotSet");
168 Assert.AreEqual (AdjustLineEndings ("<th>test</th>"), s, "Text");