WizardStepBaseTest.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. //
  2. // Tests for System.Web.UI.WebControls.WizardStepBaseTest.cs
  3. //
  4. // Author:
  5. // Yoni Klein ([email protected])
  6. //
  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. #if NET_2_0
  29. using System;
  30. using System.Web;
  31. using System.Web.UI;
  32. using System.Web.UI.WebControls;
  33. using NUnit.Framework;
  34. using System.IO;
  35. using MonoTests.stand_alone.WebHarness;
  36. using MonoTests.SystemWeb.Framework;
  37. using System.Collections;
  38. namespace MonoTests.System.Web.UI.WebControls
  39. {
  40. public class PokerWizardStepBase : WizardStepBase
  41. {
  42. // View state Stuff
  43. public PokerWizardStepBase ()
  44. : base ()
  45. {
  46. TrackViewState ();
  47. }
  48. public object SaveState ()
  49. {
  50. return SaveViewState ();
  51. }
  52. public void LoadState (object o)
  53. {
  54. LoadViewState (o);
  55. }
  56. public StateBag StateBag
  57. {
  58. get { return base.ViewState; }
  59. }
  60. public void DoOnLoad (EventArgs e)
  61. {
  62. base.OnLoad (e);
  63. }
  64. public string RenderChildren ()
  65. {
  66. StringWriter sw = new StringWriter ();
  67. sw.NewLine = "\n";
  68. HtmlTextWriter writer = new HtmlTextWriter (sw);
  69. base.RenderChildren (writer);
  70. return writer.InnerWriter.ToString ();
  71. }
  72. }
  73. [TestFixture]
  74. public class WizardStepBaseTest
  75. {
  76. private bool event_checker;
  77. [TestFixtureTearDown]
  78. public void TearDown ()
  79. {
  80. WebTest.Unload ();
  81. }
  82. [Test]
  83. public void WizardStepBase_DefaultProperty ()
  84. {
  85. PokerWizardStepBase step = new PokerWizardStepBase ();
  86. Assert.AreEqual (true, step.AllowReturn, "AllowReturn");
  87. Assert.AreEqual (true, step.EnableTheming, "EnableTheming");
  88. Assert.AreEqual (null, step.ID, "ID");
  89. Assert.AreEqual (WizardStepType.Auto, step.StepType, "StepType");
  90. Assert.AreEqual ("", step.Title, "Title");
  91. Assert.AreEqual (null, step.Wizard, "Wizard");
  92. }
  93. [Test]
  94. public void WizardStepBase_DefaultPropertyNotWorking ()
  95. {
  96. PokerWizardStepBase step = new PokerWizardStepBase ();
  97. Assert.AreEqual (null, step.Name, "Name");
  98. }
  99. [Test]
  100. public void WizardStepBase_AssignProperty ()
  101. {
  102. PokerWizardStepBase step = new PokerWizardStepBase ();
  103. Wizard w = new Wizard ();
  104. Assert.AreEqual (0, step.StateBag.Count, "ViewState.Count");
  105. w.WizardSteps.Add (step);
  106. Assert.AreEqual (w, step.Wizard, "Wizard");
  107. step.EnableTheming = false;
  108. Assert.AreEqual (false, step.EnableTheming, "EnableTheming");
  109. step.ID = "test";
  110. Assert.AreEqual ("test", step.ID, "ID");
  111. step.Title = "test";
  112. Assert.AreEqual ("test", step.Title, "Title");
  113. step.AllowReturn = false;
  114. Assert.AreEqual (false, step.AllowReturn, "AllowReturn");
  115. step.StepType = WizardStepType.Complete;
  116. Assert.AreEqual (WizardStepType.Complete, step.StepType, "StepType");
  117. }
  118. [Test]
  119. public void WizardStepBase_StateBag ()
  120. {
  121. PokerWizardStepBase step = new PokerWizardStepBase ();
  122. Wizard w = new Wizard ();
  123. step.StepType = WizardStepType.Complete;
  124. Assert.AreEqual (WizardStepType.Complete, step.StepType, "StepType");
  125. Assert.AreEqual (1, step.StateBag.Count, "StepTypeStateBag");
  126. step.AllowReturn = false;
  127. Assert.AreEqual (false, step.AllowReturn, "AllowReturn");
  128. Assert.AreEqual (2, step.StateBag.Count, "AllowReturnStateBag");
  129. step.Title = "test";
  130. Assert.AreEqual ("test", step.Title, "Title");
  131. Assert.AreEqual (3, step.StateBag.Count, "Title");
  132. }
  133. [Test]
  134. public void WizardStepBase_LoadViewState ()
  135. {
  136. PokerWizardStepBase step = new PokerWizardStepBase ();
  137. PokerWizardStepBase copy = new PokerWizardStepBase ();
  138. step.AllowReturn = false;
  139. Assert.AreEqual (false, step.AllowReturn, "AllowReturn");
  140. Assert.AreEqual (1, step.StateBag.Count, "AllowReturnStateBag");
  141. step.StepType = WizardStepType.Complete;
  142. Assert.AreEqual (WizardStepType.Complete, step.StepType, "StepType");
  143. Assert.AreEqual (2, step.StateBag.Count, "StepTypeStateBag");
  144. object state = step.SaveState ();
  145. copy.LoadState (state);
  146. Assert.AreEqual (false, copy.AllowReturn, "AllowReturn");
  147. Assert.AreEqual (WizardStepType.Complete, copy.StepType, "StepType");
  148. }
  149. [Test]
  150. public void WizardStepBase_LoadEvent ()
  151. {
  152. Wizard w = new Wizard ();
  153. PokerWizardStepBase step = new PokerWizardStepBase ();
  154. w.WizardSteps.Add (step);
  155. step.Load += new EventHandler (eventchecker);
  156. step.DoOnLoad (new EventArgs ());
  157. eventassert ("OnLoadEvent");
  158. }
  159. [Test]
  160. public void WizardStepBase_RenderChildren ()
  161. {
  162. Wizard w = new Wizard ();
  163. PokerWizardStepBase step = new PokerWizardStepBase ();
  164. LiteralControl lc = new LiteralControl ("test");
  165. step.Controls.Add (lc);
  166. w.WizardSteps.Add (step);
  167. Assert.AreEqual ("test", step.RenderChildren (), "RenderChildren");
  168. }
  169. [Test]
  170. public void WizardStepBase_ID ()
  171. {
  172. Wizard w = new Wizard ();
  173. PokerWizardStepBase step = new PokerWizardStepBase ();
  174. step.ID = "step1";
  175. w.WizardSteps.Add (step);
  176. Assert.AreEqual (step, w.FindControl ("step1"), "Step with ID fail");
  177. }
  178. [Test]
  179. [Category ("NunitWeb")]
  180. public void WizardStepBase_RenderTest ()
  181. {
  182. // This render test include Title property test
  183. string html = new WebTest (PageInvoker.CreateOnLoad (
  184. new PageDelegate (Render_Test))).Run ();
  185. string origin = @"<table cellspacing=""0"" cellpadding=""0"" border=""0"" style=""border-collapse:collapse;"">
  186. <tr>
  187. <td style=""height:100%;""><a href=""#ctl01_SkipLink""><img alt=""Skip Navigation Links."" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd?d=u9knZDluAzVeq3S7b_Cm7w2&amp;t=632875336762459244"" style=""border-width:0px;"" /></a><table id=""ctl01_SideBarContainer_SideBarList"" cellspacing=""0"" border=""0"" style=""border-collapse:collapse;"">
  188. <tr>
  189. <td style=""font-weight:bold;""><a id=""ctl01_SideBarContainer_SideBarList_ctl00_SideBarButton"" href=""javascript:__doPostBack('ctl01$SideBarContainer$SideBarList$ctl00$SideBarButton','')"">my_title</a></td>
  190. </tr><tr>
  191. <td><a id=""ctl01_SideBarContainer_SideBarList_ctl01_SideBarButton"" href=""javascript:__doPostBack('ctl01$SideBarContainer$SideBarList$ctl01$SideBarButton','')"">my_title_2</a></td>
  192. </tr>
  193. </table><a id=""ctl01_SkipLink""></a></td><td style=""height:100%;""><table cellspacing=""0"" cellpadding=""0"" border=""0"" style=""height:100%;width:100%;border-collapse:collapse;"">
  194. <tr style=""height:100%;"">
  195. <td>123</td>
  196. </tr><tr>
  197. <td align=""right""><table cellspacing=""5"" cellpadding=""5"" border=""0"">
  198. <tr>
  199. <td align=""right""><input type=""submit"" name=""ctl01$StartNavigationTemplateContainerID$StartNextButton"" value=""Next"" id=""ctl01_StartNavigationTemplateContainerID_StartNextButton"" /></td>
  200. </tr>
  201. </table></td>
  202. </tr>
  203. </table></td>
  204. </tr>
  205. </table>";
  206. HtmlDiff.AssertAreEqual (origin, HtmlDiff.GetControlFromPageHtml (html), "BaseRender");
  207. if (html.IndexOf ("my_title") < 0) {
  208. Assert.Fail ("WizardStepBase title not rendered");
  209. }
  210. }
  211. public static void Render_Test (Page p)
  212. {
  213. LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
  214. LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
  215. Wizard w = new Wizard ();
  216. PokerWizardStepBase ws = new PokerWizardStepBase ();
  217. ws.Title = "my_title";
  218. ws.Controls.Add (new LiteralControl ("123"));
  219. ws.StepType = WizardStepType.Start;
  220. PokerWizardStepBase ws2 = new PokerWizardStepBase ();
  221. ws2.Title = "my_title_2";
  222. ws2.Controls.Add (new LiteralControl ("1234567"));
  223. ws2.StepType = WizardStepType.Finish;
  224. w.DisplaySideBar = true;
  225. w.WizardSteps.Add (ws);
  226. w.WizardSteps.Add (ws2);
  227. p.Form.Controls.Add (lcb);
  228. p.Form.Controls.Add (w);
  229. p.Form.Controls.Add (lce);
  230. }
  231. [Test]
  232. [Category ("NunitWeb")]
  233. [Category ("NotWorking")]
  234. public void WizardStepBase_PostBackAllowReturnTest ()
  235. {
  236. // This test examine the rendering 2 steps and make postbake
  237. // assigned AllowReturn property
  238. WebTest t = new WebTest ();
  239. PageDelegates pd = new PageDelegates ();
  240. pd.PreInit = _postback;
  241. pd.PreRenderComplete = read_control;
  242. t.Invoker = new PageInvoker (pd);
  243. string result = t.Run ();
  244. if (result.IndexOf ("Start") < 0)
  245. Assert.Fail ("Rendering fault");
  246. ArrayList list = t.UserData as ArrayList;
  247. Assert.IsNotNull (list, "PostBackDataNotCreated");
  248. FormRequest fr = new FormRequest (t.Response, "form1");
  249. fr.Controls.Add ("__EVENTTARGET");
  250. fr.Controls.Add ("__EVENTARGUMENT");
  251. fr.Controls["__EVENTTARGET"].Value = list[1].ToString ();
  252. fr.Controls["__EVENTARGUMENT"].Value = "";
  253. t.Request = fr;
  254. result = t.Run ();
  255. if (result.IndexOf ("StepType") < 0)
  256. Assert.Fail ("MovedToStep1");
  257. if (result.IndexOf ("Previous") > 0) {
  258. Assert.Fail ("Previous button rendered");
  259. }
  260. }
  261. public static void _postback (Page p)
  262. {
  263. p.EnableEventValidation = false;
  264. Wizard w = new Wizard ();
  265. w.ID = "Wizard";
  266. PokerWizardStepBase ws = new PokerWizardStepBase ();
  267. ws.ID = "step";
  268. ws.StepType = WizardStepType.Start;
  269. ws.Controls.Add (new LiteralControl ("StartType"));
  270. ws.AllowReturn = false;
  271. PokerWizardStepBase ws1 = new PokerWizardStepBase ();
  272. ws1.ID = "step1";
  273. ws1.StepType = WizardStepType.Step;
  274. ws1.Controls.Add (new LiteralControl ("StepType"));
  275. w.DisplaySideBar = true;
  276. w.WizardSteps.Add (ws);
  277. w.WizardSteps.Add (ws1);
  278. p.Controls.Add (w);
  279. }
  280. [Test]
  281. [Category ("NunitWeb")]
  282. [Category ("NotWorking")]
  283. public void WizardStepBase_Theme ()
  284. {
  285. #if DOT_NET
  286. WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.WizardTest.skin", "App_Themes/Theme1/WizardTest.skin");
  287. #else
  288. WebTest.CopyResource (GetType (), "WizardTest.skin", "App_Themes/Theme1/WizardTest.skin");
  289. #endif
  290. WebTest t = new WebTest ();
  291. PageDelegates pd = new PageDelegates ();
  292. pd.PreInit = set_properties;
  293. pd.Load = theme;
  294. t.Invoker = new PageInvoker (pd);
  295. string html = t.Run ();
  296. if (html.IndexOf ("testing") < 0) {
  297. Assert.Fail ("WizardStepBase themes not applyed when EnableTheming = true");
  298. }
  299. pd.Load = notheme;
  300. t.Invoker = new PageInvoker (pd);
  301. html = t.Run ();
  302. if (html.IndexOf ("testing") > 0) {
  303. Assert.Fail ("WizardStepBase themes applyed when EnableTheming = false");
  304. }
  305. }
  306. public static void set_properties (Page p)
  307. {
  308. p.Theme = "Theme1";
  309. }
  310. public static void theme (Page p)
  311. {
  312. Wizard w = new Wizard ();
  313. PokerWizardStepBase ws = new PokerWizardStepBase ();
  314. ws.Controls.Add (new Button ());
  315. ws.EnableTheming = true;
  316. ws.SkinID = "WizardTest";
  317. w.WizardSteps.Add (ws);
  318. p.Form.Controls.Add (w);
  319. }
  320. public static void notheme (Page p)
  321. {
  322. Wizard w = new Wizard ();
  323. PokerWizardStepBase ws = new PokerWizardStepBase ();
  324. ws.Controls.Add (new Button ());
  325. ws.EnableTheming = false;
  326. ws.SkinID = "WizardTest";
  327. w.WizardSteps.Add (ws);
  328. p.Form.Controls.Add (w);
  329. }
  330. private void eventchecker (object o, EventArgs e)
  331. {
  332. event_checker = true;
  333. }
  334. private void eventassert (string message)
  335. {
  336. Assert.IsTrue (event_checker, message);
  337. event_checker = false;
  338. }
  339. public static void read_control (Page p)
  340. {
  341. ArrayList list = new ArrayList ();
  342. recurcive_find (list, typeof (LinkButton), p.FindControl ("Wizard"));
  343. WebTest.CurrentTest.UserData = list;
  344. }
  345. public static void recurcive_find (ArrayList list, Type t, Control control)
  346. {
  347. foreach (Control c in control.Controls) {
  348. if (c == null)
  349. continue;
  350. if (t == c.GetType ()) {
  351. list.Add (c.UniqueID);
  352. }
  353. recurcive_find (list, t, c);
  354. }
  355. }
  356. }
  357. }
  358. #endif