2009-08-17 Rodrigo Kumpera <rkumpera@novell.com>
[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                         WebTest.CopyResource (GetType (), "ServerControlInClientSideComment.aspx", "ServerControlInClientSideComment.aspx");
58                         WebTest.CopyResource (GetType (), "UnquotedAngleBrackets.aspx", "UnquotedAngleBrackets.aspx");
59                         WebTest.CopyResource (GetType (), "FullTagsInText.aspx", "FullTagsInText.aspx");
60                         WebTest.CopyResource (GetType (), "TagsExpressionsAndCommentsInText.aspx", "TagsExpressionsAndCommentsInText.aspx");
61                         WebTest.CopyResource (GetType (), "NewlineInCodeExpression.aspx", "NewlineInCodeExpression.aspx");
62                         WebTest.CopyResource (GetType (), "DuplicateControlsInClientComment.aspx", "DuplicateControlsInClientComment.aspx");
63 #if NET_2_0
64                         WebTest.CopyResource (GetType (), "InvalidPropertyBind1.aspx", "InvalidPropertyBind1.aspx");
65                         WebTest.CopyResource (GetType (), "InvalidPropertyBind2.aspx", "InvalidPropertyBind2.aspx");
66                         WebTest.CopyResource (GetType (), "InvalidPropertyBind3.aspx", "InvalidPropertyBind3.aspx");
67                         WebTest.CopyResource (GetType (), "InvalidPropertyBind4.aspx", "InvalidPropertyBind4.aspx");
68                         WebTest.CopyResource (GetType (), "ValidPropertyBind1.aspx", "ValidPropertyBind1.aspx");
69                         WebTest.CopyResource (GetType (), "ValidPropertyBind2.aspx", "ValidPropertyBind2.aspx");
70                         WebTest.CopyResource (GetType (), "ValidPropertyBind3.aspx", "ValidPropertyBind3.aspx");
71                         WebTest.CopyResource (GetType (), "ValidPropertyBind4.aspx", "ValidPropertyBind4.aspx");
72                         WebTest.CopyResource (GetType (), "ValidPropertyBind5.aspx", "ValidPropertyBind5.aspx");
73                         WebTest.CopyResource (GetType (), "NoBindForMethodsWithBindInName.aspx", "NoBindForMethodsWithBindInName.aspx");
74                         WebTest.CopyResource (GetType (), "ReadWritePropertyControl.ascx", "ReadWritePropertyControl.ascx");
75                         WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.aspx", "ContentPlaceHolderInTemplate.aspx");
76                         WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.master", "ContentPlaceHolderInTemplate.master");
77                         WebTest.CopyResource (GetType (), "LinkInHeadWithEmbeddedExpression.aspx", "LinkInHeadWithEmbeddedExpression.aspx");
78                         WebTest.CopyResource (GetType (), "ExpressionInListControl.aspx", "ExpressionInListControl.aspx");
79                         WebTest.CopyResource (GetType (), "PreprocessorDirectivesInMarkup.aspx", "PreprocessorDirectivesInMarkup.aspx");
80 #endif
81                 }
82                 
83                 [Test]
84                 [NUnit.Framework.Category ("NunitWeb")]
85 #if !TARGET_JVM
86                 [NUnit.Framework.Category ("NotWorking")]
87 #endif
88                 public void ReadOnlyPropertyBindTest ()
89                 {
90                         new WebTest ("ReadOnlyPropertyBind.aspx").Run ();
91                 }
92
93 #if NET_2_0
94                 // Test for bug #449970
95                 [Test]
96                 public void MasterPageContentPlaceHolderInTemplate ()
97                 {
98                         new WebTest ("ContentPlaceHolderInTemplate.aspx").Run ();
99                 }
100                 
101                 [Test]
102                 [ExpectedException ("System.Web.Compilation.CompilationException")]
103                 public void InvalidPropertyBindTest1 ()
104                 {
105                         new WebTest ("InvalidPropertyBind1.aspx").Run ();
106                 }
107
108                 [Test]
109                 [ExpectedException (typeof (HttpParseException))]
110                 public void InvalidPropertyBindTest2 ()
111                 {
112                         new WebTest ("InvalidPropertyBind2.aspx").Run ();
113                 }
114
115                 [Test]
116                 [ExpectedException ("System.Web.Compilation.CompilationException")]
117                 public void InvalidPropertyBindTest3 ()
118                 {
119                         new WebTest ("InvalidPropertyBind3.aspx").Run ();
120                 }
121
122                 [Test]
123                 [ExpectedException (typeof (HttpParseException))]
124                 public void InvalidPropertyBindTest4 ()
125                 {
126                         new WebTest ("InvalidPropertyBind4.aspx").Run ();
127                 }
128
129                 [Test]
130                 public void ValidPropertyBindTest1 ()
131                 {
132                         new WebTest ("ValidPropertyBind1.aspx").Run ();
133                 }
134
135                 [Test]
136                 public void ValidPropertyBindTest2 ()
137                 {
138                         new WebTest ("ValidPropertyBind2.aspx").Run ();
139                 }
140
141                 [Test]
142                 public void ValidPropertyBindTest3 ()
143                 {
144                         new WebTest ("ValidPropertyBind3.aspx").Run ();
145                 }
146
147                 [Test]
148                 public void ValidPropertyBindTest4 ()
149                 {
150                         new WebTest ("ValidPropertyBind4.aspx").Run ();
151                 }
152
153                 [Test]
154                 public void ValidPropertyBindTest5 ()
155                 {
156                         new WebTest ("ValidPropertyBind5.aspx").Run ();
157                 }
158
159                 // bug #493639
160                 [Test]
161                 public void NoBindForMethodsWithBindInNameTest ()
162                 {
163                         string pageHtml = new WebTest ("NoBindForMethodsWithBindInName.aspx").Run ();
164                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
165                         string originalHtml = "<span id=\"grid_ctl02_lblTest\">Test</span>";
166                         
167                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
168                 }
169
170                 // bug #498637
171                 [Test]
172                 public void LinkInHeadWithEmbeddedExpression ()
173                 {
174                         string pageHtml = new WebTest ("LinkInHeadWithEmbeddedExpression.aspx").Run ();
175                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
176                         string originalHtml = "<link href=\"Themes/Default/Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />";
177
178                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
179                 }
180
181                 [Test]
182                 public void ExpressionInListControl ()
183                 {
184                         string pageHtml = new WebTest ("ExpressionInListControl.aspx").Run ();
185                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
186                         string originalHtml = @"<select name=""DropDown1"" id=""DropDown1"">
187         <option value=""strvalue"">str</option>
188
189 </select>";
190                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
191                 }
192
193                 [Test (Description="Bug #508888")]
194                 public void ServerSideControlsInScriptBlock ()
195                 {
196                         string pageHtml = new WebTest ("ServerSideControlsInScriptBlock.aspx").Run ();
197                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
198                         string originalHtml = @"<script type=""text/javascript"">alert (escape(""reporting/location?report=ViewsByDate&minDate=minDate&maxDate=maxDate""));</script>";
199                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
200                 }
201
202                 [Test (Description="Bug #520024")]
203                 public void PreprocessorDirectivesInMarkup ()
204                 {
205                         // Just test if it doesn't throw an exception
206                         new WebTest ("PreprocessorDirectivesInMarkup.aspx").Run ();
207                 }
208
209                 [Test (Description="Bug #526449")]
210                 public void NewlineInCodeExpression ()
211                 {
212                         string pageHtml = new WebTest ("NewlineInCodeExpression.aspx").Run ();
213                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
214                         string originalHtml = "<a href=\"test\">bla</a>";
215                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
216                 }
217 #endif
218
219                 [Test (Description="Bug #525104")]
220                 [ExpectedException (typeof (HttpException))]
221                 public void DuplicateControlsInClientComment ()
222                 {
223                         // Just test if it throws an exception
224                         new WebTest ("DuplicateControlsInClientCommment.aspx").Run ();
225                 }
226                 
227                 [Test (Description="Bug #517656")]
228                 public void ServerControlInClientSideComment ()
229                 {
230                         string pageHtml = new WebTest ("ServerControlInClientSideComment.aspx").Run ();
231                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
232                         string originalHtml = @"<!-- comment start
233   <input id=""testBox"" type=""checkbox"" name=""testBox"" />
234 comment end -->";
235                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
236                 }
237
238                 [Test]
239                 public void UnquotedAngleBrackets ()
240                 {
241                         // We just test if it doesn't throw an exception
242                         new WebTest ("UnquotedAngleBrackets.aspx").Run ();
243                 }
244
245                 [Test]
246                 public void FullTagsInText ()
247                 {
248                         // We just test if it doesn't throw an exception
249                         new WebTest ("FullTagsInText.aspx").Run ();
250                 }
251
252                 [Test]
253                 public void TagsExpressionsAndCommentsInText ()
254                 {
255                         // We just test if it doesn't throw an exception
256                         new WebTest ("TagsExpressionsAndCommentsInText.aspx").Run ();
257                 }
258                 
259                 [Test]
260                 public void ChildTemplatesTest ()
261                 {
262                         try {
263                                 WebTest.Host.AppDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
264                                 new WebTest ("TemplateControlParsingTest.aspx").Run ();
265                         } finally {
266                                 WebTest.Host.AppDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
267                         }
268                 }
269                 
270                 [TestFixtureTearDown]
271                 public void TearDown ()
272                 {
273                         Thread.Sleep (100);
274                         WebTest.Unload ();
275                 }
276
277                 public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
278                 {
279                         if (e.Name != "System.Web_test")
280                                 return null;
281
282                         return Assembly.GetExecutingAssembly ();
283                 }
284         }
285 }
286