[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Web / Test / System.Web.UI / ControlTest.cs
blobbe4fc108a89307a25e17ba74e2f493804821ddde
1 //
2 // Tests for System.Web.UI.Control
3 //
4 // Author:
5 // Peter Dennis Bartok (pbartok@novell.com)
6 // Gonzalo Paniagua Javier (gonzalo@novell.com)
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
33 using System;
34 using System.Collections;
35 using System.Drawing;
36 using System.IO;
37 using System.Globalization;
38 using System.Web;
39 using System.Web.UI;
40 using System.Web.UI.WebControls;
41 using MonoTests.SystemWeb.Framework;
42 using MonoTests.stand_alone.WebHarness;
44 using System.Web.UI.Adapters;
46 using System.Web.Routing;
48 namespace MonoTests.System.Web.UI
50 [TestFixture]
51 public class ControlTest
53 [Test]
54 public void DataBindingInterfaceTest ()
56 Control c;
57 DataBindingCollection db;
59 c = new Control ();
60 Assert.AreEqual (false, ((IDataBindingsAccessor) c).HasDataBindings, "DB1");
61 db = ((IDataBindingsAccessor) c).DataBindings;
62 Assert.IsNotNull (db, "DB2");
63 Assert.AreEqual (false, ((IDataBindingsAccessor) c).HasDataBindings, "DB3");
64 db.Add (new DataBinding ("property", typeof (bool), "expression"));
65 Assert.AreEqual (true, ((IDataBindingsAccessor) c).HasDataBindings);
68 [Test] // bug #82546
69 public void FindControl_NamingContainer ()
71 Control topControl = new NamingContainer ();
72 topControl.ID = "top";
74 Control controlLevel1A = new Control ();
75 controlLevel1A.ID = "Level1#A";
76 topControl.Controls.Add (controlLevel1A);
78 Control controlLevel1B = new Control ();
79 controlLevel1B.ID = "Level1#B";
80 topControl.Controls.Add (controlLevel1B);
82 Control controlLevel2AA = new Control ();
83 controlLevel2AA.ID = "Level2#AA";
84 controlLevel1A.Controls.Add (controlLevel2AA);
86 Control controlLevel2AB = new Control ();
87 controlLevel2AB.ID = "Level2#AB";
88 controlLevel1A.Controls.Add (controlLevel2AB);
90 Control foundControl = topControl.FindControl ("Level1#A");
91 Assert.IsNotNull (foundControl, "#A1");
92 Assert.AreSame (controlLevel1A, foundControl, "#A2");
94 foundControl = topControl.FindControl ("LEVEL1#B");
95 Assert.IsNotNull (foundControl, "#B1");
96 Assert.AreSame (controlLevel1B, foundControl, "#B2");
98 foundControl = topControl.FindControl ("LeVeL2#AB");
99 Assert.IsNotNull (foundControl, "#C1");
100 Assert.AreSame (controlLevel2AB, foundControl, "#C2");
102 foundControl = topControl.FindControl ("doesnotexist");
103 Assert.IsNull (foundControl, "#D1");
104 foundControl = topControl.FindControl ("top");
105 Assert.IsNull (foundControl, "#D2");
107 foundControl = controlLevel1A.FindControl ("Level2#AA");
108 Assert.IsNotNull (foundControl, "#E1");
109 Assert.AreSame (controlLevel2AA, foundControl, "#E2");
111 foundControl = controlLevel1A.FindControl ("LEveL2#ab");
112 Assert.IsNotNull (foundControl, "#F1");
113 Assert.AreSame (controlLevel2AB, foundControl, "#F2");
116 [Test]
117 public void UniqueID1 ()
119 // Standalone NC
120 Control nc = new MyNC ();
121 Assert.IsNull (nc.UniqueID, "nulltest");
124 [Test]
125 public void UniqueID1_1 () {
126 // Standalone NC
127 Control nc = new MyNC ();
128 Page p = new Page ();
129 p.Controls.Add (nc);
130 Assert.IsNotNull (nc.UniqueID, "notnull");
133 [Test]
134 public void UniqueID2 ()
136 // NC in NC
137 Control nc = new MyNC ();
138 Control nc2 = new MyNC ();
139 nc2.Controls.Add (nc);
140 Assert.IsNotNull (nc.UniqueID, "notnull");
141 Assert.IsTrue (nc.UniqueID.IndexOfAny (new char[] { ':', '$' }) == -1, "separator");
144 [Test]
145 public void UniqueID2_1 () {
146 // NC in NC
147 Control nc = new MyNC ();
148 Control nc2 = new MyNC ();
149 nc2.Controls.Add (nc);
150 Page p = new Page ();
151 p.Controls.Add (nc2);
152 Assert.IsNotNull (nc.UniqueID, "notnull");
153 Assert.IsTrue (nc.UniqueID.IndexOfAny (new char [] { ':', '$' }) != -1, "separator");
156 [Test]
157 public void UniqueID3 ()
159 // NC in control
160 Control control = new Control ();
161 Control nc = new MyNC ();
163 control.Controls.Add (nc);
164 Assert.IsNull (nc.UniqueID, "null");
167 [Test]
168 public void UniqueID4 ()
170 // NC in control
171 Control control = new Control ();
172 Control nc = new MyNC ();
174 nc.Controls.Add (control);
175 Assert.IsNotNull (control.UniqueID, "notnull");
178 [Test]
179 public void UniqueID5 ()
181 // NC in control
182 Control control = new Control ();
183 Control nc = new MyNC ();
184 Control nc2 = new MyNC ();
186 nc2.Controls.Add (nc);
187 nc.Controls.Add (control);
188 Assert.IsNotNull (control.UniqueID, "notnull");
189 Assert.IsNull (nc2.ID, "null-1");
190 Assert.IsNull (nc.ID, "null-2");
191 Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char[] { ':', '$' }), "separator");
194 [Test]
195 public void UniqueID6 () {
196 // NC in NC
197 Control nc = new MyNC ();
198 Page p = new Page ();
199 p.Controls.Add (nc);
200 Assert.IsNotNull (nc.UniqueID, "notnull");
202 Control c1 = new Control ();
203 Control c2 = new Control ();
204 nc.Controls.Add (c1);
205 nc.Controls.Add (c2);
206 string uid1_1 = c1.UniqueID;
207 string uid2_1 = c2.UniqueID;
209 nc.Controls.Clear ();
211 Assert.IsNull (c1.UniqueID);
212 Assert.IsNull (c2.UniqueID);
214 // ad in another order
215 nc.Controls.Add (c2);
216 nc.Controls.Add (c1);
217 string uid1_2 = c1.UniqueID;
218 string uid2_2 = c2.UniqueID;
220 Assert.IsFalse (uid1_1 == uid1_2);
221 Assert.IsFalse (uid2_1 == uid2_2);
222 Assert.AreEqual (uid1_1, uid2_2);
223 Assert.AreEqual (uid2_1, uid1_2);
225 nc.Controls.Remove (c1);
226 nc.Controls.Add (c1);
227 string uid1_3 = c1.UniqueID;
228 Assert.IsFalse (uid1_3 == uid1_2, "id was not reset");
230 EnsureIDControl c3 = new EnsureIDControl ();
231 nc.Controls.Add (c3);
232 string uid3_1 = c3.UniqueID;
233 c3.DoEnsureID ();
234 Assert.IsNotNull (c3.ID);
235 nc.Controls.Remove (c3);
236 nc.Controls.Add (c3);
237 string uid3_2 = c3.UniqueID;
238 Assert.IsNull (c3.ID);
239 Assert.IsFalse (uid3_1 == uid3_2, "id was not reset");
242 [Test]
243 public void ClientID ()
245 // NC in control
246 Control control = new Control ();
247 Control nc = new MyNC ();
248 Control nc2 = new MyNC ();
249 Control nc3 = new MyNC ();
251 nc3.Controls.Add (nc2);
252 nc2.Controls.Add (nc);
253 nc.Controls.Add (control);
254 string expected = "ctl00_ctl00_ctl00";
255 Assert.AreEqual (expected, control.ClientID, "ClientID");
258 // From bug #76919: Control uses _controls instead of
259 // Controls when RenderChildren is called.
260 [Test]
261 public void Controls1 ()
263 DerivedControl derived = new DerivedControl ();
264 derived.Controls.Add (new LiteralControl ("hola"));
265 StringWriter sw = new StringWriter ();
266 HtmlTextWriter htw = new HtmlTextWriter (sw);
267 derived.RenderControl (htw);
268 string result = sw.ToString ();
269 Assert.AreEqual ("", result, "#01");
272 [Test] // Bug #471305
273 [Category ("NunitWeb")]
274 public void NoDoubleOnInitOnRemoveAdd ()
276 WebTest.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx", "NoDoubleOnInitOnRemoveAdd.aspx");
277 WebTest.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx.cs", "NoDoubleOnInitOnRemoveAdd.aspx.cs");
278 WebTest t = new WebTest ("NoDoubleOnInitOnRemoveAdd.aspx");
279 string html = t.Run ();
281 Assert.AreEqual (-1, html.IndexOf ("<span>label</span><span>label</span>"), "#A1");
284 [Test]
285 [Category("NunitWeb")]
286 public void AppRelativeTemplateSourceDirectory ()
288 new WebTest(PageInvoker.CreateOnLoad(AppRelativeTemplateSourceDirectory_Load)).Run();
291 public static void AppRelativeTemplateSourceDirectory_Load(Page p)
293 Control ctrl = new Control();
294 Assert.AreEqual("~/", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#1");
295 ctrl.AppRelativeTemplateSourceDirectory = "~/Fake";
296 Assert.AreEqual("~/Fake", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#2");
299 [Test]
300 public void ApplyStyleSheetSkin ()
302 Page p = new Page ();
303 p.StyleSheetTheme = "";
304 Control c = new Control ();
305 c.ApplyStyleSheetSkin (p);
308 [Test]
309 [Category ("NunitWeb")]
310 public void ApplyStyleSheetSkin_1 ()
312 WebTest.CopyResource (GetType (), "Theme2.skin", "App_Themes/Theme2/Theme2.skin");
313 WebTest t = new WebTest ();
314 PageDelegates pd = new PageDelegates ();
315 pd.PreInit = ApplyStyleSheetSkin_PreInit;
316 pd.Load = ApplyStyleSheetSkin_Load;
317 t.Invoker = new PageInvoker (pd);
318 string str = t.Run ();
320 public static void ApplyStyleSheetSkin_PreInit (Page p)
322 p.Theme = "Theme2";
324 public static void ApplyStyleSheetSkin_Load (Page p)
326 Label lbl = new Label ();
327 lbl.ID = "StyleLbl";
328 lbl.SkinID = "red";
329 lbl.Text = "StyleLabel";
330 p.Controls.Add (lbl);
331 lbl.ApplyStyleSheetSkin (p);
332 Assert.AreEqual (Color.Red, lbl.ForeColor, "ApplyStyleSheetSkin_BackColor");
333 Assert.AreEqual ("TextFromSkinFile", lbl.Text, "ApplyStyleSheetSkin");
336 [Test]
337 [Category ("NunitWeb")]
338 public void ClearChildControlState ()
340 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildControlState_Load));
341 t.Run ();
342 FormRequest fr = new FormRequest (t.Response, "form1");
343 fr.Controls.Add ("__EVENTTARGET");
344 fr.Controls.Add ("__EVENTARGUMENT");
345 fr.Controls["__EVENTTARGET"].Value = "";
346 fr.Controls["__EVENTARGUMENT"].Value = "";
347 t.Request = fr;
348 t.Run ();
350 public static void ClearChildControlState_Load (Page p)
352 ControlWithState c1 = new ControlWithState ();
353 p.Form.Controls.Add (c1);
354 if (p.IsPostBack) {
355 c1.ClearChildControlState ();
357 ControlWithState c2 = new ControlWithState ();
358 c1.Controls.Add (c2);
359 ControlWithState c3 = new ControlWithState ();
360 c2.Controls.Add (c3);
361 if (!p.IsPostBack) {
362 c1.State = "State";
363 c2.State = "Cool";
364 c3.State = "SubCool";
366 else {
367 Assert.AreEqual ("State", c1.State, "ControlState#1");
368 Assert.AreEqual (null, c2.State, "ControlState#2");
369 Assert.AreEqual (null, c3.State, "ControlState#2");
373 [Test]
374 [Category ("NunitWeb")]
375 public void ClearChildState ()
377 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildState_Load));
378 t.Run ();
379 FormRequest fr = new FormRequest (t.Response, "form1");
380 fr.Controls.Add ("__EVENTTARGET");
381 fr.Controls.Add ("__EVENTARGUMENT");
382 fr.Controls["__EVENTTARGET"].Value = "";
383 fr.Controls["__EVENTARGUMENT"].Value = "";
384 t.Request = fr;
385 t.Run ();
387 public static void ClearChildState_Load (Page p)
389 ControlWithState c1 = new ControlWithState ();
390 p.Form.Controls.Add (c1);
391 if (p.IsPostBack) {
392 c1.ClearChildState ();
394 ControlWithState c2 = new ControlWithState ();
395 c1.Controls.Add (c2);
396 ControlWithState c3 = new ControlWithState ();
397 c2.Controls.Add (c3);
398 if (!p.IsPostBack) {
399 c1.State = "State";
400 c2.State = "Cool";
401 c2.Viewstate = "Very Cool";
402 c3.State = "SubCool";
403 c3.Viewstate = "Super Cool";
405 else {
406 Assert.AreEqual ("State", c1.State, "ClearChildState#1");
407 Assert.AreEqual (null, c2.State, "ClearChildState#2");
408 Assert.AreEqual (null, c3.State, "ClearChildState#3");
409 Assert.AreEqual (null, c2.Viewstate, "ClearChildState#4");
410 Assert.AreEqual (null, c3.Viewstate, "ClearChildState#5");
414 [Test]
415 public void DataBind ()
417 MyNC ctrl = new MyNC ();
418 ctrl.DataBinding += new EventHandler (ctrl_DataBinding);
419 Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
420 ctrl.DataBind (false);
421 Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
422 ctrl.DataBind (true);
423 Assert.AreEqual (true, _eventDataBinding, "After DataBinding");
425 bool _eventDataBinding;
426 void ctrl_DataBinding (object sender, EventArgs e)
428 _eventDataBinding = true;
431 [Test]
432 public void DataBindChildren ()
434 MyNC ctrl1 = new MyNC ();
435 Control ctrl2 = new Control ();
436 Control ctrl3 = new Control ();
437 ctrl2.DataBinding += new EventHandler (ctrl2_DataBinding);
438 ctrl3.DataBinding += new EventHandler (ctrl3_DataBinding);
440 ctrl2.Controls.Add (ctrl3);
441 ctrl1.Controls.Add (ctrl2);
442 Assert.AreEqual (false, _eventChild1, "Before DataBinding#1");
443 Assert.AreEqual (false, _eventChild2, "Before DataBinding#2");
444 ctrl1.DataBindChildren ();
445 Assert.AreEqual (true, _eventChild1, "After DataBinding#1");
446 Assert.AreEqual (true, _eventChild2, "After DataBinding#2");
448 bool _eventChild1;
449 bool _eventChild2;
450 void ctrl3_DataBinding (object sender, EventArgs e)
452 _eventChild1 = true;
454 void ctrl2_DataBinding (object sender, EventArgs e)
456 _eventChild2 = true;
459 [Test]
460 public void EnsureID ()
462 MyNC ctrl = new MyNC ();
463 MyNC ctrl1 = new MyNC ();
464 ctrl.Controls.Add (ctrl1);
465 Page p = new Page ();
466 p.Controls.Add (ctrl);
467 ctrl.EnsureID ();
468 if (String.IsNullOrEmpty (ctrl.ID))
469 Assert.Fail ("EnsureID#1");
470 ctrl1.EnsureID ();
471 if (String.IsNullOrEmpty (ctrl1.ID))
472 Assert.Fail ("EnsureID#2");
475 [Test]
476 [Category("NotWorking")]
477 public void Focus ()
479 WebTest t = new WebTest (PageInvoker.CreateOnLoad (Focus_Load));
480 string html = t.Run ();
481 Assert.AreEqual (3, contain (html, "TestBox"), "Focus script not created");
484 public static void Focus_Load (Page p)
486 TextBox tbx = new TextBox ();
487 tbx.ID = "TestBox";
488 p.Controls.Add (tbx);
489 tbx.Focus ();
491 int contain (string orig, string compare)
493 if (orig.IndexOf (compare) == -1)
494 return 0;
495 return 1 + contain (orig.Substring (orig.IndexOf (compare) + compare.Length), compare);
498 [Test]
499 public void HasEvent ()
501 MyNC ctrl1 = new MyNC ();
502 Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#1");
503 EventHandler ctrl_hdlr = new EventHandler (ctrl1_Init);
504 ctrl1.Init += new EventHandler (ctrl1_Init);
505 ctrl1.Init += ctrl_hdlr;
506 Assert.AreEqual (true, ctrl1.HasEvents (), "HasEvent#2");
507 // Dosn't work than removed handler
508 //ctrl1.Init -= ctrl_hdlr;
509 //Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#3");
511 void ctrl1_Init (object sender, EventArgs e)
513 throw new Exception ("The method or operation is not implemented.");
516 [Test]
517 public void IsViewStateEnabled ()
519 DerivedControl c = new DerivedControl ();
520 Assert.IsTrue (c.DoIsViewStateEnabled);
521 Page p = new Page ();
522 c.Page = p;
523 p.Controls.Add (c);
524 Assert.IsTrue (c.DoIsViewStateEnabled);
525 p.EnableViewState = false;
526 Assert.IsFalse (c.DoIsViewStateEnabled);
529 [Test]
530 [Category ("NunitWeb")]
531 public void ControlState ()
533 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState_Load));
534 t.Run ();
535 FormRequest fr = new FormRequest (t.Response, "form1");
536 fr.Controls.Add ("__EVENTTARGET");
537 fr.Controls.Add ("__EVENTARGUMENT");
538 fr.Controls["__EVENTTARGET"].Value = "";
539 fr.Controls["__EVENTARGUMENT"].Value = "";
540 t.Request = fr;
541 t.Run ();
543 public static void ControlState_Load (Page p)
545 ControlWithState c1 = new ControlWithState ();
546 ControlWithState c2 = new ControlWithState ();
547 c1.Controls.Add (c2);
548 p.Form.Controls.Add (c1);
549 if (!p.IsPostBack) {
550 c1.State = "State";
551 c2.State = "Cool";
553 else {
554 ControlWithState c3 = new ControlWithState ();
555 p.Form.Controls.Add (c3);
556 Assert.AreEqual ("State", c1.State, "ControlState");
557 Assert.AreEqual ("Cool", c2.State, "ControlState");
561 [Test]
562 [Category ("NunitWeb")]
563 public void ControlState2 () {
564 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState2_Load));
565 t.Run ();
566 FormRequest fr = new FormRequest (t.Response, "form1");
567 fr.Controls.Add ("__EVENTTARGET");
568 fr.Controls.Add ("__EVENTARGUMENT");
569 fr.Controls ["__EVENTTARGET"].Value = "";
570 fr.Controls ["__EVENTARGUMENT"].Value = "";
571 t.Request = fr;
572 t.Run ();
574 fr = new FormRequest (t.Response, "form1");
575 fr.Controls.Add ("__EVENTTARGET");
576 fr.Controls.Add ("__EVENTARGUMENT");
577 fr.Controls ["__EVENTTARGET"].Value = "";
578 fr.Controls ["__EVENTARGUMENT"].Value = "";
579 t.Request = fr;
580 t.Run ();
582 public static void ControlState2_Load (Page p) {
583 ControlWithState parent = new ControlWithState ();
584 p.Form.Controls.Add (parent);
585 if (!p.IsPostBack) {
586 // emulate DataBind
587 parent.Controls.Clear ();
588 parent.ClearChildControlState ();
589 ControlWithState c1 = new ControlWithState ();
590 ControlWithState c2 = new ControlWithState ();
591 parent.Controls.Add (c1);
592 parent.Controls.Add (c2);
593 c1.State = "State1_1";
594 c2.State = "State1_2";
595 parent.State = "First";
597 else if (parent.State == "First") {
598 // emulate DataBind
599 parent.Controls.Clear ();
600 parent.ClearChildControlState ();
601 ControlWithState c1 = new ControlWithState ();
602 ControlWithState c2 = new ControlWithState ();
603 parent.Controls.Add (c1);
604 parent.Controls.Add (c2);
605 c1.State = "State2_1";
606 c2.State = "State2_2";
607 parent.State = "Second";
609 else {
610 // emulate CrerateChildControl only
611 parent.Controls.Clear ();
612 ControlWithState c1 = new ControlWithState ();
613 ControlWithState c2 = new ControlWithState ();
614 parent.Controls.Add (c1);
615 parent.Controls.Add (c2);
617 Assert.AreEqual ("State2_1", c1.State, "ControlState#1");
618 Assert.AreEqual ("State2_2", c2.State, "ControlState#2");
622 [Test]
623 public void ClientIDSeparator ()
625 DerivedControl ctrl = new DerivedControl ();
626 Assert.AreEqual (95, (int) ctrl.ClientIDSeparator, "ClientIDSeparator");
629 [Test]
630 public void IDSeparator ()
632 DerivedControl ctrl = new DerivedControl ();
633 Assert.AreEqual (36, (int) ctrl.IdSeparator, "IDSeparator");
636 [Test]
637 [Category ("NunitWeb")]
638 public void IsChildControlStateCleared ()
640 WebTest t = new WebTest (PageInvoker.CreateOnLoad (IsChildControlStateCleared_Load));
641 t.Run ();
642 FormRequest fr = new FormRequest (t.Response, "form1");
643 fr.Controls.Add ("__EVENTTARGET");
644 fr.Controls.Add ("__EVENTARGUMENT");
645 fr.Controls["__EVENTTARGET"].Value = "";
646 fr.Controls["__EVENTARGUMENT"].Value = "";
647 t.Request = fr;
648 t.Run ();
650 public static void IsChildControlStateCleared_Load (Page p)
652 ControlWithState c1 = new ControlWithState ();
653 p.Form.Controls.Add (c1);
654 if (p.IsPostBack) {
655 Assert.IsFalse (c1.IsChildControlStateCleared, "ControlState#1");
656 c1.ClearChildControlState ();
657 Assert.IsTrue (c1.IsChildControlStateCleared, "ControlState#1");
659 ControlWithState c2 = new ControlWithState ();
660 c1.Controls.Add (c2);
661 ControlWithState c3 = new ControlWithState ();
662 c2.Controls.Add (c3);
663 if (p.IsPostBack) {
664 Assert.IsFalse (c2.IsChildControlStateCleared, "ControlState#1");
665 Assert.IsFalse (c3.IsChildControlStateCleared, "ControlState#1");
667 if (!p.IsPostBack) {
668 c1.State = "State";
669 c2.State = "Cool";
670 c3.State = "SubCool";
674 [Test]
675 [Category ("NunitWeb")]
676 public void LoadViewStateByID ()
678 ControlWithState c1 = new ControlWithState ();
679 ControlWithState c2 = new ControlWithState ();
680 c1.Controls.Add (c2);
681 Assert.AreEqual (false, c1.LoadViewStateByID, "LoadViewStateByID#1");
684 [Test]
685 [Category ("NunitWeb")]
686 public void OpenFile ()
688 WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFile_Load));
689 t.Run ();
691 public static void OpenFile_Load (Page p)
693 DerivedControl ctrl = new DerivedControl ();
694 Stream strem = ctrl.OpenFile ("~/MyPage.aspx");
695 Assert.IsNotNull (strem, "OpenFile failed");
698 [Test]
699 [Category ("NunitWeb")]
700 [ExpectedException (typeof (FileNotFoundException))]
701 public void OpenFile_Exception ()
703 WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFileException_Load));
704 t.Run ();
706 public static void OpenFileException_Load (Page p)
708 DerivedControl ctrl = new DerivedControl ();
709 Stream strem = ctrl.OpenFile ("~/Fake.tmp");
712 [Test]
713 [Category ("NunitWeb")]
714 public void ResolveClientUrl ()
716 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveClientUrl_Load));
717 string html = t.Run ();
719 public static void ResolveClientUrl_Load (Page p)
721 Control ctrl = new Control ();
722 p.Controls.Add (ctrl);
723 string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
724 Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
726 Assert.AreEqual ("", ctrl.ResolveClientUrl (""), "empty string");
728 Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~"), "~");
729 Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~/"), "~/");
731 Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
732 Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
733 Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
734 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
735 Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
736 Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
737 Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
738 Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
739 Assert.AreEqual ("NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
740 Assert.AreEqual ("NunitWeb/../MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
741 Assert.AreEqual ("NunitWeb/./MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
742 Assert.AreEqual ("http://example.com/", ctrl.ResolveClientUrl ("http://example.com/"), "ResolveClientUrl Failed");
744 Assert.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
745 Assert.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
747 Assert.AreEqual ("./MyPage.aspx", ctrl.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
748 Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
752 [Test]
753 [Category ("NunitWeb")]
754 public void ResolveClientUrl2 ()
756 WebTest t = new WebTest ("ResolveUrl.aspx");
757 PageDelegates delegates = new PageDelegates ();
758 delegates.Load = ResolveClientUrl2_Load;
759 t.Invoker = new PageInvoker (delegates);
760 string html = t.Run ();
763 public static void ResolveClientUrl2_Load (Page p)
765 Control uc = p.FindControl ("WebUserControl1");
766 Control ctrl = uc.FindControl ("Label");
768 string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
769 Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
771 Assert.AreEqual ("", ctrl.ResolveClientUrl (""), "empty string");
773 Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~"), "~");
774 Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~/"), "~/");
776 Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
777 Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
778 Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
779 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
780 Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
781 Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
782 Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
783 Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
784 Assert.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
785 Assert.AreEqual ("Folder/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
786 Assert.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
787 Assert.AreEqual ("http://example.com/", ctrl.ResolveClientUrl ("http://example.com/"), "ResolveClientUrl Failed");
789 Assert.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
790 Assert.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
792 Assert.AreEqual ("Folder/MyPage.aspx", ctrl.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
793 Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
797 [Test]
798 [Category ("NunitWeb")]
799 public void ResolveUrl ()
801 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveUrl_Load));
802 string html = t.Run ();
805 public static void ResolveUrl_Load (Page p)
807 string appPath = "/NunitWeb";
808 Control ctrl = new Control ();
809 p.Controls.Add (ctrl);
810 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
812 Assert.AreEqual ("", ctrl.ResolveUrl (""), "empty string");
814 Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~"), "~");
815 Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~/"), "~/");
817 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
818 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
819 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
820 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
821 Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
822 Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
823 Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
824 Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
825 Assert.AreEqual (appPath + "/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
826 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
827 Assert.AreEqual (appPath + "/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
828 Assert.AreEqual ("http://example.com/", ctrl.ResolveUrl ("http://example.com/"), "ResolveClientUrl Failed");
830 Assert.AreEqual (appPath + "/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
831 Assert.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
833 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
834 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
836 Assert.AreEqual ("/", ctrl.ResolveUrl (".."), "..");
837 Assert.AreEqual ("/", ctrl.ResolveUrl ("../"), "../");
840 [Test]
841 [Category ("NunitWeb")]
842 public void ResolveUrl2 ()
844 WebTest t = new WebTest ("ResolveUrl.aspx");
845 PageDelegates delegates = new PageDelegates ();
846 delegates.Load = ResolveUrl2_Load;
847 t.Invoker = new PageInvoker (delegates);
848 string html = t.Run ();
851 public static void ResolveUrl2_Load (Page p)
853 string appPath = "/NunitWeb";
854 Control uc = p.FindControl ("WebUserControl1");
855 Control ctrl = uc.FindControl ("Label");
857 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
859 Assert.AreEqual ("", ctrl.ResolveUrl (""), "empty string");
861 Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~"), "~");
862 Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~/"), "~/");
864 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
865 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
866 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
867 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
868 Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
869 Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
870 Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
871 Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
872 Assert.AreEqual (appPath + "/Folder/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
873 Assert.AreEqual (appPath + "/Folder/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
874 Assert.AreEqual (appPath + "/Folder/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
875 Assert.AreEqual ("http://example.com/", ctrl.ResolveUrl ("http://example.com/"), "ResolveClientUrl Failed");
877 Assert.AreEqual (appPath + "/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
878 Assert.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
880 Assert.AreEqual (appPath + "/Folder/MyPage.aspx", ctrl.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
881 Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
883 Assert.AreEqual (appPath + "/", ctrl.ResolveUrl (".."), "..");
884 Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("../"), "../");
885 Assert.AreEqual ("/", ctrl.ResolveUrl ("../.."), "../..");
886 Assert.AreEqual ("/", ctrl.ResolveUrl ("../../"), "../../");
887 Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("../../MyPage.aspx"), "../../MyPage.aspx");
890 [Test]
891 [Category ("NotWorking")] // Not implemented exception
892 public void ResolveAdapter_2 ()
894 DerivedControl ctrl = new DerivedControl ();
895 Assert.AreEqual (null, ctrl.ResolveAdapter (), "ResolveAdapter");
898 [Test]
899 public void EnableTheming ()
901 DerivedControl ctrl = new DerivedControl ();
902 Assert.AreEqual (true, ctrl.EnableTheming, "EnableTheming#1");
903 ctrl.EnableTheming = false;
904 Assert.AreEqual (false, ctrl.EnableTheming, "EnableTheming#2");
907 [Test]
908 public void BindingContainer ()
910 ControlWithTemplate c = new ControlWithTemplate ();
911 c.Template = new CompiledTemplateBuilder (new BuildTemplateMethod (BindingContainer_BuildTemplate));
913 // cause CreateChildControls called
914 c.FindControl ("stam");
917 static void BindingContainer_BuildTemplate (Control control)
919 Control child1 = new Control ();
920 control.Controls.Add (child1);
922 Assert.IsTrue (Object.ReferenceEquals (child1.NamingContainer, control), "NamingContainer #1");
923 Assert.IsTrue (Object.ReferenceEquals (child1.BindingContainer, control), "BindingContainer #1");
925 NamingContainer nc = new NamingContainer ();
926 Control child2 = new Control ();
927 nc.Controls.Add (child2);
928 control.Controls.Add (nc);
930 Assert.IsTrue (Object.ReferenceEquals (child2.NamingContainer, nc), "NamingContainer #2");
931 Assert.IsTrue (Object.ReferenceEquals (child2.BindingContainer, nc), "BindingContainer #2");
933 // DetailsViewPagerRow marked to be not BindingContainer
934 DetailsViewPagerRow row = new DetailsViewPagerRow (0, DataControlRowType.Pager, DataControlRowState.Normal);
935 TableCell cell = new TableCell ();
936 Control child3 = new Control ();
937 cell.Controls.Add (child3);
938 row.Cells.Add (cell);
939 control.Controls.Add (row);
941 Assert.IsTrue (Object.ReferenceEquals (child3.NamingContainer, row), "NamingContainer #3");
942 Assert.IsTrue (Object.ReferenceEquals (child3.BindingContainer, control), "BindingContainer #3");
944 [Test]
945 public void Control_Adapter ()
947 MyNC ctr = new MyNC ();
948 Assert.AreEqual (null, ctr.Adapter (), "Adapter");
950 [Test]
951 public void ChildControlsCreated () {
952 ChildControlsCreatedControl ctr = new ChildControlsCreatedControl ();
953 ctr.Controls.Add (new Control ());
954 //ctr.DoEnsureChildControls ();
956 Assert.AreEqual (1, ctr.Controls.Count, "ChildControlsCreated#1");
957 ctr.SetChildControlsCreated (false);
958 Assert.AreEqual (1, ctr.Controls.Count, "ChildControlsCreated#2");
961 [Test (Description="Bug #594238")]
962 public void OverridenControlsPropertyAndPostBack_Bug594238 ()
964 WebTest t = new WebTest ("OverridenControlsPropertyAndPostBack_Bug594238.aspx");
965 t.Run ();
967 FormRequest fr = new FormRequest (t.Response, "form1");
968 fr.Controls.Add ("__EVENTTARGET");
969 fr.Controls.Add ("__EVENTARGUMENT");
970 fr.Controls ["__EVENTTARGET"].Value = "container$children$lb";
971 fr.Controls ["__EVENTARGUMENT"].Value = String.Empty;
972 t.Request = fr;
973 string originalHtml = "<span id=\"container\"><a id=\"container_children_lb\" href=\"javascript:__doPostBack(&#39;container$children$lb&#39;,&#39;&#39;)\">Woot! I got clicked!</a></span><hr/>";
974 string pageHtml = t.Run ();
975 string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
977 HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
980 [TestFixtureTearDown]
981 public void Tear_down ()
983 WebTest.Unload ();
986 [TestFixtureSetUp]
987 public void TestFixtureSetUp ()
989 WebTest.CopyResource (GetType (), "ResolveUrl.aspx", "ResolveUrl.aspx");
990 WebTest.CopyResource (GetType (), "ResolveUrl.ascx", "Folder/ResolveUrl.ascx");
991 WebTest.CopyResource (GetType (), "OverridenControlsPropertyAndPostBack_Bug594238.aspx", "OverridenControlsPropertyAndPostBack_Bug594238.aspx");
994 [Test]
995 public void GetRouteUrl_Object ()
997 var t = new WebTest (PageInvoker.CreateOnLoad (GetRouteUrl_Object_Load));
998 t.Run ();
1001 public static void GetRouteUrl_Object_Load (Page p)
1003 RouteTable.Routes.Clear ();
1005 var ctl = new Control ();
1006 object obj = new { foo = "one", bar = "two" };
1007 string path = ctl.GetRouteUrl (obj);
1008 Assert.IsNull (path, "#A1");
1010 RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1011 path = ctl.GetRouteUrl (obj);
1012 Assert.IsNotNull (path, "#A2-1");
1013 Assert.AreEqual ("/NunitWeb/one-two", path, "#A2-2");
1015 path = ctl.GetRouteUrl ((object)null);
1016 Assert.IsNull (path, "#A3");
1019 [Test]
1020 public void GetRouteUrl_RouteValueDictionary ()
1022 var t = new WebTest (PageInvoker.CreateOnLoad (GetRouteUrl_RouteValueDictionary_Load));
1023 t.Run ();
1026 public static void GetRouteUrl_RouteValueDictionary_Load (Page p)
1028 RouteTable.Routes.Clear ();
1030 var ctl = new Control ();
1031 var rvd = new RouteValueDictionary {
1032 {"foo", "one"},
1033 {"bar", "two"}
1035 string path = ctl.GetRouteUrl (rvd);
1036 Assert.IsNull (path, "#A1");
1038 RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1039 path = ctl.GetRouteUrl (rvd);
1040 Assert.IsNotNull (path, "#A2-1");
1041 Assert.AreEqual ("/NunitWeb/one-two", path, "#A2-2");
1043 path = ctl.GetRouteUrl ((RouteValueDictionary) null);
1044 Assert.IsNull (path, "#A3");
1047 [Test]
1048 public void GetRouteUrl_String_Object ()
1050 var t = new WebTest (PageInvoker.CreateOnLoad (GetRouteUrl_String_Object_Load));
1051 t.Run ();
1054 public static void GetRouteUrl_String_Object_Load (Page p)
1056 RouteTable.Routes.Clear ();
1058 var ctl = new Control ();
1059 object obj = new { foo = "one", bar = "two" };
1060 string path;
1061 Assert.Throws<ArgumentException> (() => {
1062 path = ctl.GetRouteUrl ("myroute1", obj);
1063 }, "#A1");
1065 RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1066 RouteTable.Routes.Add ("myroute1", new Route ("{bar}-{foo}", new PageRouteHandler ("~/default.aspx")));
1067 path = ctl.GetRouteUrl ("myroute1", obj);
1068 Assert.IsNotNull (path, "#A2-1");
1069 Assert.AreEqual ("/NunitWeb/two-one", path, "#A2-2");
1071 path = ctl.GetRouteUrl ("myroute1", (object) null);
1072 Assert.IsNull (path, "#A3");
1075 [Test]
1076 public void GetRouteUrl_String_RouteValueDictionary ()
1078 var t = new WebTest (PageInvoker.CreateOnLoad (GetRouteUrl_String_RouteValueDictionary_Load));
1079 t.Run ();
1082 public static void GetRouteUrl_String_RouteValueDictionary_Load (Page p)
1084 RouteTable.Routes.Clear ();
1086 var ctl = new Control ();
1087 var rvd = new RouteValueDictionary {
1088 {"foo", "one"},
1089 {"bar", "two"}
1091 string path;
1092 Assert.Throws<ArgumentException> (() => {
1093 path = ctl.GetRouteUrl ("myroute", rvd);
1094 }, "#A1");
1096 RouteTable.Routes.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1097 RouteTable.Routes.Add ("myroute", new Route ("{bar}-{foo}", new PageRouteHandler ("~/default.aspx")));
1098 path = ctl.GetRouteUrl ("myroute", rvd);
1099 Assert.IsNotNull (path, "#A2-1");
1100 Assert.AreEqual ("/NunitWeb/two-one", path, "#A2-2");
1102 path = ctl.GetRouteUrl ("myroute", (RouteValueDictionary) null);
1103 Assert.IsNull (path, "#A3-1");
1105 path = ctl.GetRouteUrl (null, (RouteValueDictionary) null);
1106 Assert.IsNull (path, "#A3-2");
1108 path = ctl.GetRouteUrl (String.Empty, (RouteValueDictionary) null);
1109 Assert.IsNull (path, "#A3-3");
1111 #region helpcalsses
1112 class ControlWithState : Control
1114 string _state;
1116 public string State
1118 get { return _state; }
1119 set { _state = value; }
1122 public string Viewstate {
1123 get { return (string) ViewState ["Viewstate"]; }
1124 set { ViewState ["Viewstate"] = value; }
1127 protected internal override void OnInit (EventArgs e)
1129 base.OnInit (e);
1130 Page.RegisterRequiresControlState (this);
1133 protected internal override object SaveControlState ()
1135 return State;
1138 protected internal override void LoadControlState (object savedState)
1140 State = (string) savedState;
1143 public new void ClearChildState ()
1145 base.ClearChildState ();
1148 public new void ClearChildControlState ()
1150 base.ClearChildControlState ();
1153 public new bool IsChildControlStateCleared
1155 get { return base.IsChildControlStateCleared; }
1158 public new bool LoadViewStateByID
1160 get { return base.LoadViewStateByID; }
1164 class MyNC : Control, INamingContainer
1166 public ControlAdapter Adapter ()
1168 return base.Adapter;
1171 public new void DataBind (bool opt)
1173 base.DataBind (opt);
1176 public new void DataBindChildren ()
1178 base.DataBindChildren ();
1181 public new void EnsureID ()
1183 base.EnsureID ();
1186 public new bool HasEvents ()
1188 return base.HasEvents ();
1192 class DerivedControl : Control
1194 ControlCollection coll;
1196 public DerivedControl ()
1198 coll = new ControlCollection (this);
1201 public override ControlCollection Controls
1203 get { return coll; }
1206 public bool DoIsViewStateEnabled
1208 get { return IsViewStateEnabled; }
1211 public new char ClientIDSeparator
1213 get { return base.ClientIDSeparator; }
1216 public new char IdSeparator
1218 get { return base.IdSeparator; }
1221 public new Stream OpenFile (string path)
1223 return base.OpenFile (path);
1226 public new ControlAdapter ResolveAdapter ()
1228 return base.ResolveAdapter ();
1232 class NamingContainer : Control, INamingContainer
1236 class ControlWithTemplate : Control
1238 ITemplate _template;
1240 [TemplateContainer (typeof (TemplateContainer))]
1241 public ITemplate Template
1243 get { return _template; }
1244 set { _template = value; }
1247 protected internal override void CreateChildControls ()
1249 Controls.Clear ();
1251 TemplateContainer container = new TemplateContainer ();
1252 Controls.Add (container);
1254 if (Template != null)
1255 Template.InstantiateIn (container);
1259 class TemplateContainer : Control, INamingContainer
1262 #endregion
1265 public class Customadaptercontrol : Control
1267 public new ControlAdapter Adapter {
1268 get { return base.Adapter; }
1271 public new ControlAdapter ResolveAdapter ()
1273 return base.ResolveAdapter ();
1277 public class Customadapter : ControlAdapter
1281 class EnsureIDControl : Control {
1282 public void DoEnsureID () {
1283 EnsureID ();
1287 public class ChildControlsCreatedControl : Control
1289 protected internal override void CreateChildControls () {
1290 Controls.Add (new Control ());
1293 public void DoEnsureChildControls () {
1294 EnsureChildControls ();
1297 public void SetChildControlsCreated (bool value) {
1298 ChildControlsCreated = value;