2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / ControlTest.cs
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)
9
10
11 //
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.
30 //
31
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
43 #if NET_2_0
44 using System.Web.UI.Adapters;
45 #endif
46
47 namespace MonoTests.System.Web.UI
48 {
49         [TestFixture]
50         public class ControlTest
51         {
52                 [Test]
53                 public void DataBindingInterfaceTest ()
54                 {
55                         Control c;
56                         DataBindingCollection db;
57
58                         c = new Control ();
59                         Assert.AreEqual (false, ((IDataBindingsAccessor) c).HasDataBindings, "DB1");
60                         db = ((IDataBindingsAccessor) c).DataBindings;
61                         Assert.IsNotNull (db, "DB2");
62                         Assert.AreEqual (false, ((IDataBindingsAccessor) c).HasDataBindings, "DB3");
63                         db.Add (new DataBinding ("property", typeof (bool), "expression"));
64                         Assert.AreEqual (true, ((IDataBindingsAccessor) c).HasDataBindings);
65                 }
66
67                 [Test] // bug #82546
68                 public void FindControl_NamingContainer ()
69                 {
70                         Control topControl = new NamingContainer ();
71                         topControl.ID = "top";
72
73                         Control controlLevel1A = new Control ();
74                         controlLevel1A.ID = "Level1#A";
75                         topControl.Controls.Add (controlLevel1A);
76
77                         Control controlLevel1B = new Control ();
78                         controlLevel1B.ID = "Level1#B";
79                         topControl.Controls.Add (controlLevel1B);
80
81                         Control controlLevel2AA = new Control ();
82                         controlLevel2AA.ID = "Level2#AA";
83                         controlLevel1A.Controls.Add (controlLevel2AA);
84
85                         Control controlLevel2AB = new Control ();
86                         controlLevel2AB.ID = "Level2#AB";
87                         controlLevel1A.Controls.Add (controlLevel2AB);
88
89                         Control foundControl = topControl.FindControl ("Level1#A");
90                         Assert.IsNotNull (foundControl, "#A1");
91                         Assert.AreSame (controlLevel1A, foundControl, "#A2");
92
93                         foundControl = topControl.FindControl ("LEVEL1#B");
94                         Assert.IsNotNull (foundControl, "#B1");
95                         Assert.AreSame (controlLevel1B, foundControl, "#B2");
96
97                         foundControl = topControl.FindControl ("LeVeL2#AB");
98                         Assert.IsNotNull (foundControl, "#C1");
99                         Assert.AreSame (controlLevel2AB, foundControl, "#C2");
100
101                         foundControl = topControl.FindControl ("doesnotexist");
102                         Assert.IsNull (foundControl, "#D1");
103                         foundControl = topControl.FindControl ("top");
104                         Assert.IsNull (foundControl, "#D2");
105
106                         foundControl = controlLevel1A.FindControl ("Level2#AA");
107                         Assert.IsNotNull (foundControl, "#E1");
108                         Assert.AreSame (controlLevel2AA, foundControl, "#E2");
109
110                         foundControl = controlLevel1A.FindControl ("LEveL2#ab");
111                         Assert.IsNotNull (foundControl, "#F1");
112                         Assert.AreSame (controlLevel2AB, foundControl, "#F2");
113                 }
114
115                 [Test]
116                 public void UniqueID1 ()
117                 {
118                         // Standalone NC
119                         Control nc = new MyNC ();
120                         Assert.IsNull (nc.UniqueID, "nulltest");
121                 }
122                 
123                 [Test]
124                 public void UniqueID1_1 () {
125                         // Standalone NC
126                         Control nc = new MyNC ();
127                         Page p = new Page ();
128                         p.Controls.Add (nc);
129                         Assert.IsNotNull (nc.UniqueID, "notnull");
130                 }
131                 
132                 [Test]
133                 public void UniqueID2 ()
134                 {
135                         // NC in NC
136                         Control nc = new MyNC ();
137                         Control nc2 = new MyNC ();
138                         nc2.Controls.Add (nc);
139                         Assert.IsNotNull (nc.UniqueID, "notnull");
140                         Assert.IsTrue (nc.UniqueID.IndexOfAny (new char[] { ':', '$' }) == -1, "separator");
141                 }
142
143                 [Test]
144                 public void UniqueID2_1 () {
145                         // NC in NC
146                         Control nc = new MyNC ();
147                         Control nc2 = new MyNC ();
148                         nc2.Controls.Add (nc);
149                         Page p = new Page ();
150                         p.Controls.Add (nc2);
151                         Assert.IsNotNull (nc.UniqueID, "notnull");
152                         Assert.IsTrue (nc.UniqueID.IndexOfAny (new char [] { ':', '$' }) != -1, "separator");
153                 }
154
155                 [Test]
156                 public void UniqueID3 ()
157                 {
158                         // NC in control
159                         Control control = new Control ();
160                         Control nc = new MyNC ();
161
162                         control.Controls.Add (nc);
163                         Assert.IsNull (nc.UniqueID, "null");
164                 }
165
166                 [Test]
167                 public void UniqueID4 ()
168                 {
169                         // NC in control
170                         Control control = new Control ();
171                         Control nc = new MyNC ();
172
173                         nc.Controls.Add (control);
174                         Assert.IsNotNull (control.UniqueID, "notnull");
175                 }
176
177                 [Test]
178                 public void UniqueID5 ()
179                 {
180                         // NC in control
181                         Control control = new Control ();
182                         Control nc = new MyNC ();
183                         Control nc2 = new MyNC ();
184
185                         nc2.Controls.Add (nc);
186                         nc.Controls.Add (control);
187                         Assert.IsNotNull (control.UniqueID, "notnull");
188                         Assert.IsNull (nc2.ID, "null-1");
189                         Assert.IsNull (nc.ID, "null-2");
190                         Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char[] { ':', '$' }), "separator");
191                 }
192
193                 [Test]
194                 public void UniqueID6 () {
195                         // NC in NC
196                         Control nc = new MyNC ();
197                         Page p = new Page ();
198                         p.Controls.Add (nc);
199                         Assert.IsNotNull (nc.UniqueID, "notnull");
200
201                         Control c1 = new Control ();
202                         Control c2 = new Control ();
203                         nc.Controls.Add (c1);
204                         nc.Controls.Add (c2);
205                         string uid1_1 = c1.UniqueID;
206                         string uid2_1 = c2.UniqueID;
207
208                         nc.Controls.Clear ();
209
210                         Assert.IsNull (c1.UniqueID);
211                         Assert.IsNull (c2.UniqueID);
212
213                         // ad in another order
214                         nc.Controls.Add (c2);
215                         nc.Controls.Add (c1);
216                         string uid1_2 = c1.UniqueID;
217                         string uid2_2 = c2.UniqueID;
218
219                         Assert.IsFalse (uid1_1 == uid1_2);
220                         Assert.IsFalse (uid2_1 == uid2_2);
221                         Assert.AreEqual (uid1_1, uid2_2);
222                         Assert.AreEqual (uid2_1, uid1_2);
223
224                         nc.Controls.Remove (c1);
225                         nc.Controls.Add (c1);
226                         string uid1_3 = c1.UniqueID;
227                         Assert.IsFalse (uid1_3 == uid1_2, "id was not reset");
228
229 #if NET_2_0
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");
240 #endif
241                 }
242
243                 [Test]
244                 public void ClientID () 
245                 {
246                         // NC in control
247                         Control control = new Control ();
248                         Control nc = new MyNC ();
249                         Control nc2 = new MyNC ();
250                         Control nc3 = new MyNC ();
251
252                         nc3.Controls.Add (nc2);
253                         nc2.Controls.Add (nc);
254                         nc.Controls.Add (control);
255 #if NET_2_0
256                         string expected = "ctl00_ctl00_ctl00";
257 #else
258                         string expected = "_ctl0__ctl0__ctl0";
259 #endif
260                         Assert.AreEqual (expected, control.ClientID, "ClientID");
261                 }
262
263                 // From bug #76919: Control uses _controls instead of
264                 // Controls when RenderChildren is called.
265                 [Test]
266                 public void Controls1 ()
267                 {
268                         DerivedControl derived = new DerivedControl ();
269                         derived.Controls.Add (new LiteralControl ("hola"));
270                         StringWriter sw = new StringWriter ();
271                         HtmlTextWriter htw = new HtmlTextWriter (sw);
272                         derived.RenderControl (htw);
273                         string result = sw.ToString ();
274                         Assert.AreEqual ("", result, "#01");
275                 }
276
277                 [Test] // Bug #471305
278                 [Category ("NunitWeb")]
279                 public void NoDoubleOnInitOnRemoveAdd ()
280                 {
281                         WebTest.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx", "NoDoubleOnInitOnRemoveAdd.aspx");
282                         WebTest.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx.cs", "NoDoubleOnInitOnRemoveAdd.aspx.cs");
283                         WebTest t = new WebTest ("NoDoubleOnInitOnRemoveAdd.aspx");
284                         string html = t.Run ();
285
286                         Assert.AreEqual (-1, html.IndexOf ("<span>label</span><span>label</span>"), "#A1");
287                 }
288                 
289 #if NET_2_0
290                 [Test]
291                 [Category("NunitWeb")]
292                 public void AppRelativeTemplateSourceDirectory ()
293                 {
294                         new WebTest(PageInvoker.CreateOnLoad(AppRelativeTemplateSourceDirectory_Load)).Run();
295                 }
296                 
297                 public static void AppRelativeTemplateSourceDirectory_Load(Page p)
298                 {
299                         Control ctrl = new Control();
300                         Assert.AreEqual("~/", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#1");
301                         ctrl.AppRelativeTemplateSourceDirectory = "~/Fake";
302                         Assert.AreEqual("~/Fake", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#2");
303                 }
304
305                 [Test]
306                 public void ApplyStyleSheetSkin ()
307                 {
308                         Page p = new Page ();
309                         p.StyleSheetTheme = "";
310                         Control c = new Control ();
311                         c.ApplyStyleSheetSkin (p);
312                 }
313
314                 [Test]
315                 [Category ("NunitWeb")]
316                 public void ApplyStyleSheetSkin_1 ()
317                 {
318                         WebTest.CopyResource (GetType (), "Theme2.skin", "App_Themes/Theme2/Theme2.skin");
319                         WebTest t = new WebTest ();
320                         PageDelegates pd = new PageDelegates ();
321                         pd.PreInit = ApplyStyleSheetSkin_PreInit;
322                         pd.Load = ApplyStyleSheetSkin_Load;
323                         t.Invoker = new PageInvoker (pd);
324                         string str = t.Run ();
325                 }
326                 public static void ApplyStyleSheetSkin_PreInit (Page p)
327                 {
328                         p.Theme = "Theme2";
329                 }
330                 public static void ApplyStyleSheetSkin_Load (Page p)
331                 {
332                         Label lbl = new Label ();
333                         lbl.ID = "StyleLbl";
334                         lbl.SkinID = "red";
335                         lbl.Text = "StyleLabel";
336                         p.Controls.Add (lbl);
337                         lbl.ApplyStyleSheetSkin (p);
338                         Assert.AreEqual (Color.Red, lbl.ForeColor, "ApplyStyleSheetSkin_BackColor");
339                         Assert.AreEqual ("TextFromSkinFile", lbl.Text, "ApplyStyleSheetSkin");
340                 }
341
342                 [Test]
343                 [Category ("NunitWeb")]
344                 public void ClearChildControlState ()
345                 {
346                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildControlState_Load));
347                         t.Run ();
348                         FormRequest fr = new FormRequest (t.Response, "form1");
349                         fr.Controls.Add ("__EVENTTARGET");
350                         fr.Controls.Add ("__EVENTARGUMENT");
351                         fr.Controls["__EVENTTARGET"].Value = "";
352                         fr.Controls["__EVENTARGUMENT"].Value = "";
353                         t.Request = fr;
354                         t.Run ();
355                 }
356                 public static void ClearChildControlState_Load (Page p)
357                 {
358                         ControlWithState c1 = new ControlWithState ();
359                         p.Form.Controls.Add (c1);
360                         if (p.IsPostBack) {
361                                 c1.ClearChildControlState ();
362                         }
363                         ControlWithState c2 = new ControlWithState ();
364                         c1.Controls.Add (c2);
365                         ControlWithState c3 = new ControlWithState ();
366                         c2.Controls.Add (c3);
367                         if (!p.IsPostBack) {
368                                 c1.State = "State";
369                                 c2.State = "Cool";
370                                 c3.State = "SubCool";
371                         }
372                         else {
373                                 Assert.AreEqual ("State", c1.State, "ControlState#1");
374                                 Assert.AreEqual (null, c2.State, "ControlState#2");
375                                 Assert.AreEqual (null, c3.State, "ControlState#2");
376                         }
377                 }
378
379                 [Test]
380                 [Category ("NunitWeb")]
381                 public void ClearChildState ()
382                 {
383                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildState_Load));
384                         t.Run ();
385                         FormRequest fr = new FormRequest (t.Response, "form1");
386                         fr.Controls.Add ("__EVENTTARGET");
387                         fr.Controls.Add ("__EVENTARGUMENT");
388                         fr.Controls["__EVENTTARGET"].Value = "";
389                         fr.Controls["__EVENTARGUMENT"].Value = "";
390                         t.Request = fr;
391                         t.Run ();
392                 }
393                 public static void ClearChildState_Load (Page p)
394                 {
395                         ControlWithState c1 = new ControlWithState ();
396                         p.Form.Controls.Add (c1);
397                         if (p.IsPostBack) {
398                                 c1.ClearChildState ();
399                         }
400                         ControlWithState c2 = new ControlWithState ();
401                         c1.Controls.Add (c2);
402                         ControlWithState c3 = new ControlWithState ();
403                         c2.Controls.Add (c3);
404                         if (!p.IsPostBack) {
405                                 c1.State = "State";
406                                 c2.State = "Cool";
407                                 c2.Viewstate = "Very Cool";
408                                 c3.State = "SubCool";
409                                 c3.Viewstate = "Super Cool";
410                         }
411                         else {
412                                 Assert.AreEqual ("State", c1.State, "ClearChildState#1");
413                                 Assert.AreEqual (null, c2.State, "ClearChildState#2");
414                                 Assert.AreEqual (null, c3.State, "ClearChildState#3");
415                                 Assert.AreEqual (null, c2.Viewstate, "ClearChildState#4");
416                                 Assert.AreEqual (null, c3.Viewstate, "ClearChildState#5");
417                         }
418                 }
419
420                 [Test]
421                 public void DataBind ()
422                 {
423                         MyNC ctrl = new MyNC ();
424                         ctrl.DataBinding += new EventHandler (ctrl_DataBinding);
425                         Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
426                         ctrl.DataBind (false);
427                         Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
428                         ctrl.DataBind (true);
429                         Assert.AreEqual (true, _eventDataBinding, "After DataBinding");
430                 }
431                 bool _eventDataBinding;
432                 void ctrl_DataBinding (object sender, EventArgs e)
433                 {
434                         _eventDataBinding = true;
435                 }
436
437                 [Test]
438                 public void DataBindChildren ()
439                 {
440                         MyNC ctrl1 = new MyNC ();
441                         Control ctrl2 = new Control ();
442                         Control ctrl3 = new Control ();
443                         ctrl2.DataBinding += new EventHandler (ctrl2_DataBinding);
444                         ctrl3.DataBinding += new EventHandler (ctrl3_DataBinding);
445
446                         ctrl2.Controls.Add (ctrl3);
447                         ctrl1.Controls.Add (ctrl2);
448                         Assert.AreEqual (false, _eventChild1, "Before DataBinding#1");
449                         Assert.AreEqual (false, _eventChild2, "Before DataBinding#2");
450                         ctrl1.DataBindChildren ();
451                         Assert.AreEqual (true, _eventChild1, "After DataBinding#1");
452                         Assert.AreEqual (true, _eventChild2, "After DataBinding#2");
453                 }
454                 bool _eventChild1;
455                 bool _eventChild2;
456                 void ctrl3_DataBinding (object sender, EventArgs e)
457                 {
458                         _eventChild1 = true;
459                 }
460                 void ctrl2_DataBinding (object sender, EventArgs e)
461                 {
462                         _eventChild2 = true;
463                 }
464
465                 [Test]
466                 public void EnsureID ()
467                 {
468                         MyNC ctrl = new MyNC ();
469                         MyNC ctrl1 = new MyNC ();
470                         ctrl.Controls.Add (ctrl1);
471                         Page p = new Page ();
472                         p.Controls.Add (ctrl);
473                         ctrl.EnsureID ();
474                         if (String.IsNullOrEmpty (ctrl.ID))
475                                 Assert.Fail ("EnsureID#1");
476                         ctrl1.EnsureID ();
477                         if (String.IsNullOrEmpty (ctrl1.ID))
478                                 Assert.Fail ("EnsureID#2");
479                 }
480
481                 [Test]
482                 [Category("NotWorking")]
483                 public void Focus ()
484                 {
485                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (Focus_Load));
486                         string html = t.Run ();
487                         Assert.AreEqual (3, contain (html, "TestBox"), "Focus script not created");
488
489                 }
490                 public static void Focus_Load (Page p)
491                 {
492                         TextBox tbx = new TextBox ();
493                         tbx.ID = "TestBox";
494                         p.Controls.Add (tbx);
495                         tbx.Focus ();
496                 }
497                 int contain (string orig, string compare)
498                 {
499                         if (orig.IndexOf (compare) == -1)
500                                 return 0;
501                         return 1 + contain (orig.Substring (orig.IndexOf (compare) + compare.Length), compare);
502                 }
503
504                 [Test]
505                 public void HasEvent ()
506                 {
507                         MyNC ctrl1 = new MyNC ();
508                         Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#1");
509                         EventHandler ctrl_hdlr = new EventHandler (ctrl1_Init);
510                         ctrl1.Init += new EventHandler (ctrl1_Init);
511                         ctrl1.Init += ctrl_hdlr;
512                         Assert.AreEqual (true, ctrl1.HasEvents (), "HasEvent#2");
513                         // Dosn't work than removed handler
514                         //ctrl1.Init -= ctrl_hdlr;
515                         //Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#3");
516                 }
517                 void ctrl1_Init (object sender, EventArgs e)
518                 {
519                         throw new Exception ("The method or operation is not implemented.");
520                 }
521
522                 [Test]
523                 public void IsViewStateEnabled ()
524                 {
525                         DerivedControl c = new DerivedControl ();
526                         Assert.IsTrue (c.DoIsViewStateEnabled);
527                         Page p = new Page ();
528                         c.Page = p;
529                         p.Controls.Add (c);
530                         Assert.IsTrue (c.DoIsViewStateEnabled);
531                         p.EnableViewState = false;
532                         Assert.IsFalse (c.DoIsViewStateEnabled);
533                 }
534
535                 [Test]
536                 [Category ("NunitWeb")]
537                 public void ControlState ()
538                 {
539                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState_Load));
540                         t.Run ();
541                         FormRequest fr = new FormRequest (t.Response, "form1");
542                         fr.Controls.Add ("__EVENTTARGET");
543                         fr.Controls.Add ("__EVENTARGUMENT");
544                         fr.Controls["__EVENTTARGET"].Value = "";
545                         fr.Controls["__EVENTARGUMENT"].Value = "";
546                         t.Request = fr;
547                         t.Run ();
548                 }
549                 public static void ControlState_Load (Page p)
550                 {
551                         ControlWithState c1 = new ControlWithState ();
552                         ControlWithState c2 = new ControlWithState ();
553                         c1.Controls.Add (c2);
554                         p.Form.Controls.Add (c1);
555                         if (!p.IsPostBack) {
556                                 c1.State = "State";
557                                 c2.State = "Cool";
558                         }
559                         else {
560                                 ControlWithState c3 = new ControlWithState ();
561                                 p.Form.Controls.Add (c3);
562                                 Assert.AreEqual ("State", c1.State, "ControlState");
563                                 Assert.AreEqual ("Cool", c2.State, "ControlState");
564                         }
565                 }
566
567                 [Test]
568                 [Category ("NunitWeb")]
569                 public void ControlState2 () {
570                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState2_Load));
571                         t.Run ();
572                         FormRequest fr = new FormRequest (t.Response, "form1");
573                         fr.Controls.Add ("__EVENTTARGET");
574                         fr.Controls.Add ("__EVENTARGUMENT");
575                         fr.Controls ["__EVENTTARGET"].Value = "";
576                         fr.Controls ["__EVENTARGUMENT"].Value = "";
577                         t.Request = fr;
578                         t.Run ();
579                         
580                         fr = new FormRequest (t.Response, "form1");
581                         fr.Controls.Add ("__EVENTTARGET");
582                         fr.Controls.Add ("__EVENTARGUMENT");
583                         fr.Controls ["__EVENTTARGET"].Value = "";
584                         fr.Controls ["__EVENTARGUMENT"].Value = "";
585                         t.Request = fr;
586                         t.Run ();
587                 }
588                 public static void ControlState2_Load (Page p) {
589                         ControlWithState parent = new ControlWithState ();
590                         p.Form.Controls.Add (parent);
591                         if (!p.IsPostBack) {
592                                 // emulate DataBind
593                                 parent.Controls.Clear ();
594                                 parent.ClearChildControlState ();
595                                 ControlWithState c1 = new ControlWithState ();
596                                 ControlWithState c2 = new ControlWithState ();
597                                 parent.Controls.Add (c1);
598                                 parent.Controls.Add (c2);
599                                 c1.State = "State1_1";
600                                 c2.State = "State1_2";
601                                 parent.State = "First";
602                         }
603                         else if (parent.State == "First") {
604                                 // emulate DataBind
605                                 parent.Controls.Clear ();
606                                 parent.ClearChildControlState ();
607                                 ControlWithState c1 = new ControlWithState ();
608                                 ControlWithState c2 = new ControlWithState ();
609                                 parent.Controls.Add (c1);
610                                 parent.Controls.Add (c2);
611                                 c1.State = "State2_1";
612                                 c2.State = "State2_2";
613                                 parent.State = "Second";
614                         }
615                         else {
616                                 // emulate CrerateChildControl only
617                                 parent.Controls.Clear ();
618                                 ControlWithState c1 = new ControlWithState ();
619                                 ControlWithState c2 = new ControlWithState ();
620                                 parent.Controls.Add (c1);
621                                 parent.Controls.Add (c2);
622
623                                 Assert.AreEqual ("State2_1", c1.State, "ControlState#1");
624                                 Assert.AreEqual ("State2_2", c2.State, "ControlState#2");
625                         }
626                 }
627
628                 [Test]
629                 public void ClientIDSeparator ()
630                 {
631                         DerivedControl ctrl = new DerivedControl ();
632                         Assert.AreEqual (95, (int) ctrl.ClientIDSeparator, "ClientIDSeparator");
633                 }
634
635                 [Test]
636                 public void IDSeparator ()
637                 {
638                         DerivedControl ctrl = new DerivedControl ();
639                         Assert.AreEqual (36, (int) ctrl.IdSeparator, "IDSeparator");
640                 }
641
642                 [Test]
643                 [Category ("NunitWeb")]
644                 public void IsChildControlStateCleared ()
645                 {
646                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (IsChildControlStateCleared_Load));
647                         t.Run ();
648                         FormRequest fr = new FormRequest (t.Response, "form1");
649                         fr.Controls.Add ("__EVENTTARGET");
650                         fr.Controls.Add ("__EVENTARGUMENT");
651                         fr.Controls["__EVENTTARGET"].Value = "";
652                         fr.Controls["__EVENTARGUMENT"].Value = "";
653                         t.Request = fr;
654                         t.Run ();
655                 }
656                 public static void IsChildControlStateCleared_Load (Page p)
657                 {
658                         ControlWithState c1 = new ControlWithState ();
659                         p.Form.Controls.Add (c1);
660                         if (p.IsPostBack) {
661                                 Assert.IsFalse (c1.IsChildControlStateCleared, "ControlState#1");
662                                 c1.ClearChildControlState ();
663                                 Assert.IsTrue (c1.IsChildControlStateCleared, "ControlState#1");
664                         }
665                         ControlWithState c2 = new ControlWithState ();
666                         c1.Controls.Add (c2);
667                         ControlWithState c3 = new ControlWithState ();
668                         c2.Controls.Add (c3);
669                         if (p.IsPostBack) {
670                                 Assert.IsFalse (c2.IsChildControlStateCleared, "ControlState#1");
671                                 Assert.IsFalse (c3.IsChildControlStateCleared, "ControlState#1");
672                         }
673                         if (!p.IsPostBack) {
674                                 c1.State = "State";
675                                 c2.State = "Cool";
676                                 c3.State = "SubCool";
677                         }
678                 }
679
680                 [Test]
681                 [Category ("NunitWeb")]
682                 public void LoadViewStateByID ()
683                 {
684                         ControlWithState c1 = new ControlWithState ();
685                         ControlWithState c2 = new ControlWithState ();
686                         c1.Controls.Add (c2);
687                         Assert.AreEqual (false, c1.LoadViewStateByID, "LoadViewStateByID#1");
688                 }
689
690                 [Test]
691                 [Category ("NunitWeb")]
692                 public void OpenFile ()
693                 {
694                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFile_Load));
695                         t.Run ();
696                 }
697                 public static void OpenFile_Load (Page p)
698                 {
699                         DerivedControl ctrl = new DerivedControl ();
700                         Stream strem = ctrl.OpenFile ("~/MyPage.aspx");
701                         Assert.IsNotNull (strem, "OpenFile failed");
702                 }
703
704                 [Test]
705                 [Category ("NunitWeb")]
706                 [ExpectedException (typeof (FileNotFoundException))]
707                 public void OpenFile_Exception ()
708                 {
709                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFileException_Load));
710                         t.Run ();
711                 }
712                 public static void OpenFileException_Load (Page p)
713                 {
714                         DerivedControl ctrl = new DerivedControl ();
715                         Stream strem = ctrl.OpenFile ("~/Fake.tmp");
716                 }
717
718                 [Test]
719                 [Category ("NunitWeb")]
720                 public void ResolveClientUrl ()
721                 {
722                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveClientUrl_Load));
723                         string html = t.Run ();
724                 }
725                 public static void ResolveClientUrl_Load (Page p)
726                 {
727                         Control ctrl = new Control ();
728                         p.Controls.Add (ctrl);
729                         string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
730                         Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
731
732                         Assert.AreEqual ("", ctrl.ResolveClientUrl (""), "empty string");
733                         
734                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~"), "~");
735                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~/"), "~/");
736
737                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
738                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
739                         Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
740                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
741                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
742                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
743                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
744                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
745                         Assert.AreEqual ("NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
746                         Assert.AreEqual ("NunitWeb/../MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
747                         Assert.AreEqual ("NunitWeb/./MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
748                         Assert.AreEqual ("http://google.com/", ctrl.ResolveClientUrl ("http://google.com/"), "ResolveClientUrl Failed");
749
750                         Assert.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
751                         Assert.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
752
753                         Assert.AreEqual ("./MyPage.aspx", ctrl.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
754                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
755                 
756                 }
757                 
758                 [Test]
759                 [Category ("NunitWeb")]
760                 public void ResolveClientUrl2 ()
761                 {
762                         WebTest t = new WebTest ("ResolveUrl.aspx");
763                         PageDelegates delegates = new PageDelegates ();
764                         delegates.Load = ResolveClientUrl2_Load;
765                         t.Invoker = new PageInvoker (delegates);
766                         string html = t.Run ();
767                 }
768                 
769                 public static void ResolveClientUrl2_Load (Page p)
770                 {
771                         Control uc = p.FindControl ("WebUserControl1");
772                         Control ctrl = uc.FindControl ("Label");
773                         
774                         string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
775                         Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
776
777                         Assert.AreEqual ("", ctrl.ResolveClientUrl (""), "empty string");
778
779                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~"), "~");
780                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~/"), "~/");
781
782                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
783                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
784                         Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
785                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
786                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
787                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
788                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
789                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
790                         Assert.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
791                         Assert.AreEqual ("Folder/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
792                         Assert.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
793                         Assert.AreEqual ("http://google.com/", ctrl.ResolveClientUrl ("http://google.com/"), "ResolveClientUrl Failed");
794
795                         Assert.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
796                         Assert.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
797
798                         Assert.AreEqual ("Folder/MyPage.aspx", ctrl.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
799                         Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
800
801                 }
802
803                 [Test]
804                 [Category ("NunitWeb")]
805                 public void ResolveUrl ()
806                 {
807                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveUrl_Load));
808                         string html = t.Run ();
809                 }
810
811                 public static void ResolveUrl_Load (Page p)
812                 {
813 #if TARGET_JVM
814                         string appPath = "/MainsoftWebApp20";
815 #else
816                         string appPath = "/NunitWeb";
817 #endif
818                         Control ctrl = new Control ();
819                         p.Controls.Add (ctrl);
820                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
821
822                         Assert.AreEqual ("", ctrl.ResolveUrl (""), "empty string");
823
824                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~"), "~");
825                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~/"), "~/");
826
827                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
828                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
829                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
830                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
831                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
832                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
833                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
834                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
835                         Assert.AreEqual (appPath + "/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
836                         Assert.AreEqual (appPath + "/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 ("http://google.com/", ctrl.ResolveUrl ("http://google.com/"), "ResolveClientUrl Failed");
839
840                         Assert.AreEqual (appPath + "/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
841                         Assert.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
842
843                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
844                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
845
846                         Assert.AreEqual ("/", ctrl.ResolveUrl (".."), "..");
847                         Assert.AreEqual ("/", ctrl.ResolveUrl ("../"), "../");
848                 }
849
850                 [Test]
851                 [Category ("NunitWeb")]
852                 public void ResolveUrl2 ()
853                 {
854                         WebTest t = new WebTest ("ResolveUrl.aspx");
855                         PageDelegates delegates = new PageDelegates ();
856                         delegates.Load = ResolveUrl2_Load;
857                         t.Invoker = new PageInvoker (delegates);
858                         string html = t.Run ();
859                 }
860
861                 public static void ResolveUrl2_Load (Page p)
862                 {
863 #if TARGET_JVM
864                         string appPath = "/MainsoftWebApp20";
865 #else
866                         string appPath = "/NunitWeb";
867 #endif
868                         Control uc = p.FindControl ("WebUserControl1");
869                         Control ctrl = uc.FindControl ("Label");
870
871                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
872
873                         Assert.AreEqual ("", ctrl.ResolveUrl (""), "empty string");
874
875                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~"), "~");
876                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~/"), "~/");
877
878                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
879                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
880                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
881                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
882                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
883                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
884                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
885                         Assert.AreEqual ("///NunitWeb\\..\\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 (appPath + "/Folder/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
888                         Assert.AreEqual (appPath + "/Folder/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
889                         Assert.AreEqual ("http://google.com/", ctrl.ResolveUrl ("http://google.com/"), "ResolveClientUrl Failed");
890
891                         Assert.AreEqual (appPath + "/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
892                         Assert.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
893
894                         Assert.AreEqual (appPath + "/Folder/MyPage.aspx", ctrl.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
895                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
896
897                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl (".."), "..");
898                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("../"), "../");
899                         Assert.AreEqual ("/", ctrl.ResolveUrl ("../.."), "../..");
900                         Assert.AreEqual ("/", ctrl.ResolveUrl ("../../"), "../../");
901                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("../../MyPage.aspx"), "../../MyPage.aspx");
902                 }
903
904                 [Test]
905                 [Category ("NotWorking")] // Not implemented exception
906                 public void ResolveAdapter_2 ()
907                 {
908                         DerivedControl ctrl = new DerivedControl ();
909                         Assert.AreEqual (null, ctrl.ResolveAdapter (), "ResolveAdapter");
910                 }
911
912                 [Test]
913                 public void EnableTheming ()
914                 {
915                         DerivedControl ctrl = new DerivedControl ();
916                         Assert.AreEqual (true, ctrl.EnableTheming, "EnableTheming#1");
917                         ctrl.EnableTheming = false;
918                         Assert.AreEqual (false, ctrl.EnableTheming, "EnableTheming#2");
919                 }
920
921 #endif
922                 [Test]
923                 public void BindingContainer ()
924                 {
925                         ControlWithTemplate c = new ControlWithTemplate ();
926                         c.Template = new CompiledTemplateBuilder (new BuildTemplateMethod (BindingContainer_BuildTemplate));
927
928                         // cause CreateChildControls called
929                         c.FindControl ("stam");
930                 }
931
932                 static void BindingContainer_BuildTemplate (Control control)
933                 {
934                         Control child1 = new Control ();
935                         control.Controls.Add (child1);
936
937                         Assert.IsTrue (Object.ReferenceEquals (child1.NamingContainer, control), "NamingContainer #1");
938                         Assert.IsTrue (Object.ReferenceEquals (child1.BindingContainer, control), "BindingContainer #1");
939
940                         NamingContainer nc = new NamingContainer ();
941                         Control child2 = new Control ();
942                         nc.Controls.Add (child2);
943                         control.Controls.Add (nc);
944
945                         Assert.IsTrue (Object.ReferenceEquals (child2.NamingContainer, nc), "NamingContainer #2");
946                         Assert.IsTrue (Object.ReferenceEquals (child2.BindingContainer, nc), "BindingContainer #2");
947
948 #if NET_2_0
949                         // DetailsViewPagerRow marked to be not BindingContainer 
950                         DetailsViewPagerRow row = new DetailsViewPagerRow (0, DataControlRowType.Pager, DataControlRowState.Normal);
951                         TableCell cell = new TableCell ();
952                         Control child3 = new Control ();
953                         cell.Controls.Add (child3);
954                         row.Cells.Add (cell);
955                         control.Controls.Add (row);
956
957                         Assert.IsTrue (Object.ReferenceEquals (child3.NamingContainer, row), "NamingContainer #3");
958                         Assert.IsTrue (Object.ReferenceEquals (child3.BindingContainer, control), "BindingContainer #3");
959 #endif
960                 }
961 #if NET_2_0
962                 [Test]
963                 public void Control_Adapter ()
964                 {
965                         MyNC ctr = new MyNC ();
966                         Assert.AreEqual (null, ctr.Adapter (), "Adapter");
967                 }
968 #endif
969                 [Test]
970                 public void ChildControlsCreated () {
971                         ChildControlsCreatedControl ctr = new ChildControlsCreatedControl ();
972                         ctr.Controls.Add (new Control ());
973                         //ctr.DoEnsureChildControls ();
974
975                         Assert.AreEqual (1, ctr.Controls.Count, "ChildControlsCreated#1");
976                         ctr.SetChildControlsCreated (false);
977                         Assert.AreEqual (1, ctr.Controls.Count, "ChildControlsCreated#2");
978                 }
979
980 #if NET_2_0
981                 [TestFixtureTearDown]
982                 public void Tear_down ()
983                 {
984                         WebTest.Unload ();
985                 }
986                 
987                 [TestFixtureSetUp]
988                 public void TestFixtureSetUp ()
989                 {
990                         WebTest.CopyResource (GetType (), "ResolveUrl.aspx", "ResolveUrl.aspx");
991                         WebTest.CopyResource (GetType (), "ResolveUrl.ascx", "Folder/ResolveUrl.ascx");
992                 }
993
994 #endif
995
996                 #region helpcalsses
997 #if NET_2_0
998                 class ControlWithState : Control
999                 {
1000                         string _state;
1001
1002                         public string State
1003                         {
1004                                 get { return _state; }
1005                                 set { _state = value; }
1006                         }
1007
1008                         public string Viewstate {
1009                                 get { return (string) ViewState ["Viewstate"]; }
1010                                 set { ViewState ["Viewstate"] = value; }
1011                         }
1012
1013                         protected override void OnInit (EventArgs e)
1014                         {
1015                                 base.OnInit (e);
1016                                 Page.RegisterRequiresControlState (this);
1017                         }
1018
1019                         protected override object SaveControlState ()
1020                         {
1021                                 return State;
1022                         }
1023
1024                         protected override void LoadControlState (object savedState)
1025                         {
1026                                 State = (string) savedState;
1027                         }
1028
1029                         public new void ClearChildState ()
1030                         {
1031                                 base.ClearChildState ();
1032                         }
1033
1034                         public new void ClearChildControlState ()
1035                         {
1036                                 base.ClearChildControlState ();
1037                         }
1038
1039                         public new bool IsChildControlStateCleared
1040                         {
1041                                 get { return base.IsChildControlStateCleared; }
1042                         }
1043
1044                         public new bool LoadViewStateByID
1045                         {
1046                                 get { return base.LoadViewStateByID; }
1047                         }
1048                 }
1049
1050 #endif
1051                 class MyNC : Control, INamingContainer
1052                 {
1053                         #if NET_2_0
1054                         public ControlAdapter Adapter ()
1055                         {
1056                                 return base.Adapter;
1057                         }
1058
1059                         public new void DataBind (bool opt)
1060                         {
1061                                 base.DataBind (opt);
1062                         }
1063
1064                         public new void DataBindChildren ()
1065                         {
1066                                 base.DataBindChildren ();
1067                         }
1068
1069                         public new void EnsureID ()
1070                         {
1071                                 base.EnsureID ();
1072                         }
1073
1074                         public new bool HasEvents ()
1075                         {
1076                                 return base.HasEvents ();
1077                         }
1078                         #endif
1079                 }
1080
1081                 class DerivedControl : Control
1082                 {
1083                         ControlCollection coll;
1084
1085                         public DerivedControl ()
1086                         {
1087                                 coll = new ControlCollection (this);
1088                         }
1089
1090                         public override ControlCollection Controls
1091                         {
1092                                 get { return coll; }
1093                         }
1094
1095 #if NET_2_0
1096                         public bool DoIsViewStateEnabled
1097                         {
1098                                 get { return IsViewStateEnabled; }
1099                         }
1100
1101                         public new char ClientIDSeparator
1102                         {
1103                                 get { return base.ClientIDSeparator; }
1104                         }
1105
1106                         public new char IdSeparator
1107                         {
1108                                 get { return base.IdSeparator; }
1109                         }
1110
1111                         public new Stream OpenFile (string path)
1112                         {
1113                                 return base.OpenFile (path);
1114                         }
1115
1116                         public new ControlAdapter ResolveAdapter ()
1117                         {
1118                                 return base.ResolveAdapter ();
1119                         }
1120 #endif
1121                 }
1122
1123                 class NamingContainer : Control, INamingContainer
1124                 {
1125                 }
1126
1127                 class ControlWithTemplate : Control
1128                 {
1129                         ITemplate _template;
1130
1131                         [TemplateContainer (typeof (TemplateContainer))]
1132                         public ITemplate Template
1133                         {
1134                                 get { return _template; }
1135                                 set { _template = value; }
1136                         }
1137
1138                         protected override void CreateChildControls ()
1139                         {
1140                                 Controls.Clear ();
1141
1142                                 TemplateContainer container = new TemplateContainer ();
1143                                 Controls.Add (container);
1144
1145                                 if (Template != null)
1146                                         Template.InstantiateIn (container);
1147                         }
1148                 }
1149
1150                 class TemplateContainer : Control, INamingContainer
1151                 {
1152                 }
1153                 #endregion
1154         }
1155
1156 #if NET_2_0
1157         public class Customadaptercontrol : Control
1158         {
1159                 public new ControlAdapter Adapter {
1160                         get { return base.Adapter; }
1161                 }
1162
1163                 public new ControlAdapter ResolveAdapter ()
1164                 {
1165                         return base.ResolveAdapter ();
1166                 }
1167         }
1168
1169         public class Customadapter : ControlAdapter
1170         {
1171         }
1172
1173         class EnsureIDControl : Control {
1174                 public void DoEnsureID () {
1175                         EnsureID ();
1176                 }
1177         }
1178 #endif
1179
1180         public class ChildControlsCreatedControl : Control
1181         {
1182                 protected override void CreateChildControls () {
1183                         Controls.Add (new Control ());
1184                 }
1185
1186                 public void DoEnsureChildControls () {
1187                         EnsureChildControls ();
1188                 }
1189
1190                 public void SetChildControlsCreated (bool value) {
1191                         ChildControlsCreated = value;
1192                 }
1193         }
1194 }