HtmlTableRowTest.cs 5.9 KB

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