2
0

HtmlTableRowTest.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 ()
  94. {
  95. HtmlTableRow r = new HtmlTableRow ();
  96. Assert.IsNotNull (r.InnerHtml);
  97. }
  98. [Test]
  99. [ExpectedException (typeof (NotSupportedException))]
  100. public void InnerText ()
  101. {
  102. HtmlTableRow r = new HtmlTableRow ();
  103. Assert.IsNotNull (r.InnerText);
  104. }
  105. private string AdjustLineEndings (string s)
  106. {
  107. return s.Replace ("\r\n", Environment.NewLine);
  108. }
  109. [Test]
  110. public void Render ()
  111. {
  112. TestHtmlTableRow r = new TestHtmlTableRow ();
  113. r.Align = "*1*";
  114. r.BgColor = "*2*";
  115. r.BorderColor = "*3*";
  116. r.Height = "*4*";
  117. r.VAlign = "*5*";
  118. Assert.AreEqual (AdjustLineEndings ("<tr align=\"*1*\" bgcolor=\"*2*\" bordercolor=\"*3*\" height=\"*4*\" valign=\"*5*\">\r\n</tr>\r\n"), r.Render ());
  119. }
  120. [Test]
  121. [ExpectedException (typeof (NullReferenceException))]
  122. public void HtmlTableCellControlCollectionAdd_Null ()
  123. {
  124. TestHtmlTableRow t = new TestHtmlTableRow ();
  125. ControlCollection c = t.GetCollection ();
  126. c.Add (null);
  127. }
  128. [Test]
  129. [ExpectedException (typeof (ArgumentException))]
  130. public void HtmlTableCellControlCollectionAdd_WrongType ()
  131. {
  132. TestHtmlTableRow t = new TestHtmlTableRow ();
  133. ControlCollection c = t.GetCollection ();
  134. c.Add (new HtmlTable ());
  135. }
  136. [Test]
  137. public void HtmlTableCellControlCollectionAdd ()
  138. {
  139. TestHtmlTableRow t = new TestHtmlTableRow ();
  140. ControlCollection c = t.GetCollection ();
  141. c.Add (new HtmlTableCell ());
  142. c.Add (new InheritedHtmlTableCell ());
  143. Assert.AreEqual (2, c.Count, "Cells");
  144. }
  145. [Test]
  146. [ExpectedException (typeof (NullReferenceException))]
  147. public void HtmlTableCellControlCollectionAddAt_Null ()
  148. {
  149. TestHtmlTableRow t = new TestHtmlTableRow ();
  150. ControlCollection c = t.GetCollection ();
  151. c.AddAt (0, null);
  152. }
  153. [Test]
  154. [ExpectedException (typeof (ArgumentException))]
  155. public void HtmlTableCellControlCollectionAddAt_WrongType ()
  156. {
  157. TestHtmlTableRow t = new TestHtmlTableRow ();
  158. ControlCollection c = t.GetCollection ();
  159. c.AddAt (0, new HtmlTable ());
  160. }
  161. [Test]
  162. public void HtmlTableCellControlCollectionAddAt ()
  163. {
  164. TestHtmlTableRow t = new TestHtmlTableRow ();
  165. ControlCollection c = t.GetCollection ();
  166. c.AddAt (0, new HtmlTableCell ());
  167. c.AddAt (0, new InheritedHtmlTableCell ());
  168. Assert.AreEqual (2, c.Count, "Cells");
  169. }
  170. }
  171. }