1 //
2 // HtmlTableRowTest.cs
3 //	- Unit tests for System.Web.UI.HtmlControls.HtmlTableRow
4 //
5 // Author:
6 //	Sebastien Pouliot  <sebastien@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 
35 using NUnit.Framework;
36 
37 namespace MonoTests.System.Web.UI.HtmlControls {
38 
39 	public class TestHtmlTableRow : HtmlTableRow {
40 
Render()41 		public string Render ()
42 		{
43 			HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
44 			base.Render (writer);
45 			return writer.InnerWriter.ToString ();
46 		}
47 
GetCollection()48 		public ControlCollection GetCollection ()
49 		{
50 			return base.CreateControlCollection ();
51 		}
52 	}
53 
54 	public class InheritedHtmlTableCell : HtmlTableCell {
55 	}
56 
57 	[TestFixture]
58 	public class HtmlTableRowTest {
59 
60 		[Test]
DefaultProperties()61 		public void DefaultProperties ()
62 		{
63 			HtmlTableRow r = new HtmlTableRow ();
64 			Assert.AreEqual (0, r.Attributes.Count, "Attributes.Count");
65 
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");
72 
73 			Assert.AreEqual ("tr", r.TagName, "TagName");
74 		}
75 
76 		[Test]
NullProperties()77 		public void NullProperties ()
78 		{
79 			HtmlTableRow r = new HtmlTableRow ();
80 			r.Align = null;
81 			Assert.AreEqual (String.Empty, r.Align, "Align");
82 			r.BgColor = null;
83 			Assert.AreEqual (String.Empty, r.BgColor, "BgColor");
84 			r.BorderColor = null;
85 			Assert.AreEqual (String.Empty, r.BorderColor, "BorderColor");
86 			r.Height = null;
87 			Assert.AreEqual (String.Empty, r.Height, "Height");
88 			r.VAlign = null;
89 			Assert.AreEqual (String.Empty, r.VAlign, "VAlign");
90 
91 			Assert.AreEqual (0, r.Attributes.Count, "Attributes.Count");
92 		}
93 
94 		[Test]
CleanProperties()95 		public void CleanProperties ()
96 		{
97 			HtmlTableRow r = new HtmlTableRow ();
98 			r.Align = "center";
99 			Assert.AreEqual ("center", r.Align, "Align");
100 			Assert.AreEqual (1, r.Attributes.Count, "1");
101 
102 			r.Align = null;
103 			Assert.AreEqual (String.Empty, r.Align, "-Align");
104 			Assert.AreEqual (0, r.Attributes.Count, "0");
105 		}
106 
107 		[Test]
108 		[ExpectedException (typeof (NotSupportedException))]
InnerHtml_Get()109 		public void InnerHtml_Get ()
110 		{
111 			HtmlTableRow r = new HtmlTableRow ();
112 			Assert.IsNotNull (r.InnerHtml);
113 		}
114 
115 		[Test]
116 		[ExpectedException (typeof (NotSupportedException))]
InnerHtml_Set()117 		public void InnerHtml_Set ()
118 		{
119 			HtmlTableRow r = new HtmlTableRow ();
120 			r.InnerHtml = String.Empty;
121 		}
122 
123 		[Test]
124 		[ExpectedException (typeof (NotSupportedException))]
InnerText_Get()125 		public void InnerText_Get ()
126 		{
127 			HtmlTableRow r = new HtmlTableRow ();
128 			Assert.IsNotNull (r.InnerText);
129 		}
130 
131 		[Test]
132 		[ExpectedException (typeof (NotSupportedException))]
InnerText_Set()133 		public void InnerText_Set ()
134 		{
135 			HtmlTableRow r = new HtmlTableRow ();
136 			r.InnerText = String.Empty;
137 		}
138 
AdjustLineEndings(string s)139 		private string AdjustLineEndings (string s)
140 		{
141 			return s.Replace ("\r\n", Environment.NewLine);
142 		}
143 
144 		[Test]
Render()145 		public void Render ()
146 		{
147 			TestHtmlTableRow r = new TestHtmlTableRow ();
148 			r.Align = "*1*";
149 			r.BgColor = "*2*";
150 			r.BorderColor = "*3*";
151 			r.Height = "*4*";
152 			r.VAlign = "*5*";
153 			Assert.AreEqual (AdjustLineEndings ("<tr align=\"*1*\" bgcolor=\"*2*\" bordercolor=\"*3*\" height=\"*4*\" valign=\"*5*\">\r\n</tr>\r\n"), r.Render ());
154 		}
155 
156 		[Test]
157 		[ExpectedException (typeof (NullReferenceException))]
HtmlTableCellControlCollectionAdd_Null()158 		public void HtmlTableCellControlCollectionAdd_Null ()
159 		{
160 			TestHtmlTableRow t = new TestHtmlTableRow ();
161 			ControlCollection c = t.GetCollection ();
162 			c.Add (null);
163 		}
164 
165 		[Test]
166 		[ExpectedException (typeof (ArgumentException))]
HtmlTableCellControlCollectionAdd_WrongType()167 		public void HtmlTableCellControlCollectionAdd_WrongType ()
168 		{
169 			TestHtmlTableRow t = new TestHtmlTableRow ();
170 			ControlCollection c = t.GetCollection ();
171 			c.Add (new HtmlTable ());
172 		}
173 
174 		[Test]
HtmlTableCellControlCollectionAdd()175 		public void HtmlTableCellControlCollectionAdd ()
176 		{
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");
182 		}
183 
184 		[Test]
185 		[ExpectedException (typeof (NullReferenceException))]
HtmlTableCellControlCollectionAddAt_Null()186 		public void HtmlTableCellControlCollectionAddAt_Null ()
187 		{
188 			TestHtmlTableRow t = new TestHtmlTableRow ();
189 			ControlCollection c = t.GetCollection ();
190 			c.AddAt (0, null);
191 		}
192 
193 		[Test]
194 		[ExpectedException (typeof (ArgumentException))]
HtmlTableCellControlCollectionAddAt_WrongType()195 		public void HtmlTableCellControlCollectionAddAt_WrongType ()
196 		{
197 			TestHtmlTableRow t = new TestHtmlTableRow ();
198 			ControlCollection c = t.GetCollection ();
199 			c.AddAt (0, new HtmlTable ());
200 		}
201 
202 		[Test]
HtmlTableCellControlCollectionAddAt()203 		public void HtmlTableCellControlCollectionAddAt ()
204 		{
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");
210 		}
211 	}
212 }
213