b09207f55c969fe7c29bcbfa1550e34bc54b9932
[mono.git] / mcs / class / System.Web / Test / System.Web.Compilation / TemplateControlCompilerTest.cs
1 using System;
2 using System.Collections.Generic;
3 using MonoTests.SystemWeb.Framework;
4 using MonoTests.stand_alone.WebHarness;
5 using NUnit.Framework;
6 using System.Web;
7 using System.Web.Compilation;
8 using System.Web.UI.WebControls;
9 using System.Reflection;
10 using System.ComponentModel;
11 using System.Threading;
12
13 namespace MonoTests.System.Web.Compilation {
14         public class ReadOnlyPropertyControl:TextBox {
15                 [Bindable (true)]
16                 public bool MyProp
17                 {
18                         get { return true; }
19                 }
20
21         }
22
23 #if NET_2_0
24         public class BindTestDataItem
25         {
26                 int data;
27                 public int Data {
28                         get { return data; }
29                         set { data = value; }
30                 }
31
32                 public BindTestDataItem (int data)
33                 {
34                         this.data = data;
35                 }
36         }
37         
38         public class BindTestDataSource 
39         {
40                 public IList <BindTestDataItem> GetData ()
41                 {
42                         return new List <BindTestDataItem> {new BindTestDataItem (0), new BindTestDataItem (1)};
43                 }
44         }
45 #endif
46         
47         [TestFixture]
48         public class TemplateControlCompilerTest
49         {
50                 [TestFixtureSetUp]
51                 public void TemplateControlCompiler_Init ()
52                 {
53                         WebTest.CopyResource (GetType (), "ReadOnlyPropertyBind.aspx", "ReadOnlyPropertyBind.aspx");
54                         WebTest.CopyResource (GetType (), "ReadOnlyPropertyControl.ascx", "ReadOnlyPropertyControl.ascx");
55                         WebTest.CopyResource (GetType (), "TemplateControlParsingTest.aspx", "TemplateControlParsingTest.aspx");
56                         WebTest.CopyResource (GetType (), "ServerSideControlsInScriptBlock.aspx", "ServerSideControlsInScriptBlock.aspx");
57 #if NET_2_0
58                         WebTest.CopyResource (GetType (), "InvalidPropertyBind1.aspx", "InvalidPropertyBind1.aspx");
59                         WebTest.CopyResource (GetType (), "InvalidPropertyBind2.aspx", "InvalidPropertyBind2.aspx");
60                         WebTest.CopyResource (GetType (), "InvalidPropertyBind3.aspx", "InvalidPropertyBind3.aspx");
61                         WebTest.CopyResource (GetType (), "InvalidPropertyBind4.aspx", "InvalidPropertyBind4.aspx");
62                         WebTest.CopyResource (GetType (), "ValidPropertyBind1.aspx", "ValidPropertyBind1.aspx");
63                         WebTest.CopyResource (GetType (), "ValidPropertyBind2.aspx", "ValidPropertyBind2.aspx");
64                         WebTest.CopyResource (GetType (), "ValidPropertyBind3.aspx", "ValidPropertyBind3.aspx");
65                         WebTest.CopyResource (GetType (), "ValidPropertyBind4.aspx", "ValidPropertyBind4.aspx");
66                         WebTest.CopyResource (GetType (), "ValidPropertyBind5.aspx", "ValidPropertyBind5.aspx");
67                         WebTest.CopyResource (GetType (), "NoBindForMethodsWithBindInName.aspx", "NoBindForMethodsWithBindInName.aspx");
68                         WebTest.CopyResource (GetType (), "ReadWritePropertyControl.ascx", "ReadWritePropertyControl.ascx");
69                         WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.aspx", "ContentPlaceHolderInTemplate.aspx");
70                         WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.master", "ContentPlaceHolderInTemplate.master");
71                         WebTest.CopyResource (GetType (), "LinkInHeadWithEmbeddedExpression.aspx", "LinkInHeadWithEmbeddedExpression.aspx");
72                         WebTest.CopyResource (GetType (), "ExpressionInListControl.aspx", "ExpressionInListControl.aspx");
73 #endif
74                 }
75                 
76                 [Test]
77                 [NUnit.Framework.Category ("NunitWeb")]
78 #if !TARGET_JVM
79                 [NUnit.Framework.Category ("NotWorking")]
80 #endif
81                 public void ReadOnlyPropertyBindTest ()
82                 {
83                         new WebTest ("ReadOnlyPropertyBind.aspx").Run ();
84                 }
85
86 #if NET_2_0
87                 // Test for bug #449970
88                 [Test]
89                 public void MasterPageContentPlaceHolderInTemplate ()
90                 {
91                         new WebTest ("ContentPlaceHolderInTemplate.aspx").Run ();
92                 }
93                 
94                 [Test]
95                 [ExpectedException (typeof (CompilationException))]
96                 public void InvalidPropertyBindTest1 ()
97                 {
98                         new WebTest ("InvalidPropertyBind1.aspx").Run ();
99                 }
100
101                 [Test]
102                 [ExpectedException (typeof (HttpParseException))]
103                 public void InvalidPropertyBindTest2 ()
104                 {
105                         new WebTest ("InvalidPropertyBind2.aspx").Run ();
106                 }
107
108                 [Test]
109                 [ExpectedException (typeof (CompilationException))]
110                 public void InvalidPropertyBindTest3 ()
111                 {
112                         new WebTest ("InvalidPropertyBind3.aspx").Run ();
113                 }
114
115                 [Test]
116                 [ExpectedException (typeof (HttpParseException))]
117                 public void InvalidPropertyBindTest4 ()
118                 {
119                         new WebTest ("InvalidPropertyBind4.aspx").Run ();
120                 }
121
122                 [Test]
123                 public void ValidPropertyBindTest1 ()
124                 {
125                         new WebTest ("ValidPropertyBind1.aspx").Run ();
126                 }
127
128                 [Test]
129                 public void ValidPropertyBindTest2 ()
130                 {
131                         new WebTest ("ValidPropertyBind2.aspx").Run ();
132                 }
133
134                 [Test]
135                 public void ValidPropertyBindTest3 ()
136                 {
137                         new WebTest ("ValidPropertyBind3.aspx").Run ();
138                 }
139
140                 [Test]
141                 public void ValidPropertyBindTest4 ()
142                 {
143                         new WebTest ("ValidPropertyBind4.aspx").Run ();
144                 }
145
146                 [Test]
147                 public void ValidPropertyBindTest5 ()
148                 {
149                         new WebTest ("ValidPropertyBind5.aspx").Run ();
150                 }
151
152                 // bug #493639
153                 [Test]
154                 public void NoBindForMethodsWithBindInNameTest ()
155                 {
156                         string pageHtml = new WebTest ("NoBindForMethodsWithBindInName.aspx").Run ();
157                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
158                         string originalHtml = "<span id=\"grid_ctl02_lblTest\">Test</span>";
159                         
160                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
161                 }
162
163                 // bug #498637
164                 [Test]
165                 public void LinkInHeadWithEmbeddedExpression ()
166                 {
167                         string pageHtml = new WebTest ("LinkInHeadWithEmbeddedExpression.aspx").Run ();
168                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
169                         string originalHtml = "<link href=\"Themes/Default/Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />";
170
171                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
172                 }
173
174                 [Test]
175                 public void ExpressionInListControl ()
176                 {
177                         string pageHtml = new WebTest ("ExpressionInListControl.aspx").Run ();
178                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
179                         string originalHtml = @"<select name=""DropDown1"" id=""DropDown1"">
180         <option value=""strvalue"">str</option>
181
182 </select>";
183                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
184                 }
185
186                 [Test (Description="Bug #508888")]
187                 public void ServerSideControlsInScriptBlock ()
188                 {
189                         string pageHtml = new WebTest ("ServerSideControlsInScriptBlock.aspx").Run ();
190                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
191                         string originalHtml = @"<script type=""text/javascript"">alert (escape(""reporting/location?report=ViewsByDate&minDate=minDate&maxDate=maxDate""));</script>";
192                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
193                 }
194 #endif
195                 
196                 [Test]
197                 public void ChildTemplatesTest ()
198                 {
199                         try {
200                                 WebTest.Host.AppDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
201                                 new WebTest ("TemplateControlParsingTest.aspx").Run ();
202                         } finally {
203                                 WebTest.Host.AppDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
204                         }
205                 }
206                 
207                 [TestFixtureTearDown]
208                 public void TearDown ()
209                 {
210                         Thread.Sleep (100);
211                         WebTest.Unload ();
212                 }
213
214                 public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
215                 {
216                         if (e.Name != "System.Web_test")
217                                 return null;
218
219                         return Assembly.GetExecutingAssembly ();
220                 }
221         }
222 }
223