ControlTest.cs add directive for 1.1
[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]
68                 public void UniqueID1 ()
69                 {
70                         // Standalone NC
71                         Control nc = new MyNC ();
72                         Assert.IsNull (nc.UniqueID, "nulltest");
73                 }
74
75                 [Test]
76                 public void UniqueID2 ()
77                 {
78                         // NC in NC
79                         Control nc = new MyNC ();
80                         Control nc2 = new MyNC ();
81                         nc2.Controls.Add (nc);
82                         Assert.IsNotNull (nc.UniqueID, "notnull");
83                         Assert.IsTrue (nc.UniqueID.IndexOfAny (new char[] { ':', '$' }) == -1, "separator");
84                 }
85
86                 [Test]
87                 public void UniqueID3 ()
88                 {
89                         // NC in control
90                         Control control = new Control ();
91                         Control nc = new MyNC ();
92
93                         control.Controls.Add (nc);
94                         Assert.IsNull (nc.UniqueID, "null");
95                 }
96
97                 [Test]
98                 public void UniqueID4 ()
99                 {
100                         // NC in control
101                         Control control = new Control ();
102                         Control nc = new MyNC ();
103
104                         nc.Controls.Add (control);
105                         Assert.IsNotNull (control.UniqueID, "notnull");
106                 }
107
108                 [Test]
109                 public void UniqueID5 ()
110                 {
111                         // NC in control
112                         Control control = new Control ();
113                         Control nc = new MyNC ();
114                         Control nc2 = new MyNC ();
115
116                         nc2.Controls.Add (nc);
117                         nc.Controls.Add (control);
118                         Assert.IsNotNull (control.UniqueID, "notnull");
119                         Assert.IsNull (nc2.ID, "null-1");
120                         Assert.IsNull (nc.ID, "null-2");
121                         Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char[] { ':', '$' }), "separator");
122                 }
123
124                 // From bug #76919: Control uses _controls instead of
125                 // Controls when RenderChildren is called.
126                 [Test]
127                 public void Controls1 ()
128                 {
129                         DerivedControl derived = new DerivedControl ();
130                         derived.Controls.Add (new LiteralControl ("hola"));
131                         StringWriter sw = new StringWriter ();
132                         HtmlTextWriter htw = new HtmlTextWriter (sw);
133                         derived.RenderControl (htw);
134                         string result = sw.ToString ();
135                         Assert.AreEqual ("", result, "#01");
136                 }
137
138 #if NET_2_0
139                 [Test]
140                 [Category ("NotWorking")]
141                 public void AppRelativeTemplateSourceDirectory ()
142                 {
143                         Control ctrl = new Control ();
144                         Assert.AreEqual ("", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#1");
145                         ctrl.AppRelativeTemplateSourceDirectory = "~/Fake";
146                         Assert.AreEqual ("~/Fake", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#2");
147                 }
148
149                 [Test]
150                 public void ApplyStyleSheetSkin ()
151                 {
152                         Page p = new Page ();
153                         p.StyleSheetTheme = "";
154                         Control c = new Control ();
155                         c.ApplyStyleSheetSkin (p);
156                 }
157
158                 [Test]
159                 [Category ("NotWorking")]
160                 [Category ("NunitWeb")]
161                 public void ApplyStyleSheetSkin_1 ()
162                 {
163                         WebTest.CopyResource (GetType (), "Theme2.skin", "App_Themes/Theme2/Theme2.skin");
164                         WebTest t = new WebTest ();
165                         PageDelegates pd = new PageDelegates ();
166                         pd.PreInit = ApplyStyleSheetSkin_PreInit;
167                         pd.Load = ApplyStyleSheetSkin_Load;
168                         t.Invoker = new PageInvoker (pd);
169                         string str = t.Run ();
170                 }
171                 public static void ApplyStyleSheetSkin_PreInit (Page p)
172                 {
173                         p.Theme = "Theme2";
174                 }
175                 public static void ApplyStyleSheetSkin_Load (Page p)
176                 {
177                         Label lbl = new Label ();
178                         lbl.ID = "StyleLbl";
179                         lbl.SkinID = "red";
180                         lbl.Text = "StyleLabel";
181                         p.Controls.Add (lbl);
182                         lbl.ApplyStyleSheetSkin (p);
183                         Assert.AreEqual (Color.Red, lbl.ForeColor, "ApplyStyleSheetSkin_BackColor");
184                         Assert.AreEqual ("TextFromSkinFile", lbl.Text, "ApplyStyleSheetSkin");
185                 }
186
187                 [Test]
188                 [Category ("NotWorking")]
189                 [Category ("NunitWeb")]
190                 public void ClearChildControlState ()
191                 {
192                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildControlState_Load));
193                         t.Run ();
194                         FormRequest fr = new FormRequest (t.Response, "form1");
195                         fr.Controls.Add ("__EVENTTARGET");
196                         fr.Controls.Add ("__EVENTARGUMENT");
197                         fr.Controls["__EVENTTARGET"].Value = "";
198                         fr.Controls["__EVENTARGUMENT"].Value = "";
199                         t.Request = fr;
200                         t.Run ();
201                 }
202                 public static void ClearChildControlState_Load (Page p)
203                 {
204                         ParentControlWithState c1 = new ParentControlWithState ();
205                         ControlWithState c2 = new ControlWithState ();
206                         c1.Controls.Add (c2);
207                         p.Form.Controls.Add (c1);
208                         if (!p.IsPostBack) {
209                                 c1.State = "State";
210                                 c2.State = "Cool";
211                         }
212                         else {
213                                 c1.ClearChildControlState ();
214                                 Assert.AreEqual ("State", c1.State, "ControlState#1");
215                                 Assert.AreEqual (null, c2.State, "ControlState#2");
216                         }
217                 }
218
219                 [Test]
220                 [Category ("NotWorking")]
221                 [Category ("NunitWeb")]
222                 public void ClearChildState ()
223                 {
224                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildState_Load));
225                         t.Run ();
226                         FormRequest fr = new FormRequest (t.Response, "form1");
227                         fr.Controls.Add ("__EVENTTARGET");
228                         fr.Controls.Add ("__EVENTARGUMENT");
229                         fr.Controls["__EVENTTARGET"].Value = "";
230                         fr.Controls["__EVENTARGUMENT"].Value = "";
231                         t.Request = fr;
232                         t.Run ();
233                 }
234                 public static void ClearChildState_Load (Page p)
235                 {
236                         ParentControlWithViewState c1 = new ParentControlWithViewState ();
237                         ParentControlWithViewState c2 = new ParentControlWithViewState ();
238                         c1.Controls.Add (c2);
239                         p.Form.Controls.Add (c1);
240                         if (!p.IsPostBack) {
241                                 c1.State = "State";
242                                 c2.State = "Cool";
243                                 c1.Viewstate = "VState";
244                                 c2.Viewstate = "VCool";
245                         }
246                         else {
247                                 Assert.AreEqual ("State", c1.State, "ControlState#1");
248                                 Assert.AreEqual ("VState", c1.Viewstate, "ControlViewState#1");
249                                 Assert.AreEqual (null, c2.State, "ControlState#2");
250                                 Assert.AreEqual (null, c2.Viewstate, "ControlViewState#2");
251                         }
252                 }
253
254                 [Test]
255                 public void DataBind ()
256                 {
257                         MyNC ctrl = new MyNC ();
258                         ctrl.DataBinding += new EventHandler (ctrl_DataBinding);
259                         Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
260                         ctrl.DataBind (false);
261                         Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
262                         ctrl.DataBind (true);
263                         Assert.AreEqual (true, _eventDataBinding, "After DataBinding");
264                 }
265                 bool _eventDataBinding;
266                 void ctrl_DataBinding (object sender, EventArgs e)
267                 {
268                         _eventDataBinding = true;
269                 }
270
271                 [Test]
272                 public void DataBindChildren ()
273                 {
274                         MyNC ctrl1 = new MyNC ();
275                         Control ctrl2 = new Control ();
276                         Control ctrl3 = new Control ();
277                         ctrl2.DataBinding += new EventHandler (ctrl2_DataBinding);
278                         ctrl3.DataBinding += new EventHandler (ctrl3_DataBinding);
279
280                         ctrl2.Controls.Add (ctrl3);
281                         ctrl1.Controls.Add (ctrl2);
282                         Assert.AreEqual (false, _eventChild1, "Before DataBinding#1");
283                         Assert.AreEqual (false, _eventChild2, "Before DataBinding#2");
284                         ctrl1.DataBindChildren ();
285                         Assert.AreEqual (true, _eventChild1, "After DataBinding#1");
286                         Assert.AreEqual (true, _eventChild2, "After DataBinding#2");
287                 }
288                 bool _eventChild1;
289                 bool _eventChild2;
290                 void ctrl3_DataBinding (object sender, EventArgs e)
291                 {
292                         _eventChild1 = true;
293                 }
294                 void ctrl2_DataBinding (object sender, EventArgs e)
295                 {
296                         _eventChild2 = true;
297                 }
298
299                 [Test]
300                 [Category ("NotWorking")] // Not implemented exception
301                 public void EnsureID ()
302                 {
303                         MyNC ctrl = new MyNC ();
304                         MyNC ctrl1 = new MyNC ();
305                         ctrl.Controls.Add (ctrl1);
306                         Page p = new Page ();
307                         p.Controls.Add (ctrl);
308                         ctrl.EnsureID ();
309                         if (ctrl.ID == string.Empty)
310                                 Assert.Fail ("EnsureID#1");
311                         if (ctrl1.ID == string.Empty)
312                                 Assert.Fail ("EnsureID#2");
313                 }
314
315                 [Test]
316                 [Category ("NotWorking")] // Not implemented exception
317                 public void Focus ()
318                 {
319                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (Focus_Load));
320                         string html = t.Run ();
321                         Assert.AreEqual (3, contain (html, "TestBox"), "Focus script not created");
322
323                 }
324                 public static void Focus_Load (Page p)
325                 {
326                         TextBox tbx = new TextBox ();
327                         tbx.ID = "TestBox";
328                         p.Controls.Add (tbx);
329                         tbx.Focus ();
330                 }
331                 int contain (string orig, string compare)
332                 {
333                         if (orig.IndexOf (compare) == -1)
334                                 return 0;
335                         return 1 + contain (orig.Substring (orig.IndexOf (compare) + compare.Length), compare);
336                 }
337
338                 [Test]
339                 [Category ("NotWorking")] // Not implemented exception
340                 public void HasEvent ()
341                 {
342                         MyNC ctrl1 = new MyNC ();
343                         Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#1");
344                         EventHandler ctrl_hdlr = new EventHandler (ctrl1_Init);
345                         ctrl1.Init += new EventHandler (ctrl1_Init);
346                         ctrl1.Init += ctrl_hdlr;
347                         Assert.AreEqual (true, ctrl1.HasEvents (), "HasEvent#2");
348                         // Dosn't work than removed handler
349                         //ctrl1.Init -= ctrl_hdlr;
350                         //Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#3");
351                 }
352                 void ctrl1_Init (object sender, EventArgs e)
353                 {
354                         throw new Exception ("The method or operation is not implemented.");
355                 }
356
357                 [Test]
358                 [Category ("NotWorking")]
359                 public void IsViewStateEnabled ()
360                 {
361                         DerivedControl c = new DerivedControl ();
362                         Assert.IsTrue (c.DoIsViewStateEnabled);
363                         Page p = new Page ();
364                         c.Page = p;
365                         p.Controls.Add (c);
366                         Assert.IsTrue (c.DoIsViewStateEnabled);
367                         p.EnableViewState = false;
368                         Assert.IsFalse (c.DoIsViewStateEnabled);
369                 }
370
371                 [Test]
372                 [Category ("NotWorking")]
373                 [Category ("NunitWeb")]
374                 public void ControlState ()
375                 {
376                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState_Load));
377                         t.Run ();
378                         FormRequest fr = new FormRequest (t.Response, "form1");
379                         fr.Controls.Add ("__EVENTTARGET");
380                         fr.Controls.Add ("__EVENTARGUMENT");
381                         fr.Controls["__EVENTTARGET"].Value = "";
382                         fr.Controls["__EVENTARGUMENT"].Value = "";
383                         t.Request = fr;
384                         t.Run ();
385                 }
386                 public static void ControlState_Load (Page p)
387                 {
388                         ControlWithState c1 = new ControlWithState ();
389                         ControlWithState c2 = new ControlWithState ();
390                         c1.Controls.Add (c2);
391                         p.Form.Controls.Add (c1);
392                         if (!p.IsPostBack) {
393                                 c1.State = "State";
394                                 c2.State = "Cool";
395                         }
396                         else {
397                                 ControlWithState c3 = new ControlWithState ();
398                                 p.Form.Controls.Add (c3);
399                                 Assert.AreEqual ("State", c1.State, "ControlState");
400                                 Assert.AreEqual ("Cool", c2.State, "ControlState");
401                         }
402                 }
403
404                 [Test]
405                 [Category ("NotWorking")] // Not implemented exception
406                 public void ClientIDSeparator ()
407                 {
408                         DerivedControl ctrl = new DerivedControl ();
409                         Assert.AreEqual (95, (int) ctrl.ClientIDSeparator, "ClientIDSeparator");
410                 }
411
412                 [Test]
413                 [Category ("NotWorking")] // Not implemented exception
414                 public void IDSeparator ()
415                 {
416                         DerivedControl ctrl = new DerivedControl ();
417                         Assert.AreEqual (36, (int) ctrl.IdSeparator, "IDSeparator");
418                 }
419
420                 [Test]
421                 [Category ("NunitWeb")]
422                 [Category ("NotWorking")]
423                 public void IsChildControlStateCleared ()
424                 {
425                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (IsChildControlStateCleared_Load));
426                         t.Run ();
427                         FormRequest fr = new FormRequest (t.Response, "form1");
428                         fr.Controls.Add ("__EVENTTARGET");
429                         fr.Controls.Add ("__EVENTARGUMENT");
430                         fr.Controls["__EVENTTARGET"].Value = "";
431                         fr.Controls["__EVENTARGUMENT"].Value = "";
432                         t.Request = fr;
433                         t.Run ();
434                 }
435                 public static void IsChildControlStateCleared_Load (Page p)
436                 {
437                         ParentControlWithState c1 = new ParentControlWithState ();
438                         ControlWithState c2 = new ControlWithState ();
439                         c1.Controls.Add (c2);
440                         p.Form.Controls.Add (c1);
441                         if (!p.IsPostBack) {
442                                 c1.State = "State";
443                                 c2.State = "Cool";
444                         }
445                         else {
446                                 c1.ClearChildControlState ();
447                                 Assert.AreEqual ("State", c1.State, "ControlState#1");
448                                 Assert.AreEqual (null, c2.State, "ControlState#2");
449                                 Assert.AreEqual (true, c1.IsChildControlStateCleared, "IsChildControlStateCleared");
450                         }
451                 }
452
453                 [Test]
454                 [Category ("NotWorking")] // Not implemented exception
455                 [Category ("NunitWeb")]
456                 public void LoadViewStateByID ()
457                 {
458                         ParentControlWithState c1 = new ParentControlWithState ();
459                         ControlWithState c2 = new ControlWithState ();
460                         c1.Controls.Add (c2);
461                         Assert.AreEqual (false, c1.LoadViewStateByID, "LoadViewStateByID#1");
462                 }
463
464                 [Test]
465                 [Category ("NotWorking")] // Not implemented exception
466                 [Category ("NunitWeb")]
467                 public void OpenFile ()
468                 {
469                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFile_Load));
470                         t.Run ();
471                 }
472                 public static void OpenFile_Load (Page p)
473                 {
474                         DerivedControl ctrl = new DerivedControl ();
475                         Stream strem = ctrl.OpenFile ("~/MyPage.aspx");
476                         Assert.IsNotNull (strem, "OpenFile failed");
477                 }
478
479                 [Test]
480                 [Category ("NotWorking")]
481                 [Category ("NunitWeb")]
482                 [ExpectedException (typeof (FileNotFoundException))]
483                 public void OpenFile_Exception ()
484                 {
485                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFileException_Load));
486                         t.Run ();
487                 }
488                 public static void OpenFileException_Load (Page p)
489                 {
490                         DerivedControl ctrl = new DerivedControl ();
491                         Stream strem = ctrl.OpenFile ("~/Fake.tmp");
492                 }
493
494                 //// MonoTests.SystemWeb.Framework limitation for Add_browsers - directory include in project
495                 //[Test]
496                 //[Category ("NunitWeb")]
497                 //public void ResolveAdapter_1 ()
498                 //{
499                 //        WebTest.CopyResource (GetType (), "adapters.browser", "App_Browsers/adapters.browser");
500                 //        WebTest t = new WebTest (PageInvoker.CreateOnInit (ResolveAdapter_Init));
501                 //        string html = t.Run ();
502                 //}
503                 //public static void ResolveAdapter_Init (Page p)
504                 //{
505                 //        Customadaptercontrol ctrl = new Customadaptercontrol ();
506                 //        p.Controls.Add (ctrl);
507                 //        ctrl.Load += new EventHandler (ctrl_Load);
508                 //}
509                 //static void ctrl_Load (object sender, EventArgs e)
510                 //{
511                 //        Assert.IsNotNull (((Customadaptercontrol) sender).ResolveAdapter (), "ResolveAdapter Failed#1");
512                 //        Assert.AreEqual ("Customadapter", ((Customadaptercontrol) sender).ResolveAdapter ().ToString (), "ResolveAdapter Failed#2");
513                 //}
514
515                 [Test]
516                 [Category ("NunitWeb")]
517                 public void ResolveClientUrl ()
518                 {
519                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveClientUrl_Load));
520                         string html = t.Run ();
521                 }
522                 public static void ResolveClientUrl_Load (Page p)
523                 {
524                         Control ctrl = new Control ();
525                         p.Controls.Add (ctrl);
526                         string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
527                         Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
528                 }
529
530                 [Test]
531                 [Category ("NotWorking")] // Not implemented exception
532                 public void ResolveAdapter_2 ()
533                 {
534                         DerivedControl ctrl = new DerivedControl ();
535                         Assert.AreEqual (null, ctrl.ResolveAdapter (), "ResolveAdapter");
536                 }
537
538                 [Test]
539                 public void EnableTheming ()
540                 {
541                         DerivedControl ctrl = new DerivedControl ();
542                         Assert.AreEqual (true, ctrl.EnableTheming, "EnableTheming#1");
543                         ctrl.EnableTheming = false;
544                         Assert.AreEqual (false, ctrl.EnableTheming, "EnableTheming#2");
545                 }
546
547 #endif
548                 [Test]
549                 public void BindingContainer ()
550                 {
551                         ControlWithTemplate c = new ControlWithTemplate ();
552                         c.Template = new CompiledTemplateBuilder (new BuildTemplateMethod (BindingContainer_BuildTemplate));
553
554                         // cause CreateChildControls called
555                         c.FindControl ("stam");
556                 }
557                 static void BindingContainer_BuildTemplate (Control control)
558                 {
559                         Control child1 = new Control ();
560                         control.Controls.Add (child1);
561
562                         Assert.IsTrue (Object.ReferenceEquals (child1.NamingContainer, control), "NamingContainer #1");
563                         Assert.IsTrue (Object.ReferenceEquals (child1.BindingContainer, control), "BindingContainer #1");
564
565                         NamingContainer nc = new NamingContainer ();
566                         Control child2 = new Control ();
567                         nc.Controls.Add (child2);
568                         control.Controls.Add (nc);
569
570                         Assert.IsTrue (Object.ReferenceEquals (child2.NamingContainer, nc), "NamingContainer #2");
571                         Assert.IsTrue (Object.ReferenceEquals (child2.BindingContainer, nc), "BindingContainer #2");
572
573 #if NET_2_0
574                         // DetailsViewPagerRow marked to be not BindingContainer 
575                         DetailsViewPagerRow row = new DetailsViewPagerRow (0, DataControlRowType.Pager, DataControlRowState.Normal);
576                         TableCell cell = new TableCell ();
577                         Control child3 = new Control ();
578                         cell.Controls.Add (child3);
579                         row.Cells.Add (cell);
580                         control.Controls.Add (row);
581
582                         Assert.IsTrue (Object.ReferenceEquals (child3.NamingContainer, row), "NamingContainer #3");
583                         Assert.IsTrue (Object.ReferenceEquals (child3.BindingContainer, control), "BindingContainer #3");
584 #endif
585                 }
586 #if NET_2_0
587                 [Test]
588                 public void Contorl_Adapter ()
589                 {
590                         MyNC ctr = new MyNC ();
591                         Assert.AreEqual (null, ctr.Adapter (), "Adapter");
592                 }
593 #endif
594 #if NET_2_0
595                 [TestFixtureTearDown]
596                 public void Tear_down ()
597                 {
598                         WebTest.Unload ();
599                 }
600 #endif
601
602                 #region helpcalsses
603 #if NET_2_0
604                 class ControlWithState : Control
605                 {
606                         string _state;
607
608                         public string State
609                         {
610                                 get { return _state; }
611                                 set { _state = value; }
612                         }
613
614                         protected override void OnInit (EventArgs e)
615                         {
616                                 base.OnInit (e);
617                                 Page.RegisterRequiresControlState (this);
618                                 Page.RegisterRequiresControlState (this);
619                         }
620
621                         protected override object SaveControlState ()
622                         {
623                                 return State;
624                         }
625
626                         protected override void LoadControlState (object savedState)
627                         {
628                                 State = (string) savedState;
629                         }
630
631                         public new void ClearChildControlState ()
632                         {
633                                 base.ClearChildControlState ();
634                         }
635                 }
636
637                 class ParentControlWithState : Control
638                 {
639                         string _state;
640                         public string State
641                         {
642                                 get { return _state; }
643                                 set { _state = value; }
644                         }
645
646                         protected override void OnInit (EventArgs e)
647                         {
648                                 base.OnInit (e);
649                                 Page.RegisterRequiresControlState (this);
650                                 Page.RegisterRequiresControlState (this);
651                         }
652
653                         protected override void CreateChildControls ()
654                         {
655                                 Controls.Clear ();
656                                 base.CreateChildControls ();
657                                 ClearChildControlState ();
658                         }
659
660                         protected override object SaveControlState ()
661                         {
662                                 return State;
663                         }
664
665                         protected override void LoadControlState (object savedState)
666                         {
667                                 State = (string) savedState;
668                         }
669
670                         public new void ClearChildControlState ()
671                         {
672                                 base.ClearChildControlState ();
673                         }
674
675                         public new bool IsChildControlStateCleared
676                         {
677                                 get { return base.IsChildControlStateCleared; }
678                         }
679
680                         public new bool LoadViewStateByID
681                         {
682                                 get { return base.LoadViewStateByID; }
683                         }
684                 }
685
686                 class ParentControlWithViewState : Control
687                 {
688
689                         string _viewstate;
690                         public string Viewstate
691                         {
692                                 get { return _viewstate; }
693                                 set { _viewstate = value; }
694                         }
695                         string _state;
696                         public string State
697                         {
698                                 get { return _state; }
699                                 set { _state = value; }
700                         }
701
702                         protected override void OnInit (EventArgs e)
703                         {
704                                 base.OnInit (e);
705                                 Page.RegisterRequiresControlState (this);
706                                 Page.RegisterRequiresControlState (this);
707                         }
708
709                         protected override void CreateChildControls ()
710                         {
711                                 Controls.Clear ();
712                                 base.CreateChildControls ();
713                                 ClearChildControlState ();
714                         }
715
716                         protected override object SaveViewState ()
717                         {
718                                 return Viewstate;
719                         }
720
721                         protected override void LoadViewState (object savedState)
722                         {
723                                 Viewstate = (string) savedState;
724                         }
725
726                         protected override object SaveControlState ()
727                         {
728                                 return State;
729                         }
730
731                         protected override void LoadControlState (object savedState)
732                         {
733                                 State = (string) savedState;
734                         }
735
736                         public new void ClearChildControlState ()
737                         {
738                                 base.ClearChildControlState ();
739                         }
740                 }
741
742                 class MyNC : Control, INamingContainer
743                 {
744                         public ControlAdapter Adapter ()
745                         {
746                                 return base.Adapter;
747                         }
748
749                         public new void DataBind (bool opt)
750                         {
751                                 base.DataBind (opt);
752                         }
753
754                         public new void DataBindChildren ()
755                         {
756                                 base.DataBindChildren ();
757                         }
758
759                         public new void EnsureID ()
760                         {
761                                 base.EnsureID ();
762                         }
763
764                         public new bool HasEvents ()
765                         {
766                                 return base.HasEvents ();
767                         }
768                 }
769 #endif
770                 class DerivedControl : Control
771                 {
772                         ControlCollection coll;
773
774                         public DerivedControl ()
775                         {
776                                 coll = new ControlCollection (this);
777                         }
778
779                         public override ControlCollection Controls
780                         {
781                                 get { return coll; }
782                         }
783
784 #if NET_2_0
785                         public bool DoIsViewStateEnabled
786                         {
787                                 get { return IsViewStateEnabled; }
788                         }
789
790                         public new char ClientIDSeparator
791                         {
792                                 get { return base.ClientIDSeparator; }
793                         }
794
795                         public new char IdSeparator
796                         {
797                                 get { return base.IdSeparator; }
798                         }
799
800                         public new Stream OpenFile (string path)
801                         {
802                                 return base.OpenFile (path);
803                         }
804
805                         public new ControlAdapter ResolveAdapter ()
806                         {
807                                 return base.ResolveAdapter ();
808                         }
809 #endif
810                 }
811
812                 class NamingContainer : Control, INamingContainer
813                 {
814                 }
815
816                 class ControlWithTemplate : Control
817                 {
818                         ITemplate _template;
819
820                         [TemplateContainer (typeof (TemplateContainer))]
821                         public ITemplate Template
822                         {
823                                 get { return _template; }
824                                 set { _template = value; }
825                         }
826
827                         protected override void CreateChildControls ()
828                         {
829                                 Controls.Clear ();
830
831                                 TemplateContainer container = new TemplateContainer ();
832                                 Controls.Add (container);
833
834                                 if (Template != null)
835                                         Template.InstantiateIn (container);
836                         }
837                 }
838
839                 class TemplateContainer : Control, INamingContainer
840                 {
841                 }
842                 #endregion
843         }
844
845 #if NET_2_0
846         public class Customadaptercontrol : Control
847         {
848                 public new ControlAdapter ResolveAdapter ()
849                 {
850                         return base.ResolveAdapter ();
851                 }
852         }
853
854         public class Customadapter : ControlAdapter
855         {
856         }
857 #endif
858 }
859
860