TableHeaderCellTest.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // TableHeaderCellTest.cs
  3. // - Unit tests for System.Web.UI.WebControls.TableHeaderCell
  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;
  32. using System.Web.UI;
  33. using System.Web.UI.WebControls;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.Web.UI.WebControls {
  36. public class TestTableHeaderCell : TableHeaderCell {
  37. public string Tag {
  38. get { return base.TagName; }
  39. }
  40. public StateBag StateBag {
  41. get { return base.ViewState; }
  42. }
  43. public string Render ()
  44. {
  45. HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
  46. base.Render (writer);
  47. return writer.InnerWriter.ToString ();
  48. }
  49. }
  50. [TestFixture]
  51. public class TableHeaderCellTest {
  52. [Test]
  53. public void DefaultProperties ()
  54. {
  55. TestTableHeaderCell th = new TestTableHeaderCell ();
  56. Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
  57. Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count");
  58. #if NET_2_0
  59. Assert.AreEqual (String.Empty, th.AbbreviatedText, "AbbreviatedText");
  60. Assert.AreEqual (0, th.CategoryText.Length, "CategoryText");
  61. Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "Scope");
  62. #endif
  63. Assert.AreEqual ("th", th.Tag, "TagName");
  64. Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count-2");
  65. Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-2");
  66. }
  67. [Test]
  68. public void NullProperties ()
  69. {
  70. TestTableHeaderCell th = new TestTableHeaderCell ();
  71. #if NET_2_0
  72. th.AbbreviatedText = null;
  73. Assert.AreEqual (String.Empty, th.AbbreviatedText, "AbbreviatedText");
  74. th.CategoryText = new string[0];
  75. Assert.AreEqual (0, th.CategoryText.Length, "CategoryText");
  76. Assert.AreEqual (1, th.StateBag.Count, "ViewState.Count-1");
  77. th.Scope = TableHeaderScope.NotSet;
  78. Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "Scope");
  79. Assert.AreEqual (2, th.StateBag.Count, "ViewState.Count-2");
  80. #else
  81. Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
  82. #endif
  83. Assert.AreEqual (0, th.Attributes.Count, "Attributes.Count");
  84. }
  85. [Test]
  86. public void CleanProperties ()
  87. {
  88. TestTableHeaderCell th = new TestTableHeaderCell ();
  89. #if NET_2_0
  90. th.AbbreviatedText = "header";
  91. Assert.AreEqual ("header", th.AbbreviatedText, "AbbreviatedText");
  92. th.AbbreviatedText = null;
  93. Assert.AreEqual (String.Empty, th.AbbreviatedText, "-AbbreviatedText");
  94. Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
  95. th.CategoryText = new string[1] { "mono" };
  96. Assert.AreEqual (1, th.CategoryText.Length, "CategoryText");
  97. th.CategoryText = new string[0];
  98. Assert.AreEqual (0, th.CategoryText.Length, "-CategoryText");
  99. Assert.AreEqual (1, th.StateBag.Count, "ViewState.Count-1");
  100. th.Scope = TableHeaderScope.Row;
  101. Assert.AreEqual (TableHeaderScope.Row, th.Scope, "Scope");
  102. th.Scope = TableHeaderScope.NotSet;
  103. Assert.AreEqual (TableHeaderScope.NotSet, th.Scope, "-Scope");
  104. Assert.AreEqual (2, th.StateBag.Count, "ViewState.Count-2");
  105. #else
  106. Assert.AreEqual (0, th.StateBag.Count, "ViewState.Count-1");
  107. #endif
  108. Assert.AreEqual (0, th.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. TestTableHeaderCell th = new TestTableHeaderCell ();
  118. string s = th.Render ();
  119. Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "empty/default");
  120. #if NET_2_0
  121. th.AbbreviatedText = "header";
  122. s = th.Render ();
  123. Assert.AreEqual (AdjustLineEndings ("<th abbr=\"header\"></th>"), s, "AbbreviatedText");
  124. th.AbbreviatedText = null;
  125. th.CategoryText = new string[1] { "mono" };
  126. s = th.Render ();
  127. Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono\"></th>"), s, "CategoryText-1");
  128. th.CategoryText = new string[2] { "mono", "http://www.mono-project.com" };
  129. s = th.Render ();
  130. Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono,http://www.mono-project.com\"></th>"), s, "CategoryText-2");
  131. th.CategoryText = new string[3] { "mono", "http://www.mono-project.com", "," };
  132. s = th.Render ();
  133. Assert.AreEqual (AdjustLineEndings ("<th axis=\"mono,http://www.mono-project.com,,\"></th>"), s, "CategoryText-2");
  134. th.CategoryText = new string[0];
  135. s = th.Render ();
  136. Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "CategoryText-2");
  137. th.Scope = TableHeaderScope.Row;
  138. s = th.Render ();
  139. Assert.AreEqual (AdjustLineEndings ("<th scope=\"row\"></th>"), s, "Row");
  140. th.Scope = TableHeaderScope.Column;
  141. s = th.Render ();
  142. Assert.AreEqual (AdjustLineEndings ("<th scope=\"column\"></th>"), s, "Column");
  143. th.Scope = TableHeaderScope.NotSet;
  144. s = th.Render ();
  145. Assert.AreEqual (AdjustLineEndings ("<th></th>"), s, "NotSet");
  146. #endif
  147. th.Text = "test";
  148. s = th.Render ();
  149. Assert.AreEqual (AdjustLineEndings ("<th>test</th>"), s, "Text");
  150. }
  151. }
  152. }