HtmlTableCellTest.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // HtmlTableCellTest.cs
  3. // - Unit tests for System.Web.UI.HtmlControls.HtmlTableCell
  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 TestHtmlTableCell : HtmlTableCell {
  36. public string Render ()
  37. {
  38. HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
  39. base.Render (writer);
  40. return writer.InnerWriter.ToString ();
  41. }
  42. }
  43. [TestFixture]
  44. public class HtmlTableCellTest {
  45. [Test]
  46. public void DefaultProperties ()
  47. {
  48. HtmlTableCell c = new HtmlTableCell ();
  49. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
  50. Assert.AreEqual (String.Empty, c.Align, "Align");
  51. Assert.AreEqual (String.Empty, c.BgColor, "BgColor");
  52. Assert.AreEqual (String.Empty, c.BorderColor, "BorderColor");
  53. Assert.AreEqual (-1, c.ColSpan, "ColSpan");
  54. Assert.AreEqual (String.Empty, c.Height, "Height");
  55. Assert.IsFalse (c.NoWrap, "NoWrap");
  56. Assert.AreEqual (-1, c.RowSpan, "RowSpan");
  57. Assert.AreEqual (String.Empty, c.VAlign, "VAlign");
  58. Assert.AreEqual (String.Empty, c.Width, "Width");
  59. Assert.AreEqual ("td", c.TagName, "TagName");
  60. }
  61. [Test]
  62. public void NullProperties ()
  63. {
  64. HtmlTableCell c = new HtmlTableCell ();
  65. c.Align = null;
  66. Assert.AreEqual (String.Empty, c.Align, "Align");
  67. c.BgColor = null;
  68. Assert.AreEqual (String.Empty, c.BgColor, "BgColor");
  69. c.BorderColor = null;
  70. Assert.AreEqual (String.Empty, c.BorderColor, "BorderColor");
  71. c.Height = null;
  72. Assert.AreEqual (String.Empty, c.Height, "Height");
  73. c.VAlign = null;
  74. Assert.AreEqual (String.Empty, c.VAlign, "VAlign");
  75. c.Width = null;
  76. Assert.AreEqual (String.Empty, c.Width, "Width");
  77. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
  78. }
  79. [Test]
  80. public void EmptyProperties ()
  81. {
  82. HtmlTableCell c = new HtmlTableCell ();
  83. c.ColSpan = -1;
  84. Assert.AreEqual (-1, c.ColSpan, "ColSpan");
  85. c.RowSpan = -1;
  86. Assert.AreEqual (-1, c.RowSpan, "RowSpan");
  87. c.NoWrap = false;
  88. Assert.IsFalse (c.NoWrap, "NoWrap");
  89. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
  90. }
  91. [Test]
  92. public void CleanProperties ()
  93. {
  94. HtmlTableCell c = new HtmlTableCell ();
  95. c.Align = "center";
  96. Assert.AreEqual ("center", c.Align, "Align");
  97. c.ColSpan = 1;
  98. Assert.AreEqual (1, c.ColSpan, "Align");
  99. c.NoWrap = true;
  100. Assert.IsTrue (c.NoWrap, "NoWrap");
  101. Assert.AreEqual (3, c.Attributes.Count, "3");
  102. c.Align = null;
  103. Assert.AreEqual (String.Empty, c.Align, "-Align");
  104. c.ColSpan = -1;
  105. Assert.AreEqual (-1, c.ColSpan, "-ColSpan");
  106. c.NoWrap = false;
  107. Assert.IsFalse (c.NoWrap, "-NoWrap");
  108. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
  109. }
  110. private string AdjustLineEndings (string s)
  111. {
  112. return s.Replace ("\r\n", Environment.NewLine);
  113. }
  114. [Test]
  115. public void Render ()
  116. {
  117. TestHtmlTableCell c = new TestHtmlTableCell ();
  118. c.Align = "*1*";
  119. c.BgColor = "*2*";
  120. c.BorderColor = "*3*";
  121. c.ColSpan = 4;
  122. c.Width = "*5*";
  123. Assert.AreEqual (AdjustLineEndings ("<td align=\"*1*\" bgcolor=\"*2*\" bordercolor=\"*3*\" colspan=\"4\" width=\"*5*\"></td>\r\n"), c.Render ());
  124. }
  125. }
  126. }