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