PanelTest.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. //
  2. // Tests for System.Web.UI.WebControls.Panel.cs
  3. //
  4. // Author:
  5. // Ben Maurer <[email protected]>
  6. // Yoni Klain <[email protected]>
  7. //
  8. //
  9. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using NUnit.Framework;
  31. using System;
  32. using System.IO;
  33. using System.Globalization;
  34. using System.Web;
  35. using System.Web.UI;
  36. using System.Web.UI.WebControls;
  37. using System.Drawing;
  38. using MonoTests.stand_alone.WebHarness;
  39. using MonoTests.SystemWeb.Framework;
  40. namespace MonoTests.System.Web.UI.WebControls {
  41. [TestFixture]
  42. public class PanelTest
  43. {
  44. #region helpclasses
  45. class Poker : Panel {
  46. public string Render ()
  47. {
  48. StringWriter sw = new StringWriter ();
  49. sw.NewLine = "\n";
  50. HtmlTextWriter writer = new HtmlTextWriter (sw);
  51. base.Render (writer);
  52. return writer.InnerWriter.ToString ();
  53. }
  54. }
  55. class PokerS : Panel
  56. {
  57. public string Render ()
  58. {
  59. StringWriter sw = new StringWriter ();
  60. sw.NewLine = "\n";
  61. HtmlTextWriter writer = new HtmlTextWriter (sw);
  62. base.Render (writer);
  63. return writer.InnerWriter.ToString ();
  64. }
  65. #if NET_2_0
  66. protected override Style CreateControlStyle ()
  67. {
  68. Style s = new Style (new StateBag ());
  69. s.BackColor = Color.Red;
  70. s.BorderColor = Color.Red;
  71. return s;
  72. }
  73. public override void RenderBeginTag (HtmlTextWriter writer)
  74. {
  75. base.RenderBeginTag (writer);
  76. }
  77. public override void RenderEndTag (HtmlTextWriter writer)
  78. {
  79. base.RenderEndTag (writer);
  80. }
  81. public string RenderBeginTag ()
  82. {
  83. StringWriter sw = new StringWriter ();
  84. sw.NewLine = "\n";
  85. HtmlTextWriter writer = new HtmlTextWriter (sw);
  86. base.RenderBeginTag (writer);
  87. return writer.InnerWriter.ToString ();
  88. }
  89. public string RenderEndTag ()
  90. {
  91. StringWriter sw = new StringWriter ();
  92. sw.NewLine = "\n";
  93. HtmlTextWriter writer = new HtmlTextWriter (sw);
  94. base.RenderBeginTag (writer);
  95. base.RenderEndTag (writer);
  96. return writer.InnerWriter.ToString ();
  97. }
  98. #endif
  99. }
  100. class PokerR : Panel
  101. {
  102. public string Render ()
  103. {
  104. StringWriter sw = new StringWriter ();
  105. sw.NewLine = "\n";
  106. HtmlTextWriter writer = new HtmlTextWriter (sw);
  107. sw.Write ("Render");
  108. base.Render (writer);
  109. return writer.InnerWriter.ToString ();
  110. }
  111. #if NET_2_0
  112. public override void RenderBeginTag (HtmlTextWriter writer)
  113. {
  114. writer.Write ("RenderBeginTag");
  115. }
  116. public override void RenderEndTag (HtmlTextWriter writer)
  117. {
  118. writer.Write ("RenderEndTag");
  119. }
  120. #endif
  121. }
  122. #endregion
  123. #if NET_2_0
  124. [TestFixtureSetUp]
  125. public void SetUp ()
  126. {
  127. WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
  128. }
  129. #endif
  130. [Test]
  131. [Category("NotWorking")]
  132. public void Defaults ()
  133. {
  134. Poker p = new Poker ();
  135. #if NET_2_0
  136. #if false
  137. Assert.AreEqual (ContentDirection.NotSet, p.Direction, "Direction");
  138. Assert.AreEqual (string.Empty, p.GroupingText, "GroupingText");
  139. Assert.AreEqual (ScrollBars.None, p.ScrollBars, "ScrollBars");
  140. Assert.AreEqual (string.Empty, p.DefaultButton, "DefaultButton");
  141. #endif
  142. //Note: "Panel does not have definition to: ScrollBars;DefaultButton;Direction;GroupingText";
  143. #endif
  144. }
  145. [Test]
  146. public void NoWrap ()
  147. {
  148. Poker p = new Poker ();
  149. p.Wrap = false;
  150. p.Controls.Add (new LiteralControl ("TEXT"));
  151. #if NET_2_0
  152. const string html ="<div style=\"white-space:nowrap;\">\n\tTEXT\n</div>";
  153. #elif NET_1_1
  154. const string html ="<div nowrap=\"nowrap\">\n\tTEXT\n</div>";
  155. #endif
  156. Assert.AreEqual (html, p.Render ());
  157. }
  158. #if NET_2_0
  159. [Test]
  160. public void CreateControlStyle ()
  161. {
  162. PokerS p = new PokerS ();
  163. Style s = p.ControlStyle;
  164. Assert.AreEqual (Color.Red, s.BackColor, "CreateControlStyle#1");
  165. Assert.AreEqual (Color.Red, s.BorderColor, "CreateControlStyle#2");
  166. p.ApplyStyle (s);
  167. string html = p.Render ();
  168. HtmlDiff.AssertAreEqual ("<div style=\"background-color:Red;border-color:Red;\"></div>", html, "CreateControlStyle");
  169. }
  170. [Test]
  171. [Category("NotWorking")]
  172. [Category ("NunitWeb")]
  173. public void DefaultButton ()
  174. {
  175. #if false
  176. WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
  177. WebTest t = new WebTest ("NoEventValidation.aspx");
  178. t.Invoker = PageInvoker.CreateOnInit (DefaultButton__Init);
  179. t.Run ();
  180. #endif
  181. // Note : "Panel have no definition to DefaultButton");
  182. }
  183. public static void DefaultButton__Init (Page p)
  184. {
  185. #if false
  186. Poker pl = new Poker ();
  187. pl.DefaultButton = "MyButton";
  188. Button b = new Button ();
  189. b.ID = "MyButton";
  190. p.Form.Controls.Add (b);
  191. p.Form.Controls.Add (pl);
  192. string html = pl.Render ();
  193. if (html.IndexOf ("onkeypress") == -1)
  194. Assert.Fail ("Default button script not created #1");
  195. if (html.IndexOf ("MyButton") == -1)
  196. Assert.Fail ("Default button script not created #2");
  197. #endif
  198. // Note :"Panel have no definition to DefaultButton");
  199. }
  200. [Test]
  201. [Category ("NotWorking")]
  202. [Category("NunitWeb")]
  203. #if false
  204. [ExpectedException(typeof(InvalidOperationException))]
  205. #endif
  206. public void DefaultButton_Exception ()
  207. {
  208. #if false
  209. WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
  210. WebTest t = new WebTest ("NoEventValidation.aspx");
  211. t.Invoker = PageInvoker.CreateOnInit (DefaultButton_Init);
  212. t.Run ();
  213. #endif
  214. // Note :"Panel have no definition to DefaultButton");
  215. }
  216. public static void DefaultButton_Init (Page p)
  217. {
  218. #if false
  219. Poker pl = new Poker ();
  220. pl.DefaultButton = "test";
  221. p.Form.Controls.Add (pl);
  222. pl.Render ();
  223. #endif
  224. // Note: "Panel have no definition to DefaultButton");
  225. }
  226. [Test]
  227. [Category("NotWorking")]
  228. public void Direction ()
  229. {
  230. Poker p = new Poker ();
  231. #if false
  232. p.Direction = ContentDirection.LeftToRight;
  233. string html = p.Render();
  234. HtmlDiff.AssertAreEqual ("<div dir=\"ltr\"></div>", html, "Direction");
  235. #endif
  236. //Note:"Panel have no definition to Direction");
  237. }
  238. [Test]
  239. [Category ("NotWorking")]
  240. public void GroupingText ()
  241. {
  242. Poker p = new Poker ();
  243. #if false
  244. p.GroupingText = "MyNameText";
  245. string html = p.Render ();
  246. HtmlDiff.AssertAreEqual ("<div><fieldset><legend>MyNameText</legend></fieldset></div>", html, "GroupingText");
  247. #endif
  248. //Note : "Panel have no definition to GroupingText");
  249. }
  250. [Test]
  251. public void RenderBeginTag ()
  252. {
  253. PokerS p = new PokerS ();
  254. string html = p.RenderBeginTag ();
  255. HtmlDiff.AssertAreEqual ("<div>\n", html, "RenderBeginTag");
  256. }
  257. [Test]
  258. public void RenderEndTag ()
  259. {
  260. PokerS p = new PokerS ();
  261. string html = p.RenderEndTag ();
  262. HtmlDiff.AssertAreEqual ("<div>\n\n</div>", html, "RenderBeginTag");
  263. }
  264. [Test]
  265. public void RenderFlow ()
  266. {
  267. PokerR p = new PokerR ();
  268. string html = p.Render ();
  269. Assert.AreEqual ("RenderRenderBeginTagRenderEndTag", html, "RenderFlow");
  270. }
  271. [Test]
  272. [Category("NotWorking")]
  273. public void Scroll_Bars ()
  274. {
  275. Poker p = new Poker ();
  276. #if false
  277. p.ScrollBars = ScrollBars.Horizontal;
  278. string html = p.Render ();
  279. HtmlDiff.AssertAreEqual ("<div style=\"overflow-x:scroll;\"></div>", html, "ScrollBars.Horizontal");
  280. p.ScrollBars = ScrollBars.Vertical;
  281. html = p.Render ();
  282. HtmlDiff.AssertAreEqual ("<div style=\"overflow-y:scroll;\"></div>", html, "ScrollBars.Vertical");
  283. p.ScrollBars = ScrollBars.Both;
  284. html = p.Render ();
  285. HtmlDiff.AssertAreEqual ("<div style=\"overflow-scroll;\"></div>", html, "ScrollBars.Both");
  286. #endif
  287. // Note : "Panel does not have definition to ScrollBars");
  288. }
  289. [TestFixtureTearDown]
  290. public void TearDown ()
  291. {
  292. WebTest.Unload ();
  293. }
  294. #endif
  295. }
  296. }