3 // - Unit tests for System.Web.UI.HtmlControls.HtmlTableRow
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.
33 using System.Web.UI.HtmlControls;
35 using NUnit.Framework;
37 namespace MonoTests.System.Web.UI.HtmlControls {
39 public class TestHtmlTableRow : HtmlTableRow {
41 public string Render ()
43 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
45 return writer.InnerWriter.ToString ();
48 public ControlCollection GetCollection ()
50 return base.CreateControlCollection ();
54 public class InheritedHtmlTableCell : HtmlTableCell {
58 public class HtmlTableRowTest {
61 public void DefaultProperties ()
63 HtmlTableRow r = new HtmlTableRow ();
64 Assert.AreEqual (0, r.Attributes.Count, "Attributes.Count");
66 Assert.AreEqual (String.Empty, r.Align, "Align");
67 Assert.AreEqual (String.Empty, r.BgColor, "BgColor");
68 Assert.AreEqual (String.Empty, r.BorderColor, "BorderColor");
69 Assert.AreEqual (0, r.Cells.Count, "Cells");
70 Assert.AreEqual (String.Empty, r.Height, "Height");
71 Assert.AreEqual (String.Empty, r.VAlign, "VAlign");
73 Assert.AreEqual ("tr", r.TagName, "TagName");
77 public void NullProperties ()
79 HtmlTableRow r = new HtmlTableRow ();
81 Assert.AreEqual (String.Empty, r.Align, "Align");
83 Assert.AreEqual (String.Empty, r.BgColor, "BgColor");
85 Assert.AreEqual (String.Empty, r.BorderColor, "BorderColor");
87 Assert.AreEqual (String.Empty, r.Height, "Height");
89 Assert.AreEqual (String.Empty, r.VAlign, "VAlign");
91 Assert.AreEqual (0, r.Attributes.Count, "Attributes.Count");
95 public void CleanProperties ()
97 HtmlTableRow r = new HtmlTableRow ();
99 Assert.AreEqual ("center", r.Align, "Align");
100 Assert.AreEqual (1, r.Attributes.Count, "1");
103 Assert.AreEqual (String.Empty, r.Align, "-Align");
104 Assert.AreEqual (0, r.Attributes.Count, "0");
108 [ExpectedException (typeof (NotSupportedException))]
109 public void InnerHtml_Get ()
111 HtmlTableRow r = new HtmlTableRow ();
112 Assert.IsNotNull (r.InnerHtml);
116 [ExpectedException (typeof (NotSupportedException))]
117 public void InnerHtml_Set ()
119 HtmlTableRow r = new HtmlTableRow ();
120 r.InnerHtml = String.Empty;
124 [ExpectedException (typeof (NotSupportedException))]
125 public void InnerText_Get ()
127 HtmlTableRow r = new HtmlTableRow ();
128 Assert.IsNotNull (r.InnerText);
132 [ExpectedException (typeof (NotSupportedException))]
133 public void InnerText_Set ()
135 HtmlTableRow r = new HtmlTableRow ();
136 r.InnerText = String.Empty;
139 private string AdjustLineEndings (string s)
141 return s.Replace ("\r\n", Environment.NewLine);
145 public void Render ()
147 TestHtmlTableRow r = new TestHtmlTableRow ();
150 r.BorderColor = "*3*";
153 Assert.AreEqual (AdjustLineEndings ("<tr align=\"*1*\" bgcolor=\"*2*\" bordercolor=\"*3*\" height=\"*4*\" valign=\"*5*\">\r\n</tr>\r\n"), r.Render ());
157 [ExpectedException (typeof (NullReferenceException))]
158 public void HtmlTableCellControlCollectionAdd_Null ()
160 TestHtmlTableRow t = new TestHtmlTableRow ();
161 ControlCollection c = t.GetCollection ();
166 [ExpectedException (typeof (ArgumentException))]
167 public void HtmlTableCellControlCollectionAdd_WrongType ()
169 TestHtmlTableRow t = new TestHtmlTableRow ();
170 ControlCollection c = t.GetCollection ();
171 c.Add (new HtmlTable ());
175 public void HtmlTableCellControlCollectionAdd ()
177 TestHtmlTableRow t = new TestHtmlTableRow ();
178 ControlCollection c = t.GetCollection ();
179 c.Add (new HtmlTableCell ());
180 c.Add (new InheritedHtmlTableCell ());
181 Assert.AreEqual (2, c.Count, "Cells");
185 [ExpectedException (typeof (NullReferenceException))]
186 public void HtmlTableCellControlCollectionAddAt_Null ()
188 TestHtmlTableRow t = new TestHtmlTableRow ();
189 ControlCollection c = t.GetCollection ();
194 [ExpectedException (typeof (ArgumentException))]
195 public void HtmlTableCellControlCollectionAddAt_WrongType ()
197 TestHtmlTableRow t = new TestHtmlTableRow ();
198 ControlCollection c = t.GetCollection ();
199 c.AddAt (0, new HtmlTable ());
203 public void HtmlTableCellControlCollectionAddAt ()
205 TestHtmlTableRow t = new TestHtmlTableRow ();
206 ControlCollection c = t.GetCollection ();
207 c.AddAt (0, new HtmlTableCell ());
208 c.AddAt (0, new InheritedHtmlTableCell ());
209 Assert.AreEqual (2, c.Count, "Cells");