PageTest.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. //
  2. // Tests for System.Web.UI.Page
  3. //
  4. // Authors:
  5. // Peter Dennis Bartok ([email protected])
  6. // Sebastien Pouliot <[email protected]>
  7. // Yoni Klain <[email protected]>
  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.Threading;
  34. using System.Security.Principal;
  35. using System.Web;
  36. using System.Web.UI;
  37. using MonoTests.SystemWeb.Framework;
  38. using MonoTests.stand_alone.WebHarness;
  39. using System.Web.UI.WebControls;
  40. using System.Web.UI.HtmlControls;
  41. using System.Collections;
  42. namespace MonoTests.System.Web.UI {
  43. class TestPage : Page {
  44. private HttpContext ctx;
  45. // don't call base class (so _context is never set to a non-null value)
  46. protected override HttpContext Context {
  47. get {
  48. if (ctx == null) {
  49. ctx = new HttpContext (null);
  50. ctx.User = new GenericPrincipal (new GenericIdentity ("me"), null);
  51. }
  52. return ctx;
  53. }
  54. }
  55. }
  56. class TestPage2 : Page {
  57. private HttpContext ctx;
  58. // don't call base class (so _context is never set to a non-null value)
  59. protected override HttpContext Context {
  60. get {
  61. if (ctx == null) {
  62. ctx = new HttpContext (
  63. new HttpRequest (String.Empty, "http://www.mono-project.com", String.Empty),
  64. new HttpResponse (new StringWriter ())
  65. );
  66. }
  67. return ctx;
  68. }
  69. }
  70. public HttpContext HttpContext {
  71. get { return Context; }
  72. }
  73. }
  74. [TestFixture]
  75. public class PageTest {
  76. [TestFixtureSetUp]
  77. public void CopyTestResources ()
  78. {
  79. #if DOT_NET
  80. WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.PageValidationTest.aspx", "PageValidationTest.aspx");
  81. WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.PageLifecycleTest.aspx", "PageLifecycleTest.aspx");
  82. #else
  83. WebTest.CopyResource (GetType (), "PageValidationTest.aspx", "PageValidationTest.aspx");
  84. WebTest.CopyResource (GetType (), "PageLifecycleTest.aspx", "PageLifecycleTest.aspx");
  85. #endif
  86. }
  87. [SetUp]
  88. public void SetUpTest ()
  89. {
  90. Thread.Sleep (100);
  91. }
  92. [Test]
  93. [ExpectedException (typeof(HttpException))]
  94. public void RequestExceptionTest ()
  95. {
  96. Page p;
  97. HttpRequest r;
  98. p = new Page ();
  99. r = p.Request;
  100. }
  101. [Test]
  102. #if NET_2_0
  103. [Category ("NotDotNet")] // page.User throw NRE in 2.0 RC
  104. #endif
  105. public void User_OverridenContext ()
  106. {
  107. TestPage page = new TestPage ();
  108. Assert.AreEqual ("me", page.User.Identity.Name, "User");
  109. }
  110. [Test]
  111. [ExpectedException (typeof (HttpException))]
  112. public void Request_OverridenContext ()
  113. {
  114. TestPage2 page = new TestPage2 ();
  115. Assert.IsNotNull (page.Request, "Request");
  116. // it doesn't seems to access the context via the virtual property
  117. }
  118. [Test]
  119. public void Request_OverridenContext_Indirect ()
  120. {
  121. TestPage2 page = new TestPage2 ();
  122. Assert.IsNotNull (page.HttpContext.Request, "Request");
  123. }
  124. #if NET_2_0
  125. [Test]
  126. [Category ("NunitWeb")]
  127. public void PageHeaderOnPreInit ()
  128. {
  129. Thread.Sleep (200);
  130. PageDelegate pd = new PageDelegate (Page_OnPreInit);
  131. WebTest t = new WebTest (PageInvoker.CreateOnPreInit (pd));
  132. string html = t.Run ();
  133. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  134. string origHtml = @" <head id=""Head1""><title>
  135. PreInit
  136. </title></head>";
  137. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderInit");
  138. Thread.Sleep (200);
  139. WebTest.Unload ();
  140. }
  141. public static void Page_OnPreInit (Page p)
  142. {
  143. Assert.AreEqual (null, p.Header, "HeaderOnPreInit");
  144. p.Title = "PreInit";
  145. }
  146. [Test]
  147. [Category ("NunitWeb")]
  148. public void PageHeaderInit ()
  149. {
  150. Thread.Sleep (200);
  151. PageDelegate pd = new PageDelegate (CheckHeader);
  152. WebTest t = new WebTest (PageInvoker.CreateOnInit (pd));
  153. string html = t.Run ();
  154. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  155. string origHtml = @" <head id=""Head1""><title>
  156. Test
  157. </title></head>";
  158. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderInit");
  159. Thread.Sleep (200);
  160. WebTest.Unload ();
  161. }
  162. [Test]
  163. [Category ("NunitWeb")]
  164. public void PageHeaderInitComplete ()
  165. {
  166. Thread.Sleep (200);
  167. WebTest t = new WebTest ();
  168. PageDelegates pd = new PageDelegates ();
  169. pd.InitComplete = CheckHeader;
  170. t.Invoker = new PageInvoker (pd);
  171. string html = t.Run ();
  172. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  173. string origHtml = @" <head id=""Head1""><title>
  174. Test
  175. </title></head>";
  176. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderInitComplete");
  177. Thread.Sleep (200);
  178. WebTest.Unload ();
  179. }
  180. [Test]
  181. [Category ("NunitWeb")]
  182. public void PageHeaderPreLoad ()
  183. {
  184. Thread.Sleep (200);
  185. WebTest t = new WebTest ();
  186. PageDelegates pd = new PageDelegates ();
  187. pd.PreLoad = CheckHeader;
  188. t.Invoker = new PageInvoker (pd);
  189. string html = t.Run ();
  190. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  191. string origHtml = @" <head id=""Head1""><title>
  192. Test
  193. </title></head>";
  194. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderPreLoad");
  195. Thread.Sleep (200);
  196. WebTest.Unload ();
  197. }
  198. [Test]
  199. [Category ("NunitWeb")]
  200. public void PageHeaderLoad ()
  201. {
  202. Thread.Sleep (200);
  203. PageDelegate pd = new PageDelegate (CheckHeader);
  204. WebTest t = new WebTest (PageInvoker.CreateOnLoad (pd));
  205. string html = t.Run ();
  206. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  207. string origHtml = @" <head id=""Head1""><title>
  208. Test
  209. </title></head>";
  210. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderLoad");
  211. Thread.Sleep (200);
  212. WebTest.Unload ();
  213. }
  214. [Test]
  215. [Category ("NunitWeb")]
  216. public void PageHeaderLoadComplete ()
  217. {
  218. Thread.Sleep (200);
  219. WebTest t = new WebTest ();
  220. PageDelegates pd = new PageDelegates ();
  221. pd.LoadComplete = CheckHeader;
  222. t.Invoker = new PageInvoker (pd);
  223. string html = t.Run ();
  224. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  225. string origHtml = @" <head id=""Head1""><title>
  226. Test
  227. </title></head>";
  228. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderLoadComplete");
  229. Thread.Sleep (200);
  230. WebTest.Unload ();
  231. }
  232. [Test]
  233. [Category ("NunitWeb")]
  234. public void PageHeaderPreRender ()
  235. {
  236. Thread.Sleep (200);
  237. WebTest t = new WebTest ();
  238. PageDelegates pd = new PageDelegates ();
  239. pd.PreRender = CheckHeader;
  240. t.Invoker = new PageInvoker (pd);
  241. string html = t.Run ();
  242. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  243. string origHtml = @" <head id=""Head1""><title>
  244. Test
  245. </title></head>";
  246. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderPreRender");
  247. Thread.Sleep (200);
  248. WebTest.Unload ();
  249. }
  250. [Test]
  251. [Category ("NunitWeb")]
  252. public void PageHeaderPreRenderComplete ()
  253. {
  254. Thread.Sleep (200);
  255. WebTest t = new WebTest ();
  256. PageDelegates pd = new PageDelegates ();
  257. pd.PreRenderComplete = CheckHeader;
  258. t.Invoker = new PageInvoker (pd);
  259. string html = t.Run ();
  260. string newHtml = html.Substring (html.IndexOf ("<head"), (html.IndexOf ("<body") - html.IndexOf ("<head")));
  261. string origHtml = @" <head id=""Head1""><title>
  262. Test
  263. </title></head>";
  264. HtmlDiff.AssertAreEqual (origHtml, newHtml, "HeaderRenderPreRenderComplete");
  265. Thread.Sleep (200);
  266. WebTest.Unload ();
  267. }
  268. public static void CheckHeader (Page p)
  269. {
  270. Assert.AreEqual ("Untitled Page", p.Title, "CheckHeader#1");
  271. Assert.AreEqual ("Untitled Page", p.Header.Title, "CheckHeader#2");
  272. p.Title = "Test0";
  273. Assert.AreEqual ("Test0", p.Header.Title, "CheckHeader#3");
  274. p.Header.Title = "Test";
  275. Assert.AreEqual ("Test", p.Title, "CheckHeader#4");
  276. }
  277. #endif
  278. #if NET_2_0
  279. [Test]
  280. [Category ("NunitWeb")]
  281. public void Page_ValidationGroup () {
  282. new WebTest (PageInvoker.CreateOnLoad (Page_ValidationGroup_Load)).Run ();
  283. }
  284. public static void Page_ValidationGroup_Load (Page page) {
  285. TextBox textbox;
  286. BaseValidator val;
  287. textbox = new TextBox ();
  288. textbox.ID = "T1";
  289. textbox.ValidationGroup = "VG1";
  290. page.Form.Controls.Add (textbox);
  291. val = new RequiredFieldValidator ();
  292. val.ControlToValidate = "T1";
  293. val.ValidationGroup = "VG1";
  294. page.Form.Controls.Add (val);
  295. textbox = new TextBox ();
  296. textbox.ID = "T2";
  297. textbox.ValidationGroup = "VG2";
  298. page.Form.Controls.Add (textbox);
  299. val = new RequiredFieldValidator ();
  300. val.ControlToValidate = "T2";
  301. val.ValidationGroup = "VG2";
  302. page.Form.Controls.Add (val);
  303. textbox = new TextBox ();
  304. textbox.ID = "T3";
  305. page.Form.Controls.Add (textbox);
  306. val = new RequiredFieldValidator ();
  307. val.ControlToValidate = "T3";
  308. page.Form.Controls.Add (val);
  309. Assert.AreEqual (3, page.Validators.Count, "Page_ValidationGroup#1");
  310. Assert.AreEqual (1, page.GetValidators ("").Count, "Page_ValidationGroup#2");
  311. Assert.AreEqual (1, page.GetValidators (null).Count, "Page_ValidationGroup#3");
  312. Assert.AreEqual (0, page.GetValidators ("Fake").Count, "Page_ValidationGroup#4");
  313. Assert.AreEqual (1, page.GetValidators ("VG1").Count, "Page_ValidationGroup#5");
  314. Assert.AreEqual (1, page.GetValidators ("VG2").Count, "Page_ValidationGroup#6");
  315. }
  316. #endif
  317. #if NET_2_0
  318. // This test are testing validation fixture using RequiredFieldValidator for example
  319. [Test]
  320. [Category ("NunitWeb")]
  321. public void Page_ValidationCollection ()
  322. {
  323. WebTest t = new WebTest (PageInvoker.CreateOnLoad (ValidationCollectionload));
  324. t.Run ();
  325. }
  326. public static void ValidationCollectionload (Page p)
  327. {
  328. RequiredFieldValidator validator = new RequiredFieldValidator ();
  329. validator.ID = "v";
  330. RequiredFieldValidator validator1 = new RequiredFieldValidator ();
  331. validator.ID = "v1";
  332. p.Controls.Add (validator);
  333. p.Controls.Add (validator1);
  334. Assert.AreEqual (2, p.Validators.Count, "Validators collection count fail");
  335. Assert.AreEqual (true, p.Validators[0].IsValid, "Validators collection value#1 fail");
  336. Assert.AreEqual (true, p.Validators[1].IsValid, "Validators collection value#2 fail");
  337. }
  338. [Test]
  339. [Category ("NotWorking")]
  340. [Category ("NunitWeb")]
  341. public void Page_ValidatorTest1 ()
  342. {
  343. WebTest t = new WebTest ("PageValidationTest.aspx");
  344. string PageRenderHtml = t.Run ();
  345. FormRequest fr = new FormRequest (t.Response, "form1");
  346. fr.Controls.Add ("TextBox1");
  347. PageDelegates pd = new PageDelegates ();
  348. pd.PreRender = ValidatorTest1PreRender;
  349. t.Invoker = new PageInvoker (pd);
  350. fr.Controls["TextBox1"].Value = "";
  351. t.Request = fr;
  352. PageRenderHtml = t.Run ();
  353. Assert.IsNotNull(t.UserData, "Validate server side method not raised fail");
  354. ArrayList list = t.UserData as ArrayList;
  355. if (list == null)
  356. Assert.Fail ("User data not created fail#1");
  357. Assert.AreEqual (1, list.Count, "Just validate with no validation group must be called fail#1");
  358. Assert.AreEqual ("Validate", list[0].ToString (), "Validate with no validation group must be called fail#1");
  359. }
  360. public static void ValidatorTest1PreRender (Page p)
  361. {
  362. Assert.AreEqual (1, p.Validators.Count, "Validators count fail#1");
  363. Assert.AreEqual (false, p.Validators[0].IsValid, "Specific validator value filed#1");
  364. Assert.AreEqual (false, p.IsValid, "Page validation Failed#1");
  365. }
  366. [Test]
  367. [Category ("NotWorking")]
  368. [Category ("NunitWeb")]
  369. public void Page_ValidatorTest2 ()
  370. {
  371. WebTest t = new WebTest ("PageValidationTest.aspx");
  372. string PageRenderHtml = t.Run ();
  373. FormRequest fr = new FormRequest (t.Response, "form1");
  374. fr.Controls.Add ("TextBox1");
  375. PageDelegates pd = new PageDelegates ();
  376. pd.PreRender = ValidatorTest2PreRender;
  377. t.Invoker = new PageInvoker (pd);
  378. fr.Controls["TextBox1"].Value = "test";
  379. t.Request = fr;
  380. PageRenderHtml = t.Run ();
  381. Assert.IsNotNull ( t.UserData, "Validate server side method not raised fail#2");
  382. ArrayList list = t.UserData as ArrayList;
  383. if (list == null)
  384. Assert.Fail ("User data not created fail#2");
  385. Assert.AreEqual (1, list.Count, "Just validate with no validation group must be called fail#2");
  386. Assert.AreEqual ("Validate", list[0].ToString (), "Validate with no validation group must be called fail#2");
  387. }
  388. public static void ValidatorTest2PreRender (Page p)
  389. {
  390. Assert.AreEqual (1, p.Validators.Count, "Validators count fail#2");
  391. Assert.AreEqual (true, p.Validators[0].IsValid, "Specific validator value fail#2");
  392. Assert.AreEqual (true, p.IsValid, "Page validation Fail#2");
  393. }
  394. [Test]
  395. [Category ("NunitWeb")]
  396. public void Page_ValidatorTest3 ()
  397. {
  398. WebTest t = new WebTest (PageInvoker.CreateOnLoad (ValidatorTest3Load));
  399. t.Run ();
  400. }
  401. public static void ValidatorTest3Load (Page p)
  402. {
  403. TextBox tbx = new TextBox ();
  404. tbx.ID = "tbx";
  405. RequiredFieldValidator vld = new RequiredFieldValidator ();
  406. vld.ID = "vld";
  407. vld.ControlToValidate = "tbx";
  408. p.Controls.Add (tbx);
  409. p.Controls.Add (vld);
  410. vld.Validate ();
  411. Assert.AreEqual (false, p.Validators[0].IsValid, "RequiredField result fail #1");
  412. tbx.Text = "test";
  413. vld.Validate ();
  414. Assert.AreEqual (true, p.Validators[0].IsValid, "RequiredField result fail #2");
  415. }
  416. [Test]
  417. [Category ("NotWorking")]
  418. [Category ("NunitWeb")]
  419. public void Page_ValidatorTest4 ()
  420. {
  421. WebTest t = new WebTest ("PageValidationTest.aspx");
  422. string PageRenderHtml = t.Run ();
  423. FormRequest fr = new FormRequest (t.Response, "form1");
  424. fr.Controls.Add ("__EVENTTARGET");
  425. fr.Controls.Add ("__EVENTARGUMENT");
  426. fr.Controls.Add ("TextBox1");
  427. fr.Controls.Add ("Button1");
  428. PageDelegates pd = new PageDelegates ();
  429. pd.PreRender = ValidatorTest4PreRender;
  430. t.Invoker = new PageInvoker (pd);
  431. fr.Controls["__EVENTTARGET"].Value = "";
  432. fr.Controls["__EVENTARGUMENT"].Value = "";
  433. fr.Controls["TextBox1"].Value = "";
  434. fr.Controls["Button1"].Value = "Button";
  435. t.Request = fr;
  436. PageRenderHtml = t.Run ();
  437. Assert.IsNotNull (t.UserData, "Validate server side method not raised fail#3");
  438. ArrayList list = t.UserData as ArrayList;
  439. if (list == null)
  440. Assert.Fail ("User data not created fail#3");
  441. Assert.AreEqual (1, list.Count, "Just validate with validation group must be called fail#3");
  442. Assert.AreEqual ("Validate_WithGroup", list[0].ToString (), "Validate with validation group must be called fail#3");
  443. }
  444. public static void ValidatorTest4PreRender (Page p)
  445. {
  446. Assert.AreEqual (1, p.Validators.Count, "Validators count fail#3");
  447. Assert.AreEqual (false, p.Validators[0].IsValid, "Specific validator value filed#3");
  448. Assert.AreEqual (false, p.IsValid, "Page validation Failed#3");
  449. }
  450. [Test]
  451. [Category ("NotWorking")]
  452. [Category ("NunitWeb")]
  453. public void Page_ValidatorTest5 ()
  454. {
  455. WebTest t = new WebTest ("PageValidationTest.aspx");
  456. string PageRenderHtml = t.Run ();
  457. FormRequest fr = new FormRequest (t.Response, "form1");
  458. fr.Controls.Add ("__EVENTTARGET");
  459. fr.Controls.Add ("__EVENTARGUMENT");
  460. fr.Controls.Add ("TextBox1");
  461. fr.Controls.Add ("Button1");
  462. PageDelegates pd = new PageDelegates ();
  463. pd.PreRender = ValidatorTest5PreRender;
  464. t.Invoker = new PageInvoker (pd);
  465. fr.Controls["__EVENTTARGET"].Value = "";
  466. fr.Controls["__EVENTARGUMENT"].Value = "";
  467. fr.Controls["TextBox1"].Value = "Test";
  468. fr.Controls["Button1"].Value = "Button";
  469. t.Request = fr;
  470. PageRenderHtml = t.Run ();
  471. Assert.IsNotNull ( t.UserData, "Validate server side method not raised fail#3");
  472. ArrayList list = t.UserData as ArrayList;
  473. if (list == null)
  474. Assert.Fail ("User data not created fail#3");
  475. Assert.AreEqual (1, list.Count, "Just validate with validation group must be called fail#3");
  476. Assert.AreEqual ("Validate_WithGroup", list[0].ToString (), "Validate with validation group must be called fail#3");
  477. }
  478. public static void ValidatorTest5PreRender (Page p)
  479. {
  480. Assert.AreEqual (1, p.Validators.Count, "Validators count fail#3");
  481. Assert.AreEqual (true, p.Validators[0].IsValid, "Specific validator value filed#3");
  482. Assert.AreEqual (true, p.IsValid, "Page validation Failed#3");
  483. }
  484. [Test]
  485. [Category ("NotWorking")]
  486. [Category ("NunitWeb")]
  487. public void Page_ValidatorTest6 ()
  488. {
  489. WebTest t = new WebTest ("PageValidationTest.aspx");
  490. string PageRenderHtml = t.Run ();
  491. FormRequest fr = new FormRequest (t.Response, "form1");
  492. fr.Controls.Add ("__EVENTTARGET");
  493. fr.Controls.Add ("__EVENTARGUMENT");
  494. fr.Controls.Add ("TextBox1");
  495. fr.Controls.Add ("Button1");
  496. PageDelegates pd = new PageDelegates ();
  497. pd.PreRender = ValidatorTest6PreRender;
  498. pd.Load = ValidatorTest6Load;
  499. t.Invoker = new PageInvoker (pd);
  500. fr.Controls["__EVENTTARGET"].Value = "";
  501. fr.Controls["__EVENTARGUMENT"].Value = "";
  502. fr.Controls["TextBox1"].Value = "Test";
  503. fr.Controls["Button1"].Value = "Button";
  504. t.Request = fr;
  505. PageRenderHtml = t.Run ();
  506. Assert.IsNotNull (t.UserData, "Validate server side method not raised fail#3");
  507. ArrayList list = t.UserData as ArrayList;
  508. if (list == null)
  509. Assert.Fail ("User data not created fail#3");
  510. Assert.AreEqual (1, list.Count, "Just validate with validation group must be called fail#3");
  511. Assert.AreEqual ("Validate_WithGroup", list[0].ToString (), "Validate with validation group must be called fail#3");
  512. }
  513. public static void ValidatorTest6PreRender (Page p)
  514. {
  515. Assert.AreEqual (1, p.Validators.Count, "Validators count fail#3");
  516. Assert.AreEqual (false, p.Validators[0].IsValid, "Specific validator value filed#3");
  517. Assert.AreEqual (false, p.IsValid, "Page validation Failed#3");
  518. }
  519. public static void ValidatorTest6Load (Page p)
  520. {
  521. if (p.IsPostBack) {
  522. RequiredFieldValidator rfv = p.FindControl ("RequiredFieldValidator1") as RequiredFieldValidator;
  523. if (rfv == null)
  524. Assert.Fail ("RequiredFieldValidator does not created fail");
  525. rfv.InitialValue = "Test";
  526. }
  527. }
  528. [Test]
  529. [Category ("NotWorking")]
  530. [Category ("NunitWeb")]
  531. public void Page_ValidatorTest7 ()
  532. {
  533. WebTest t = new WebTest ("PageValidationTest.aspx");
  534. string PageRenderHtml = t.Run ();
  535. FormRequest fr = new FormRequest (t.Response, "form1");
  536. fr.Controls.Add ("__EVENTTARGET");
  537. fr.Controls.Add ("__EVENTARGUMENT");
  538. fr.Controls.Add ("TextBox1");
  539. fr.Controls.Add ("Button1");
  540. PageDelegates pd = new PageDelegates ();
  541. pd.PreRender = ValidatorTest7PreRender;
  542. pd.Load = ValidatorTest7Load;
  543. t.Invoker = new PageInvoker (pd);
  544. fr.Controls["__EVENTTARGET"].Value = "";
  545. fr.Controls["__EVENTARGUMENT"].Value = "";
  546. fr.Controls["TextBox1"].Value = "Test";
  547. fr.Controls["Button1"].Value = "Button";
  548. t.Request = fr;
  549. PageRenderHtml = t.Run ();
  550. Assert.IsNotNull (t.UserData, "Validate server side method not raised fail#4");
  551. ArrayList list = t.UserData as ArrayList;
  552. if (list == null)
  553. Assert.Fail ("User data not created fail#4");
  554. Assert.AreEqual (1, list.Count, "Just validate with validation group must be called fail#4");
  555. Assert.AreEqual ("Validate_WithGroup", list[0].ToString (), "Validate with validation group must be called fail#4");
  556. }
  557. public static void ValidatorTest7PreRender (Page p)
  558. {
  559. Assert.AreEqual (2, p.Validators.Count, "Validators count fail#4");
  560. Assert.AreEqual (true, p.Validators[0].IsValid, "Specific validator value filed_1#4");
  561. Assert.AreEqual (true, p.Validators[1].IsValid, "Specific validator value filed#4_2#4");
  562. Assert.AreEqual (true, p.IsValid, "Page validation Failed#4");
  563. }
  564. public static void ValidatorTest7Load (Page p)
  565. {
  566. RequiredFieldValidator validator = new RequiredFieldValidator ();
  567. validator.ID = "validator";
  568. validator.ControlToValidate = "TextBox1";
  569. validator.ValidationGroup = "fake";
  570. validator.InitialValue = "Test";
  571. p.Form.Controls.Add (validator);
  572. }
  573. [Test]
  574. [Category ("NotWorking")]
  575. [Category ("NunitWeb")]
  576. public void Page_Lifecycle ()
  577. {
  578. WebTest t = new WebTest ("PageLifecycleTest.aspx");
  579. string PageRenderHtml = t.Run ();
  580. ArrayList eventlist = t.UserData as ArrayList;
  581. if (eventlist == null)
  582. Assert.Fail ("User data does not been created fail");
  583. Assert.AreEqual ("OnPreInit", eventlist[0], "Live Cycle Flow #1");
  584. Assert.AreEqual ("OnInit", eventlist[1], "Live Cycle Flow #2");
  585. Assert.AreEqual ("OnInitComplete", eventlist[2], "Live Cycle Flow #3");
  586. Assert.AreEqual ("OnPreLoad", eventlist[3], "Live Cycle Flow #4");
  587. Assert.AreEqual ("OnLoad", eventlist[4], "Live Cycle Flow #5");
  588. Assert.AreEqual ("OnLoadComplete", eventlist[5], "Live Cycle Flow #6");
  589. Assert.AreEqual ("OnPreRender", eventlist[6], "Live Cycle Flow #7");
  590. Assert.AreEqual ("OnPreRenderComplete", eventlist[7], "Live Cycle Flow #8");
  591. Assert.AreEqual ("OnSaveStateComplete", eventlist[8], "Live Cycle Flow #9");
  592. Assert.AreEqual ("OnUnload", eventlist[9], "Live Cycle Flow #10");
  593. }
  594. #endif
  595. [TestFixtureTearDown]
  596. public void TearDown ()
  597. {
  598. WebTest.Unload ();
  599. }
  600. }
  601. }