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