TableItemStyleTest.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // TableItemStyleTest.cs
  3. // - Unit tests for System.Web.UI.WebControls.TableItemStyle
  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 TestTableItemStyle : TableItemStyle {
  37. public TestTableItemStyle ()
  38. : base ()
  39. {
  40. }
  41. public TestTableItemStyle (StateBag bag)
  42. : base (bag)
  43. {
  44. }
  45. public bool Empty {
  46. get { return base.IsEmpty; }
  47. }
  48. public StateBag StateBag {
  49. get { return base.ViewState; }
  50. }
  51. }
  52. [TestFixture]
  53. public class TableItemStyleTest {
  54. private void DefaultProperties (TestTableItemStyle tis)
  55. {
  56. Assert.AreEqual (0, tis.StateBag.Count, "ViewState.Count");
  57. Assert.AreEqual (HorizontalAlign.NotSet, tis.HorizontalAlign, "HorizontalAlign");
  58. Assert.AreEqual (VerticalAlign.NotSet, tis.VerticalAlign, "VerticalAlign");
  59. Assert.IsTrue (tis.Wrap, "Wrap");
  60. Assert.AreEqual (0, tis.StateBag.Count, "ViewState.Count-2");
  61. tis.Reset ();
  62. Assert.AreEqual (0, tis.StateBag.Count, "Reset");
  63. }
  64. private void NullProperties (TestTableItemStyle tis)
  65. {
  66. Assert.IsTrue (tis.Empty, "Empty");
  67. tis.HorizontalAlign = HorizontalAlign.NotSet;
  68. Assert.AreEqual (HorizontalAlign.NotSet, tis.HorizontalAlign, "HorizontalAlign");
  69. Assert.IsFalse (tis.Empty, "!Empty");
  70. tis.VerticalAlign = VerticalAlign.NotSet;
  71. Assert.AreEqual (VerticalAlign.NotSet, tis.VerticalAlign, "VerticalAlign");
  72. tis.Wrap = true;
  73. Assert.IsTrue (tis.Wrap, "Wrap");
  74. Assert.AreEqual (3, tis.StateBag.Count, "ViewState.Count-1");
  75. tis.Reset ();
  76. Assert.AreEqual (0, tis.StateBag.Count, "Reset");
  77. Assert.IsTrue (tis.Empty, "Empty/Reset");
  78. }
  79. [Test]
  80. public void Constructor_Default ()
  81. {
  82. TestTableItemStyle tis = new TestTableItemStyle ();
  83. DefaultProperties (tis);
  84. NullProperties (tis);
  85. }
  86. [Test]
  87. public void Constructor_StateBag_Null ()
  88. {
  89. TestTableItemStyle tis = new TestTableItemStyle (null);
  90. Assert.IsNotNull (tis.StateBag, "StateBag");
  91. DefaultProperties (tis);
  92. NullProperties (tis);
  93. }
  94. [Test]
  95. public void Constructor_StateBag ()
  96. {
  97. TestTableItemStyle tis = new TestTableItemStyle (new StateBag ());
  98. Assert.IsNotNull (tis.StateBag, "StateBag");
  99. DefaultProperties (tis);
  100. NullProperties (tis);
  101. }
  102. [Test]
  103. // LAMESPEC: documented as ArgumentException
  104. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  105. public void HorizontalAlign_Invalid ()
  106. {
  107. TableItemStyle tis = new TableItemStyle ();
  108. tis.HorizontalAlign = (HorizontalAlign)Int32.MinValue;
  109. }
  110. [Test]
  111. // LAMESPEC: documented as ArgumentException
  112. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  113. public void VerticalAlign_Invalid ()
  114. {
  115. TableItemStyle tis = new TableItemStyle ();
  116. tis.VerticalAlign = (VerticalAlign)Int32.MinValue;
  117. }
  118. [Test]
  119. public void AddAttributesToRender_Null_WebControl ()
  120. {
  121. TableItemStyle tis = new TableItemStyle ();
  122. tis.AddAttributesToRender (null, new TableRow ());
  123. // no exception
  124. }
  125. [Test]
  126. public void AddAttributesToRender_HtmlTextWriter_Null ()
  127. {
  128. TableItemStyle tis = GetTableItemStyle ();
  129. HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
  130. tis.AddAttributesToRender (writer, null);
  131. Assert.AreEqual (String.Empty, writer.InnerWriter.ToString (), "empty");
  132. }
  133. [Test]
  134. public void AddAttributesToRender ()
  135. {
  136. TableItemStyle tis = GetTableItemStyle ();
  137. HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
  138. tis.AddAttributesToRender (writer, new Table ());
  139. Assert.AreEqual (String.Empty, writer.InnerWriter.ToString (), "empty");
  140. }
  141. private TableItemStyle GetTableItemStyle ()
  142. {
  143. TableItemStyle tis = new TableItemStyle ();
  144. tis.HorizontalAlign = HorizontalAlign.Justify;
  145. tis.VerticalAlign = VerticalAlign.Bottom;
  146. tis.Wrap = false;
  147. return tis;
  148. }
  149. private void CheckTableStyle (TableItemStyle tis)
  150. {
  151. Assert.AreEqual (HorizontalAlign.Justify, tis.HorizontalAlign, "HorizontalAlign");
  152. Assert.AreEqual (VerticalAlign.Bottom, tis.VerticalAlign, "VerticalAlign");
  153. Assert.IsFalse (tis.Wrap, "Wrap");
  154. }
  155. [Test]
  156. public void CopyFrom_Null ()
  157. {
  158. TableItemStyle tis = GetTableItemStyle ();
  159. tis.CopyFrom (null);
  160. CheckTableStyle (tis);
  161. }
  162. [Test]
  163. public void CopyFrom_Self ()
  164. {
  165. TableItemStyle tis = GetTableItemStyle ();
  166. tis.CopyFrom (tis);
  167. CheckTableStyle (tis);
  168. }
  169. [Test]
  170. public void CopyFrom_Empty ()
  171. {
  172. TestTableItemStyle tis = new TestTableItemStyle ();
  173. tis.CopyFrom (new TableItemStyle ());
  174. DefaultProperties (tis);
  175. }
  176. [Test]
  177. public void CopyFrom ()
  178. {
  179. TableItemStyle tis = new TableItemStyle ();
  180. tis.HorizontalAlign = HorizontalAlign.Left;
  181. tis.VerticalAlign = VerticalAlign.Top;
  182. tis.Wrap = true;
  183. tis.CopyFrom (GetTableItemStyle ());
  184. CheckTableStyle (tis);
  185. }
  186. [Test]
  187. public void MergeWith_Null ()
  188. {
  189. TableItemStyle tis = GetTableItemStyle ();
  190. tis.MergeWith (null);
  191. CheckTableStyle (tis);
  192. }
  193. [Test]
  194. public void MergeWith_Self ()
  195. {
  196. TableItemStyle tis = GetTableItemStyle ();
  197. tis.MergeWith (tis);
  198. CheckTableStyle (tis);
  199. }
  200. [Test]
  201. public void MergeWith_Empty ()
  202. {
  203. TestTableItemStyle tis = new TestTableItemStyle ();
  204. tis.MergeWith (new TableItemStyle ());
  205. DefaultProperties (tis);
  206. }
  207. [Test]
  208. public void MergeWith ()
  209. {
  210. TableItemStyle tis = new TableItemStyle ();
  211. tis.HorizontalAlign = HorizontalAlign.Left;
  212. tis.VerticalAlign = VerticalAlign.Top;
  213. tis.Wrap = true;
  214. tis.MergeWith (GetTableItemStyle ());
  215. Assert.AreEqual (HorizontalAlign.Left, tis.HorizontalAlign, "HorizontalAlign");
  216. Assert.AreEqual (VerticalAlign.Top, tis.VerticalAlign, "VerticalAlign");
  217. Assert.IsTrue (tis.Wrap, "Wrap");
  218. }
  219. }
  220. }