2 // Tests for System.Web.UI.Control
5 // Peter Dennis Bartok (pbartok@novell.com)
6 // Gonzalo Paniagua Javier (gonzalo@novell.com)
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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
;
34 using System
.Collections
;
37 using System
.Globalization
;
40 using System
.Web
.UI
.WebControls
;
41 using MonoTests
.SystemWeb
.Framework
;
42 using MonoTests
.stand_alone
.WebHarness
;
43 using MonoTests
.Common
;
46 using System
.Web
.UI
.Adapters
;
50 using System
.Web
.Routing
;
53 namespace MonoTests
.System
.Web
.UI
56 public class ControlTest
59 public void DataBindingInterfaceTest ()
62 DataBindingCollection db
;
65 Assert
.AreEqual (false, ((IDataBindingsAccessor
) c
).HasDataBindings
, "DB1");
66 db
= ((IDataBindingsAccessor
) c
).DataBindings
;
67 Assert
.IsNotNull (db
, "DB2");
68 Assert
.AreEqual (false, ((IDataBindingsAccessor
) c
).HasDataBindings
, "DB3");
69 db
.Add (new DataBinding ("property", typeof (bool), "expression"));
70 Assert
.AreEqual (true, ((IDataBindingsAccessor
) c
).HasDataBindings
);
74 public void FindControl_NamingContainer ()
76 Control topControl
= new NamingContainer ();
77 topControl
.ID
= "top";
79 Control controlLevel1A
= new Control ();
80 controlLevel1A
.ID
= "Level1#A";
81 topControl
.Controls
.Add (controlLevel1A
);
83 Control controlLevel1B
= new Control ();
84 controlLevel1B
.ID
= "Level1#B";
85 topControl
.Controls
.Add (controlLevel1B
);
87 Control controlLevel2AA
= new Control ();
88 controlLevel2AA
.ID
= "Level2#AA";
89 controlLevel1A
.Controls
.Add (controlLevel2AA
);
91 Control controlLevel2AB
= new Control ();
92 controlLevel2AB
.ID
= "Level2#AB";
93 controlLevel1A
.Controls
.Add (controlLevel2AB
);
95 Control foundControl
= topControl
.FindControl ("Level1#A");
96 Assert
.IsNotNull (foundControl
, "#A1");
97 Assert
.AreSame (controlLevel1A
, foundControl
, "#A2");
99 foundControl
= topControl
.FindControl ("LEVEL1#B");
100 Assert
.IsNotNull (foundControl
, "#B1");
101 Assert
.AreSame (controlLevel1B
, foundControl
, "#B2");
103 foundControl
= topControl
.FindControl ("LeVeL2#AB");
104 Assert
.IsNotNull (foundControl
, "#C1");
105 Assert
.AreSame (controlLevel2AB
, foundControl
, "#C2");
107 foundControl
= topControl
.FindControl ("doesnotexist");
108 Assert
.IsNull (foundControl
, "#D1");
109 foundControl
= topControl
.FindControl ("top");
110 Assert
.IsNull (foundControl
, "#D2");
112 foundControl
= controlLevel1A
.FindControl ("Level2#AA");
113 Assert
.IsNotNull (foundControl
, "#E1");
114 Assert
.AreSame (controlLevel2AA
, foundControl
, "#E2");
116 foundControl
= controlLevel1A
.FindControl ("LEveL2#ab");
117 Assert
.IsNotNull (foundControl
, "#F1");
118 Assert
.AreSame (controlLevel2AB
, foundControl
, "#F2");
122 public void UniqueID1 ()
125 Control nc
= new MyNC ();
126 Assert
.IsNull (nc
.UniqueID
, "nulltest");
130 public void UniqueID1_1 () {
132 Control nc
= new MyNC ();
133 Page p
= new Page ();
135 Assert
.IsNotNull (nc
.UniqueID
, "notnull");
139 public void UniqueID2 ()
142 Control nc
= new MyNC ();
143 Control nc2
= new MyNC ();
144 nc2
.Controls
.Add (nc
);
145 Assert
.IsNotNull (nc
.UniqueID
, "notnull");
146 Assert
.IsTrue (nc
.UniqueID
.IndexOfAny (new char[] { ':', '$' }
) == -1, "separator");
150 public void UniqueID2_1 () {
152 Control nc
= new MyNC ();
153 Control nc2
= new MyNC ();
154 nc2
.Controls
.Add (nc
);
155 Page p
= new Page ();
156 p
.Controls
.Add (nc2
);
157 Assert
.IsNotNull (nc
.UniqueID
, "notnull");
158 Assert
.IsTrue (nc
.UniqueID
.IndexOfAny (new char [] { ':', '$' }
) != -1, "separator");
162 public void UniqueID3 ()
165 Control control
= new Control ();
166 Control nc
= new MyNC ();
168 control
.Controls
.Add (nc
);
169 Assert
.IsNull (nc
.UniqueID
, "null");
173 public void UniqueID4 ()
176 Control control
= new Control ();
177 Control nc
= new MyNC ();
179 nc
.Controls
.Add (control
);
180 Assert
.IsNotNull (control
.UniqueID
, "notnull");
184 public void UniqueID5 ()
187 Control control
= new Control ();
188 Control nc
= new MyNC ();
189 Control nc2
= new MyNC ();
191 nc2
.Controls
.Add (nc
);
192 nc
.Controls
.Add (control
);
193 Assert
.IsNotNull (control
.UniqueID
, "notnull");
194 Assert
.IsNull (nc2
.ID
, "null-1");
195 Assert
.IsNull (nc
.ID
, "null-2");
196 Assert
.IsTrue (-1 != control
.UniqueID
.IndexOfAny (new char[] { ':', '$' }
), "separator");
200 public void UniqueID6 () {
202 Control nc
= new MyNC ();
203 Page p
= new Page ();
205 Assert
.IsNotNull (nc
.UniqueID
, "notnull");
207 Control c1
= new Control ();
208 Control c2
= new Control ();
209 nc
.Controls
.Add (c1
);
210 nc
.Controls
.Add (c2
);
211 string uid1_1
= c1
.UniqueID
;
212 string uid2_1
= c2
.UniqueID
;
214 nc
.Controls
.Clear ();
216 Assert
.IsNull (c1
.UniqueID
);
217 Assert
.IsNull (c2
.UniqueID
);
219 // ad in another order
220 nc
.Controls
.Add (c2
);
221 nc
.Controls
.Add (c1
);
222 string uid1_2
= c1
.UniqueID
;
223 string uid2_2
= c2
.UniqueID
;
225 Assert
.IsFalse (uid1_1
== uid1_2
);
226 Assert
.IsFalse (uid2_1
== uid2_2
);
227 Assert
.AreEqual (uid1_1
, uid2_2
);
228 Assert
.AreEqual (uid2_1
, uid1_2
);
230 nc
.Controls
.Remove (c1
);
231 nc
.Controls
.Add (c1
);
232 string uid1_3
= c1
.UniqueID
;
233 Assert
.IsFalse (uid1_3
== uid1_2
, "id was not reset");
236 EnsureIDControl c3
= new EnsureIDControl ();
237 nc
.Controls
.Add (c3
);
238 string uid3_1
= c3
.UniqueID
;
240 Assert
.IsNotNull (c3
.ID
);
241 nc
.Controls
.Remove (c3
);
242 nc
.Controls
.Add (c3
);
243 string uid3_2
= c3
.UniqueID
;
244 Assert
.IsNull (c3
.ID
);
245 Assert
.IsFalse (uid3_1
== uid3_2
, "id was not reset");
250 public void ClientID ()
253 Control control
= new Control ();
254 Control nc
= new MyNC ();
255 Control nc2
= new MyNC ();
256 Control nc3
= new MyNC ();
258 nc3
.Controls
.Add (nc2
);
259 nc2
.Controls
.Add (nc
);
260 nc
.Controls
.Add (control
);
262 string expected
= "ctl00_ctl00_ctl00";
264 string expected
= "_ctl0__ctl0__ctl0";
266 Assert
.AreEqual (expected
, control
.ClientID
, "ClientID");
269 // From bug #76919: Control uses _controls instead of
270 // Controls when RenderChildren is called.
272 public void Controls1 ()
274 DerivedControl derived
= new DerivedControl ();
275 derived
.Controls
.Add (new LiteralControl ("hola"));
276 StringWriter sw
= new StringWriter ();
277 HtmlTextWriter htw
= new HtmlTextWriter (sw
);
278 derived
.RenderControl (htw
);
279 string result
= sw
.ToString ();
280 Assert
.AreEqual ("", result
, "#01");
283 [Test
] // Bug #471305
284 [Category ("NunitWeb")]
285 public void NoDoubleOnInitOnRemoveAdd ()
287 WebTest
.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx", "NoDoubleOnInitOnRemoveAdd.aspx");
288 WebTest
.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx.cs", "NoDoubleOnInitOnRemoveAdd.aspx.cs");
289 WebTest t
= new WebTest ("NoDoubleOnInitOnRemoveAdd.aspx");
290 string html
= t
.Run ();
292 Assert
.AreEqual (-1, html
.IndexOf ("<span>label</span><span>label</span>"), "#A1");
297 [Category("NunitWeb")]
298 public void AppRelativeTemplateSourceDirectory ()
300 new WebTest(PageInvoker
.CreateOnLoad(AppRelativeTemplateSourceDirectory_Load
)).Run();
303 public static void AppRelativeTemplateSourceDirectory_Load(Page p
)
305 Control ctrl
= new Control();
306 Assert
.AreEqual("~/", ctrl
.AppRelativeTemplateSourceDirectory
, "AppRelativeTemplateSourceDirectory#1");
307 ctrl
.AppRelativeTemplateSourceDirectory
= "~/Fake";
308 Assert
.AreEqual("~/Fake", ctrl
.AppRelativeTemplateSourceDirectory
, "AppRelativeTemplateSourceDirectory#2");
312 public void ApplyStyleSheetSkin ()
314 Page p
= new Page ();
315 p
.StyleSheetTheme
= "";
316 Control c
= new Control ();
317 c
.ApplyStyleSheetSkin (p
);
321 [Category ("NunitWeb")]
322 public void ApplyStyleSheetSkin_1 ()
324 WebTest
.CopyResource (GetType (), "Theme2.skin", "App_Themes/Theme2/Theme2.skin");
325 WebTest t
= new WebTest ();
326 PageDelegates pd
= new PageDelegates ();
327 pd
.PreInit
= ApplyStyleSheetSkin_PreInit
;
328 pd
.Load
= ApplyStyleSheetSkin_Load
;
329 t
.Invoker
= new PageInvoker (pd
);
330 string str
= t
.Run ();
332 public static void ApplyStyleSheetSkin_PreInit (Page p
)
336 public static void ApplyStyleSheetSkin_Load (Page p
)
338 Label lbl
= new Label ();
341 lbl
.Text
= "StyleLabel";
342 p
.Controls
.Add (lbl
);
343 lbl
.ApplyStyleSheetSkin (p
);
344 Assert
.AreEqual (Color
.Red
, lbl
.ForeColor
, "ApplyStyleSheetSkin_BackColor");
345 Assert
.AreEqual ("TextFromSkinFile", lbl
.Text
, "ApplyStyleSheetSkin");
349 [Category ("NunitWeb")]
350 public void ClearChildControlState ()
352 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (ClearChildControlState_Load
));
354 FormRequest fr
= new FormRequest (t
.Response
, "form1");
355 fr
.Controls
.Add ("__EVENTTARGET");
356 fr
.Controls
.Add ("__EVENTARGUMENT");
357 fr
.Controls
["__EVENTTARGET"].Value
= "";
358 fr
.Controls
["__EVENTARGUMENT"].Value
= "";
362 public static void ClearChildControlState_Load (Page p
)
364 ControlWithState c1
= new ControlWithState ();
365 p
.Form
.Controls
.Add (c1
);
367 c1
.ClearChildControlState ();
369 ControlWithState c2
= new ControlWithState ();
370 c1
.Controls
.Add (c2
);
371 ControlWithState c3
= new ControlWithState ();
372 c2
.Controls
.Add (c3
);
376 c3
.State
= "SubCool";
379 Assert
.AreEqual ("State", c1
.State
, "ControlState#1");
380 Assert
.AreEqual (null, c2
.State
, "ControlState#2");
381 Assert
.AreEqual (null, c3
.State
, "ControlState#2");
386 [Category ("NunitWeb")]
387 public void ClearChildState ()
389 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (ClearChildState_Load
));
391 FormRequest fr
= new FormRequest (t
.Response
, "form1");
392 fr
.Controls
.Add ("__EVENTTARGET");
393 fr
.Controls
.Add ("__EVENTARGUMENT");
394 fr
.Controls
["__EVENTTARGET"].Value
= "";
395 fr
.Controls
["__EVENTARGUMENT"].Value
= "";
399 public static void ClearChildState_Load (Page p
)
401 ControlWithState c1
= new ControlWithState ();
402 p
.Form
.Controls
.Add (c1
);
404 c1
.ClearChildState ();
406 ControlWithState c2
= new ControlWithState ();
407 c1
.Controls
.Add (c2
);
408 ControlWithState c3
= new ControlWithState ();
409 c2
.Controls
.Add (c3
);
413 c2
.Viewstate
= "Very Cool";
414 c3
.State
= "SubCool";
415 c3
.Viewstate
= "Super Cool";
418 Assert
.AreEqual ("State", c1
.State
, "ClearChildState#1");
419 Assert
.AreEqual (null, c2
.State
, "ClearChildState#2");
420 Assert
.AreEqual (null, c3
.State
, "ClearChildState#3");
421 Assert
.AreEqual (null, c2
.Viewstate
, "ClearChildState#4");
422 Assert
.AreEqual (null, c3
.Viewstate
, "ClearChildState#5");
427 public void DataBind ()
429 MyNC ctrl
= new MyNC ();
430 ctrl
.DataBinding
+= new EventHandler (ctrl_DataBinding
);
431 Assert
.AreEqual (false, _eventDataBinding
, "Before DataBinding");
432 ctrl
.DataBind (false);
433 Assert
.AreEqual (false, _eventDataBinding
, "Before DataBinding");
434 ctrl
.DataBind (true);
435 Assert
.AreEqual (true, _eventDataBinding
, "After DataBinding");
437 bool _eventDataBinding
;
438 void ctrl_DataBinding (object sender
, EventArgs e
)
440 _eventDataBinding
= true;
444 public void DataBindChildren ()
446 MyNC ctrl1
= new MyNC ();
447 Control ctrl2
= new Control ();
448 Control ctrl3
= new Control ();
449 ctrl2
.DataBinding
+= new EventHandler (ctrl2_DataBinding
);
450 ctrl3
.DataBinding
+= new EventHandler (ctrl3_DataBinding
);
452 ctrl2
.Controls
.Add (ctrl3
);
453 ctrl1
.Controls
.Add (ctrl2
);
454 Assert
.AreEqual (false, _eventChild1
, "Before DataBinding#1");
455 Assert
.AreEqual (false, _eventChild2
, "Before DataBinding#2");
456 ctrl1
.DataBindChildren ();
457 Assert
.AreEqual (true, _eventChild1
, "After DataBinding#1");
458 Assert
.AreEqual (true, _eventChild2
, "After DataBinding#2");
462 void ctrl3_DataBinding (object sender
, EventArgs e
)
466 void ctrl2_DataBinding (object sender
, EventArgs e
)
472 public void EnsureID ()
474 MyNC ctrl
= new MyNC ();
475 MyNC ctrl1
= new MyNC ();
476 ctrl
.Controls
.Add (ctrl1
);
477 Page p
= new Page ();
478 p
.Controls
.Add (ctrl
);
480 if (String
.IsNullOrEmpty (ctrl
.ID
))
481 Assert
.Fail ("EnsureID#1");
483 if (String
.IsNullOrEmpty (ctrl1
.ID
))
484 Assert
.Fail ("EnsureID#2");
488 [Category("NotWorking")]
491 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (Focus_Load
));
492 string html
= t
.Run ();
493 Assert
.AreEqual (3, contain (html
, "TestBox"), "Focus script not created");
496 public static void Focus_Load (Page p
)
498 TextBox tbx
= new TextBox ();
500 p
.Controls
.Add (tbx
);
503 int contain (string orig
, string compare
)
505 if (orig
.IndexOf (compare
) == -1)
507 return 1 + contain (orig
.Substring (orig
.IndexOf (compare
) + compare
.Length
), compare
);
511 public void HasEvent ()
513 MyNC ctrl1
= new MyNC ();
514 Assert
.AreEqual (false, ctrl1
.HasEvents (), "HasEvent#1");
515 EventHandler ctrl_hdlr
= new EventHandler (ctrl1_Init
);
516 ctrl1
.Init
+= new EventHandler (ctrl1_Init
);
517 ctrl1
.Init
+= ctrl_hdlr
;
518 Assert
.AreEqual (true, ctrl1
.HasEvents (), "HasEvent#2");
519 // Dosn't work than removed handler
520 //ctrl1.Init -= ctrl_hdlr;
521 //Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#3");
523 void ctrl1_Init (object sender
, EventArgs e
)
525 throw new Exception ("The method or operation is not implemented.");
529 public void IsViewStateEnabled ()
531 DerivedControl c
= new DerivedControl ();
532 Assert
.IsTrue (c
.DoIsViewStateEnabled
);
533 Page p
= new Page ();
536 Assert
.IsTrue (c
.DoIsViewStateEnabled
);
537 p
.EnableViewState
= false;
538 Assert
.IsFalse (c
.DoIsViewStateEnabled
);
542 [Category ("NunitWeb")]
543 public void ControlState ()
545 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (ControlState_Load
));
547 FormRequest fr
= new FormRequest (t
.Response
, "form1");
548 fr
.Controls
.Add ("__EVENTTARGET");
549 fr
.Controls
.Add ("__EVENTARGUMENT");
550 fr
.Controls
["__EVENTTARGET"].Value
= "";
551 fr
.Controls
["__EVENTARGUMENT"].Value
= "";
555 public static void ControlState_Load (Page p
)
557 ControlWithState c1
= new ControlWithState ();
558 ControlWithState c2
= new ControlWithState ();
559 c1
.Controls
.Add (c2
);
560 p
.Form
.Controls
.Add (c1
);
566 ControlWithState c3
= new ControlWithState ();
567 p
.Form
.Controls
.Add (c3
);
568 Assert
.AreEqual ("State", c1
.State
, "ControlState");
569 Assert
.AreEqual ("Cool", c2
.State
, "ControlState");
574 [Category ("NunitWeb")]
575 public void ControlState2 () {
576 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (ControlState2_Load
));
578 FormRequest fr
= new FormRequest (t
.Response
, "form1");
579 fr
.Controls
.Add ("__EVENTTARGET");
580 fr
.Controls
.Add ("__EVENTARGUMENT");
581 fr
.Controls
["__EVENTTARGET"].Value
= "";
582 fr
.Controls
["__EVENTARGUMENT"].Value
= "";
586 fr
= new FormRequest (t
.Response
, "form1");
587 fr
.Controls
.Add ("__EVENTTARGET");
588 fr
.Controls
.Add ("__EVENTARGUMENT");
589 fr
.Controls
["__EVENTTARGET"].Value
= "";
590 fr
.Controls
["__EVENTARGUMENT"].Value
= "";
594 public static void ControlState2_Load (Page p
) {
595 ControlWithState parent
= new ControlWithState ();
596 p
.Form
.Controls
.Add (parent
);
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
= "State1_1";
606 c2
.State
= "State1_2";
607 parent
.State
= "First";
609 else if (parent
.State
== "First") {
611 parent
.Controls
.Clear ();
612 parent
.ClearChildControlState ();
613 ControlWithState c1
= new ControlWithState ();
614 ControlWithState c2
= new ControlWithState ();
615 parent
.Controls
.Add (c1
);
616 parent
.Controls
.Add (c2
);
617 c1
.State
= "State2_1";
618 c2
.State
= "State2_2";
619 parent
.State
= "Second";
622 // emulate CrerateChildControl only
623 parent
.Controls
.Clear ();
624 ControlWithState c1
= new ControlWithState ();
625 ControlWithState c2
= new ControlWithState ();
626 parent
.Controls
.Add (c1
);
627 parent
.Controls
.Add (c2
);
629 Assert
.AreEqual ("State2_1", c1
.State
, "ControlState#1");
630 Assert
.AreEqual ("State2_2", c2
.State
, "ControlState#2");
635 public void ClientIDSeparator ()
637 DerivedControl ctrl
= new DerivedControl ();
638 Assert
.AreEqual (95, (int) ctrl
.ClientIDSeparator
, "ClientIDSeparator");
642 public void IDSeparator ()
644 DerivedControl ctrl
= new DerivedControl ();
645 Assert
.AreEqual (36, (int) ctrl
.IdSeparator
, "IDSeparator");
649 [Category ("NunitWeb")]
650 public void IsChildControlStateCleared ()
652 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (IsChildControlStateCleared_Load
));
654 FormRequest fr
= new FormRequest (t
.Response
, "form1");
655 fr
.Controls
.Add ("__EVENTTARGET");
656 fr
.Controls
.Add ("__EVENTARGUMENT");
657 fr
.Controls
["__EVENTTARGET"].Value
= "";
658 fr
.Controls
["__EVENTARGUMENT"].Value
= "";
662 public static void IsChildControlStateCleared_Load (Page p
)
664 ControlWithState c1
= new ControlWithState ();
665 p
.Form
.Controls
.Add (c1
);
667 Assert
.IsFalse (c1
.IsChildControlStateCleared
, "ControlState#1");
668 c1
.ClearChildControlState ();
669 Assert
.IsTrue (c1
.IsChildControlStateCleared
, "ControlState#1");
671 ControlWithState c2
= new ControlWithState ();
672 c1
.Controls
.Add (c2
);
673 ControlWithState c3
= new ControlWithState ();
674 c2
.Controls
.Add (c3
);
676 Assert
.IsFalse (c2
.IsChildControlStateCleared
, "ControlState#1");
677 Assert
.IsFalse (c3
.IsChildControlStateCleared
, "ControlState#1");
682 c3
.State
= "SubCool";
687 [Category ("NunitWeb")]
688 public void LoadViewStateByID ()
690 ControlWithState c1
= new ControlWithState ();
691 ControlWithState c2
= new ControlWithState ();
692 c1
.Controls
.Add (c2
);
693 Assert
.AreEqual (false, c1
.LoadViewStateByID
, "LoadViewStateByID#1");
697 [Category ("NunitWeb")]
698 public void OpenFile ()
700 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (OpenFile_Load
));
703 public static void OpenFile_Load (Page p
)
705 DerivedControl ctrl
= new DerivedControl ();
706 Stream strem
= ctrl
.OpenFile ("~/MyPage.aspx");
707 Assert
.IsNotNull (strem
, "OpenFile failed");
711 [Category ("NunitWeb")]
712 [ExpectedException (typeof (FileNotFoundException
))]
713 public void OpenFile_Exception ()
715 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (OpenFileException_Load
));
718 public static void OpenFileException_Load (Page p
)
720 DerivedControl ctrl
= new DerivedControl ();
721 Stream strem
= ctrl
.OpenFile ("~/Fake.tmp");
725 [Category ("NunitWeb")]
726 public void ResolveClientUrl ()
728 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (ResolveClientUrl_Load
));
729 string html
= t
.Run ();
731 public static void ResolveClientUrl_Load (Page p
)
733 Control ctrl
= new Control ();
734 p
.Controls
.Add (ctrl
);
735 string url
= ctrl
.ResolveClientUrl ("~/MyPage.aspx");
736 Assert
.AreEqual ("MyPage.aspx", url
, "ResolveClientUrl Failed");
738 Assert
.AreEqual ("", ctrl
.ResolveClientUrl (""), "empty string");
740 Assert
.AreEqual ("./", ctrl
.ResolveClientUrl ("~"), "~");
741 Assert
.AreEqual ("./", ctrl
.ResolveClientUrl ("~/"), "~/");
743 Assert
.AreEqual ("../MyPage.aspx", ctrl
.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
744 Assert
.AreEqual ("../MyPage.aspx", ctrl
.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
745 Assert
.AreEqual ("MyPage.aspx", ctrl
.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
746 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
747 Assert
.AreEqual ("/folder/MyPage.aspx", ctrl
.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
748 Assert
.AreEqual ("/NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
749 Assert
.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
750 Assert
.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl
.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
751 Assert
.AreEqual ("NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
752 Assert
.AreEqual ("NunitWeb/../MyPage.aspx", ctrl
.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
753 Assert
.AreEqual ("NunitWeb/./MyPage.aspx", ctrl
.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
754 Assert
.AreEqual ("http://google.com/", ctrl
.ResolveClientUrl ("http://google.com/"), "ResolveClientUrl Failed");
756 Assert
.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl
.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
757 Assert
.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl
.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
759 Assert
.AreEqual ("./MyPage.aspx", ctrl
.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
760 Assert
.AreEqual ("../MyPage.aspx", ctrl
.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
765 [Category ("NunitWeb")]
766 public void ResolveClientUrl2 ()
768 WebTest t
= new WebTest ("ResolveUrl.aspx");
769 PageDelegates delegates
= new PageDelegates ();
770 delegates
.Load
= ResolveClientUrl2_Load
;
771 t
.Invoker
= new PageInvoker (delegates
);
772 string html
= t
.Run ();
775 public static void ResolveClientUrl2_Load (Page p
)
777 Control uc
= p
.FindControl ("WebUserControl1");
778 Control ctrl
= uc
.FindControl ("Label");
780 string url
= ctrl
.ResolveClientUrl ("~/MyPage.aspx");
781 Assert
.AreEqual ("MyPage.aspx", url
, "ResolveClientUrl Failed");
783 Assert
.AreEqual ("", ctrl
.ResolveClientUrl (""), "empty string");
785 Assert
.AreEqual ("./", ctrl
.ResolveClientUrl ("~"), "~");
786 Assert
.AreEqual ("./", ctrl
.ResolveClientUrl ("~/"), "~/");
788 Assert
.AreEqual ("../MyPage.aspx", ctrl
.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
789 Assert
.AreEqual ("../MyPage.aspx", ctrl
.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
790 Assert
.AreEqual ("MyPage.aspx", ctrl
.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
791 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
792 Assert
.AreEqual ("/folder/MyPage.aspx", ctrl
.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
793 Assert
.AreEqual ("/NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
794 Assert
.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
795 Assert
.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl
.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
796 Assert
.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
797 Assert
.AreEqual ("Folder/MyPage.aspx", ctrl
.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
798 Assert
.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl
.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
799 Assert
.AreEqual ("http://google.com/", ctrl
.ResolveClientUrl ("http://google.com/"), "ResolveClientUrl Failed");
801 Assert
.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl
.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
802 Assert
.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl
.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
804 Assert
.AreEqual ("Folder/MyPage.aspx", ctrl
.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
805 Assert
.AreEqual ("MyPage.aspx", ctrl
.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
810 [Category ("NunitWeb")]
811 public void ResolveUrl ()
813 WebTest t
= new WebTest (PageInvoker
.CreateOnLoad (ResolveUrl_Load
));
814 string html
= t
.Run ();
817 public static void ResolveUrl_Load (Page p
)
819 string appPath
= "/NunitWeb";
820 Control ctrl
= new Control ();
821 p
.Controls
.Add (ctrl
);
822 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
824 Assert
.AreEqual ("", ctrl
.ResolveUrl (""), "empty string");
826 Assert
.AreEqual (appPath
+ "/", ctrl
.ResolveUrl ("~"), "~");
827 Assert
.AreEqual (appPath
+ "/", ctrl
.ResolveUrl ("~/"), "~/");
829 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
830 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
831 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
832 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
833 Assert
.AreEqual ("/folder/MyPage.aspx", ctrl
.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
834 Assert
.AreEqual ("/NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
835 Assert
.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
836 Assert
.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl
.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
837 Assert
.AreEqual (appPath
+ "/NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
838 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
839 Assert
.AreEqual (appPath
+ "/NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
840 Assert
.AreEqual ("http://google.com/", ctrl
.ResolveUrl ("http://google.com/"), "ResolveClientUrl Failed");
842 Assert
.AreEqual (appPath
+ "/MyPage.aspx?param=val&yes=no", ctrl
.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
843 Assert
.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl
.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
845 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
846 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
848 Assert
.AreEqual ("/", ctrl
.ResolveUrl (".."), "..");
849 Assert
.AreEqual ("/", ctrl
.ResolveUrl ("../"), "../");
853 [Category ("NunitWeb")]
854 public void ResolveUrl2 ()
856 WebTest t
= new WebTest ("ResolveUrl.aspx");
857 PageDelegates delegates
= new PageDelegates ();
858 delegates
.Load
= ResolveUrl2_Load
;
859 t
.Invoker
= new PageInvoker (delegates
);
860 string html
= t
.Run ();
863 public static void ResolveUrl2_Load (Page p
)
865 string appPath
= "/NunitWeb";
866 Control uc
= p
.FindControl ("WebUserControl1");
867 Control ctrl
= uc
.FindControl ("Label");
869 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
871 Assert
.AreEqual ("", ctrl
.ResolveUrl (""), "empty string");
873 Assert
.AreEqual (appPath
+ "/", ctrl
.ResolveUrl ("~"), "~");
874 Assert
.AreEqual (appPath
+ "/", ctrl
.ResolveUrl ("~/"), "~/");
876 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
877 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
878 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
879 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
880 Assert
.AreEqual ("/folder/MyPage.aspx", ctrl
.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
881 Assert
.AreEqual ("/NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
882 Assert
.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
883 Assert
.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl
.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
884 Assert
.AreEqual (appPath
+ "/Folder/NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
885 Assert
.AreEqual (appPath
+ "/Folder/MyPage.aspx", ctrl
.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
886 Assert
.AreEqual (appPath
+ "/Folder/NunitWeb/MyPage.aspx", ctrl
.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
887 Assert
.AreEqual ("http://google.com/", ctrl
.ResolveUrl ("http://google.com/"), "ResolveClientUrl Failed");
889 Assert
.AreEqual (appPath
+ "/MyPage.aspx?param=val&yes=no", ctrl
.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
890 Assert
.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl
.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
892 Assert
.AreEqual (appPath
+ "/Folder/MyPage.aspx", ctrl
.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
893 Assert
.AreEqual (appPath
+ "/MyPage.aspx", ctrl
.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
895 Assert
.AreEqual (appPath
+ "/", ctrl
.ResolveUrl (".."), "..");
896 Assert
.AreEqual (appPath
+ "/", ctrl
.ResolveUrl ("../"), "../");
897 Assert
.AreEqual ("/", ctrl
.ResolveUrl ("../.."), "../..");
898 Assert
.AreEqual ("/", ctrl
.ResolveUrl ("../../"), "../../");
899 Assert
.AreEqual ("/MyPage.aspx", ctrl
.ResolveUrl ("../../MyPage.aspx"), "../../MyPage.aspx");
903 [Category ("NotWorking")] // Not implemented exception
904 public void ResolveAdapter_2 ()
906 DerivedControl ctrl
= new DerivedControl ();
907 Assert
.AreEqual (null, ctrl
.ResolveAdapter (), "ResolveAdapter");
911 public void EnableTheming ()
913 DerivedControl ctrl
= new DerivedControl ();
914 Assert
.AreEqual (true, ctrl
.EnableTheming
, "EnableTheming#1");
915 ctrl
.EnableTheming
= false;
916 Assert
.AreEqual (false, ctrl
.EnableTheming
, "EnableTheming#2");
921 public void BindingContainer ()
923 ControlWithTemplate c
= new ControlWithTemplate ();
924 c
.Template
= new CompiledTemplateBuilder (new BuildTemplateMethod (BindingContainer_BuildTemplate
));
926 // cause CreateChildControls called
927 c
.FindControl ("stam");
930 static void BindingContainer_BuildTemplate (Control control
)
932 Control child1
= new Control ();
933 control
.Controls
.Add (child1
);
935 Assert
.IsTrue (Object
.ReferenceEquals (child1
.NamingContainer
, control
), "NamingContainer #1");
936 Assert
.IsTrue (Object
.ReferenceEquals (child1
.BindingContainer
, control
), "BindingContainer #1");
938 NamingContainer nc
= new NamingContainer ();
939 Control child2
= new Control ();
940 nc
.Controls
.Add (child2
);
941 control
.Controls
.Add (nc
);
943 Assert
.IsTrue (Object
.ReferenceEquals (child2
.NamingContainer
, nc
), "NamingContainer #2");
944 Assert
.IsTrue (Object
.ReferenceEquals (child2
.BindingContainer
, nc
), "BindingContainer #2");
947 // DetailsViewPagerRow marked to be not BindingContainer
948 DetailsViewPagerRow row
= new DetailsViewPagerRow (0, DataControlRowType
.Pager
, DataControlRowState
.Normal
);
949 TableCell cell
= new TableCell ();
950 Control child3
= new Control ();
951 cell
.Controls
.Add (child3
);
952 row
.Cells
.Add (cell
);
953 control
.Controls
.Add (row
);
955 Assert
.IsTrue (Object
.ReferenceEquals (child3
.NamingContainer
, row
), "NamingContainer #3");
956 Assert
.IsTrue (Object
.ReferenceEquals (child3
.BindingContainer
, control
), "BindingContainer #3");
961 public void Control_Adapter ()
963 MyNC ctr
= new MyNC ();
964 Assert
.AreEqual (null, ctr
.Adapter (), "Adapter");
968 public void ChildControlsCreated () {
969 ChildControlsCreatedControl ctr
= new ChildControlsCreatedControl ();
970 ctr
.Controls
.Add (new Control ());
971 //ctr.DoEnsureChildControls ();
973 Assert
.AreEqual (1, ctr
.Controls
.Count
, "ChildControlsCreated#1");
974 ctr
.SetChildControlsCreated (false);
975 Assert
.AreEqual (1, ctr
.Controls
.Count
, "ChildControlsCreated#2");
979 [Test (Description
="Bug #594238")]
980 public void OverridenControlsPropertyAndPostBack_Bug594238 ()
982 WebTest t
= new WebTest ("OverridenControlsPropertyAndPostBack_Bug594238.aspx");
985 FormRequest fr
= new FormRequest (t
.Response
, "form1");
986 fr
.Controls
.Add ("__EVENTTARGET");
987 fr
.Controls
.Add ("__EVENTARGUMENT");
988 fr
.Controls
["__EVENTTARGET"].Value
= "container$children$lb";
989 fr
.Controls
["__EVENTARGUMENT"].Value
= String
.Empty
;
992 string originalHtml
= "<span id=\"container\"><a id=\"container_children_lb\" href=\"javascript:__doPostBack('container$children$lb','')\">Woot! I got clicked!</a></span><hr/>";
994 string originalHtml
= @"<span id=""container""><a href=""javascript:__doPostBack('container$children$lb','')"" id=""container_children_lb"">Woot! I got clicked!</a></span><hr/>";
996 string pageHtml
= t
.Run ();
997 string renderedHtml
= HtmlDiff
.GetControlFromPageHtml (pageHtml
);
999 HtmlDiff
.AssertAreEqual (originalHtml
, renderedHtml
, "#A1");
1002 [TestFixtureTearDown
]
1003 public void Tear_down ()
1009 public void TestFixtureSetUp ()
1011 WebTest
.CopyResource (GetType (), "ResolveUrl.aspx", "ResolveUrl.aspx");
1012 WebTest
.CopyResource (GetType (), "ResolveUrl.ascx", "Folder/ResolveUrl.ascx");
1013 WebTest
.CopyResource (GetType (), "OverridenControlsPropertyAndPostBack_Bug594238.aspx", "OverridenControlsPropertyAndPostBack_Bug594238.aspx");
1019 public void GetRouteUrl_Object ()
1021 var t
= new WebTest (PageInvoker
.CreateOnLoad (GetRouteUrl_Object_Load
));
1025 public static void GetRouteUrl_Object_Load (Page p
)
1027 RouteTable
.Routes
.Clear ();
1029 var ctl
= new Control ();
1030 object obj
= new { foo = "one", bar = "two" }
;
1031 string path
= ctl
.GetRouteUrl (obj
);
1032 Assert
.IsNull (path
, "#A1");
1034 RouteTable
.Routes
.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1035 path
= ctl
.GetRouteUrl (obj
);
1036 Assert
.IsNotNull (path
, "#A2-1");
1037 Assert
.AreEqual ("/NunitWeb/one-two", path
, "#A2-2");
1039 path
= ctl
.GetRouteUrl ((object)null);
1040 Assert
.IsNull (path
, "#A3");
1044 public void GetRouteUrl_RouteValueDictionary ()
1046 var t
= new WebTest (PageInvoker
.CreateOnLoad (GetRouteUrl_RouteValueDictionary_Load
));
1050 public static void GetRouteUrl_RouteValueDictionary_Load (Page p
)
1052 RouteTable
.Routes
.Clear ();
1054 var ctl
= new Control ();
1055 var rvd
= new RouteValueDictionary
{
1059 string path
= ctl
.GetRouteUrl (rvd
);
1060 Assert
.IsNull (path
, "#A1");
1062 RouteTable
.Routes
.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1063 path
= ctl
.GetRouteUrl (rvd
);
1064 Assert
.IsNotNull (path
, "#A2-1");
1065 Assert
.AreEqual ("/NunitWeb/one-two", path
, "#A2-2");
1067 path
= ctl
.GetRouteUrl ((RouteValueDictionary
) null);
1068 Assert
.IsNull (path
, "#A3");
1072 public void GetRouteUrl_String_Object ()
1074 var t
= new WebTest (PageInvoker
.CreateOnLoad (GetRouteUrl_String_Object_Load
));
1078 public static void GetRouteUrl_String_Object_Load (Page p
)
1080 RouteTable
.Routes
.Clear ();
1082 var ctl
= new Control ();
1083 object obj
= new { foo = "one", bar = "two" }
;
1085 AssertExtensions
.Throws
<ArgumentException
> (() => {
1086 path
= ctl
.GetRouteUrl ("myroute1", obj
);
1089 RouteTable
.Routes
.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1090 RouteTable
.Routes
.Add ("myroute1", new Route ("{bar}-{foo}", new PageRouteHandler ("~/default.aspx")));
1091 path
= ctl
.GetRouteUrl ("myroute1", obj
);
1092 Assert
.IsNotNull (path
, "#A2-1");
1093 Assert
.AreEqual ("/NunitWeb/two-one", path
, "#A2-2");
1095 path
= ctl
.GetRouteUrl ("myroute1", (object) null);
1096 Assert
.IsNull (path
, "#A3");
1100 public void GetRouteUrl_String_RouteValueDictionary ()
1102 var t
= new WebTest (PageInvoker
.CreateOnLoad (GetRouteUrl_String_RouteValueDictionary_Load
));
1106 public static void GetRouteUrl_String_RouteValueDictionary_Load (Page p
)
1108 RouteTable
.Routes
.Clear ();
1110 var ctl
= new Control ();
1111 var rvd
= new RouteValueDictionary
{
1116 AssertExtensions
.Throws
<ArgumentException
> (() => {
1117 path
= ctl
.GetRouteUrl ("myroute", rvd
);
1120 RouteTable
.Routes
.Add (new Route ("{foo}-{bar}", new PageRouteHandler ("~/default.aspx")));
1121 RouteTable
.Routes
.Add ("myroute", new Route ("{bar}-{foo}", new PageRouteHandler ("~/default.aspx")));
1122 path
= ctl
.GetRouteUrl ("myroute", rvd
);
1123 Assert
.IsNotNull (path
, "#A2-1");
1124 Assert
.AreEqual ("/NunitWeb/two-one", path
, "#A2-2");
1126 path
= ctl
.GetRouteUrl ("myroute", (RouteValueDictionary
) null);
1127 Assert
.IsNull (path
, "#A3-1");
1129 path
= ctl
.GetRouteUrl (null, (RouteValueDictionary
) null);
1130 Assert
.IsNull (path
, "#A3-2");
1132 path
= ctl
.GetRouteUrl (String
.Empty
, (RouteValueDictionary
) null);
1133 Assert
.IsNull (path
, "#A3-3");
1138 class ControlWithState
: Control
1144 get { return _state; }
1145 set { _state = value; }
1148 public string Viewstate
{
1149 get { return (string) ViewState ["Viewstate"]; }
1150 set { ViewState ["Viewstate"] = value; }
1153 protected internal override void OnInit (EventArgs e
)
1156 Page
.RegisterRequiresControlState (this);
1159 protected internal override object SaveControlState ()
1164 protected internal override void LoadControlState (object savedState
)
1166 State
= (string) savedState
;
1169 public new void ClearChildState ()
1171 base.ClearChildState ();
1174 public new void ClearChildControlState ()
1176 base.ClearChildControlState ();
1179 public new bool IsChildControlStateCleared
1181 get { return base.IsChildControlStateCleared; }
1184 public new bool LoadViewStateByID
1186 get { return base.LoadViewStateByID; }
1191 class MyNC
: Control
, INamingContainer
1194 public ControlAdapter
Adapter ()
1196 return base.Adapter
;
1199 public new void DataBind (bool opt
)
1201 base.DataBind (opt
);
1204 public new void DataBindChildren ()
1206 base.DataBindChildren ();
1209 public new void EnsureID ()
1214 public new bool HasEvents ()
1216 return base.HasEvents ();
1221 class DerivedControl
: Control
1223 ControlCollection coll
;
1225 public DerivedControl ()
1227 coll
= new ControlCollection (this);
1230 public override ControlCollection Controls
1232 get { return coll; }
1236 public bool DoIsViewStateEnabled
1238 get { return IsViewStateEnabled; }
1241 public new char ClientIDSeparator
1243 get { return base.ClientIDSeparator; }
1246 public new char IdSeparator
1248 get { return base.IdSeparator; }
1251 public new Stream
OpenFile (string path
)
1253 return base.OpenFile (path
);
1256 public new ControlAdapter
ResolveAdapter ()
1258 return base.ResolveAdapter ();
1263 class NamingContainer
: Control
, INamingContainer
1267 class ControlWithTemplate
: Control
1269 ITemplate _template
;
1271 [TemplateContainer (typeof (TemplateContainer
))]
1272 public ITemplate Template
1274 get { return _template; }
1275 set { _template = value; }
1278 protected internal override void CreateChildControls ()
1282 TemplateContainer container
= new TemplateContainer ();
1283 Controls
.Add (container
);
1285 if (Template
!= null)
1286 Template
.InstantiateIn (container
);
1290 class TemplateContainer
: Control
, INamingContainer
1297 public class Customadaptercontrol
: Control
1299 public new ControlAdapter Adapter
{
1300 get { return base.Adapter; }
1303 public new ControlAdapter
ResolveAdapter ()
1305 return base.ResolveAdapter ();
1309 public class Customadapter
: ControlAdapter
1313 class EnsureIDControl
: Control
{
1314 public void DoEnsureID () {
1320 public class ChildControlsCreatedControl
: Control
1322 protected internal override void CreateChildControls () {
1323 Controls
.Add (new Control ());
1326 public void DoEnsureChildControls () {
1327 EnsureChildControls ();
1330 public void SetChildControlsCreated (bool value) {
1331 ChildControlsCreated
= value;