2
0

TemplateControlCompilerTest.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. namespace MonoTests.System.Web.Compilation {
  13. public class ReadOnlyPropertyControl:TextBox {
  14. [Bindable (true)]
  15. public bool MyProp
  16. {
  17. get { return true; }
  18. }
  19. }
  20. #if NET_2_0
  21. public class BindTestDataItem
  22. {
  23. int data;
  24. public int Data {
  25. get { return data; }
  26. set { data = value; }
  27. }
  28. public BindTestDataItem (int data)
  29. {
  30. this.data = data;
  31. }
  32. }
  33. public class BindTestDataSource
  34. {
  35. public IList <BindTestDataItem> GetData ()
  36. {
  37. return new List <BindTestDataItem> {new BindTestDataItem (0), new BindTestDataItem (1)};
  38. }
  39. }
  40. #endif
  41. [TestFixture]
  42. public class TemplateControlCompilerTest
  43. {
  44. [TestFixtureSetUp]
  45. public void TemplateControlCompiler_Init ()
  46. {
  47. WebTest.CopyResource (GetType (), "ReadOnlyPropertyBind.aspx", "ReadOnlyPropertyBind.aspx");
  48. WebTest.CopyResource (GetType (), "ReadOnlyPropertyControl.ascx", "ReadOnlyPropertyControl.ascx");
  49. WebTest.CopyResource (GetType (), "TemplateControlParsingTest.aspx", "TemplateControlParsingTest.aspx");
  50. WebTest.CopyResource (GetType (), "ServerSideControlsInScriptBlock.aspx", "ServerSideControlsInScriptBlock.aspx");
  51. WebTest.CopyResource (GetType (), "ServerControlInClientSideComment.aspx", "ServerControlInClientSideComment.aspx");
  52. WebTest.CopyResource (GetType (), "UnquotedAngleBrackets.aspx", "UnquotedAngleBrackets.aspx");
  53. WebTest.CopyResource (GetType (), "FullTagsInText.aspx", "FullTagsInText.aspx");
  54. WebTest.CopyResource (GetType (), "TagsExpressionsAndCommentsInText.aspx", "TagsExpressionsAndCommentsInText.aspx");
  55. WebTest.CopyResource (GetType (), "NewlineInCodeExpression.aspx", "NewlineInCodeExpression.aspx");
  56. WebTest.CopyResource (GetType (), "DuplicateControlsInClientComment.aspx", "DuplicateControlsInClientComment.aspx");
  57. WebTest.CopyResource (GetType (), "TagsNestedInClientTag.aspx", "TagsNestedInClientTag.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. [Test]
  78. [NUnit.Framework.Category ("NunitWeb")]
  79. #if !TARGET_JVM
  80. [NUnit.Framework.Category ("NotWorking")]
  81. #endif
  82. public void ReadOnlyPropertyBindTest ()
  83. {
  84. new WebTest ("ReadOnlyPropertyBind.aspx").Run ();
  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. [Test]
  94. [ExpectedException ("System.Web.Compilation.CompilationException")]
  95. public void InvalidPropertyBindTest1 ()
  96. {
  97. new WebTest ("InvalidPropertyBind1.aspx").Run ();
  98. }
  99. [Test]
  100. [ExpectedException (typeof (HttpParseException))]
  101. public void InvalidPropertyBindTest2 ()
  102. {
  103. new WebTest ("InvalidPropertyBind2.aspx").Run ();
  104. }
  105. [Test]
  106. [ExpectedException ("System.Web.Compilation.CompilationException")]
  107. public void InvalidPropertyBindTest3 ()
  108. {
  109. new WebTest ("InvalidPropertyBind3.aspx").Run ();
  110. }
  111. [Test]
  112. [ExpectedException (typeof (HttpParseException))]
  113. public void InvalidPropertyBindTest4 ()
  114. {
  115. new WebTest ("InvalidPropertyBind4.aspx").Run ();
  116. }
  117. [Test]
  118. public void ValidPropertyBindTest1 ()
  119. {
  120. new WebTest ("ValidPropertyBind1.aspx").Run ();
  121. }
  122. [Test]
  123. public void ValidPropertyBindTest2 ()
  124. {
  125. new WebTest ("ValidPropertyBind2.aspx").Run ();
  126. }
  127. [Test]
  128. public void ValidPropertyBindTest3 ()
  129. {
  130. new WebTest ("ValidPropertyBind3.aspx").Run ();
  131. }
  132. [Test]
  133. public void ValidPropertyBindTest4 ()
  134. {
  135. new WebTest ("ValidPropertyBind4.aspx").Run ();
  136. }
  137. [Test]
  138. public void ValidPropertyBindTest5 ()
  139. {
  140. new WebTest ("ValidPropertyBind5.aspx").Run ();
  141. }
  142. // bug #493639
  143. [Test]
  144. public void NoBindForMethodsWithBindInNameTest ()
  145. {
  146. string pageHtml = new WebTest ("NoBindForMethodsWithBindInName.aspx").Run ();
  147. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  148. string originalHtml = "<span id=\"grid_ctl02_lblTest\">Test</span>";
  149. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  150. }
  151. // bug #498637
  152. [Test]
  153. public void LinkInHeadWithEmbeddedExpression ()
  154. {
  155. string pageHtml = new WebTest ("LinkInHeadWithEmbeddedExpression.aspx").Run ();
  156. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  157. string originalHtml = "<link href=\"Themes/Default/Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />";
  158. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  159. }
  160. [Test]
  161. public void ExpressionInListControl ()
  162. {
  163. string pageHtml = new WebTest ("ExpressionInListControl.aspx").Run ();
  164. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  165. string originalHtml = @"<select name=""DropDown1"" id=""DropDown1"">
  166. <option value=""strvalue"">str</option>
  167. </select>";
  168. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  169. }
  170. [Test (Description="Bug #508888")]
  171. public void ServerSideControlsInScriptBlock ()
  172. {
  173. string pageHtml = new WebTest ("ServerSideControlsInScriptBlock.aspx").Run ();
  174. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  175. string originalHtml = @"<script type=""text/javascript"">alert (escape(""reporting/location?report=ViewsByDate&minDate=minDate&maxDate=maxDate""));</script>";
  176. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  177. }
  178. [Test (Description="Bug #520024")]
  179. public void PreprocessorDirectivesInMarkup ()
  180. {
  181. // Just test if it doesn't throw an exception
  182. new WebTest ("PreprocessorDirectivesInMarkup.aspx").Run ();
  183. }
  184. [Test (Description="Bug #526449")]
  185. public void NewlineInCodeExpression ()
  186. {
  187. string pageHtml = new WebTest ("NewlineInCodeExpression.aspx").Run ();
  188. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  189. string originalHtml = "<a href=\"test\">bla</a>";
  190. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  191. }
  192. [Test (Description="Bug #524358")]
  193. [ExpectedException ("System.Web.Compilation.ParseException")]
  194. public void DuplicateControlsInClientComment ()
  195. {
  196. // Just test if it throws an exception
  197. new WebTest ("DuplicateControlsInClientComment.aspx").Run ();
  198. }
  199. #endif
  200. [Test (Description="Bug #323719")]
  201. public void TagsNestedInClientTag ()
  202. {
  203. string pageHtml = new WebTest ("TagsNestedInClientTag.aspx").Run ();
  204. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  205. string originalHtml = @"<script language=""javascript"" src=""/js/test.js"" type=""text/javascript""></script>
  206. <sometag language=""javascript"" src=""/js/test.js"" type=""text/javascript""></sometag>";
  207. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  208. }
  209. [Test (Description="Bug #517656")]
  210. public void ServerControlInClientSideComment ()
  211. {
  212. string pageHtml = new WebTest ("ServerControlInClientSideComment.aspx").Run ();
  213. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  214. string originalHtml = @"<!-- comment start
  215. <input id=""testBox"" type=""checkbox"" name=""testBox"" />
  216. comment end -->";
  217. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  218. }
  219. [Test]
  220. public void UnquotedAngleBrackets ()
  221. {
  222. // We just test if it doesn't throw an exception
  223. new WebTest ("UnquotedAngleBrackets.aspx").Run ();
  224. }
  225. [Test]
  226. public void FullTagsInText ()
  227. {
  228. // We just test if it doesn't throw an exception
  229. new WebTest ("FullTagsInText.aspx").Run ();
  230. }
  231. [Test]
  232. public void TagsExpressionsAndCommentsInText ()
  233. {
  234. // We just test if it doesn't throw an exception
  235. new WebTest ("TagsExpressionsAndCommentsInText.aspx").Run ();
  236. }
  237. [Test]
  238. public void ChildTemplatesTest ()
  239. {
  240. try {
  241. WebTest.Host.AppDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
  242. new WebTest ("TemplateControlParsingTest.aspx").Run ();
  243. } finally {
  244. WebTest.Host.AppDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
  245. }
  246. }
  247. [TestFixtureTearDown]
  248. public void TearDown ()
  249. {
  250. Thread.Sleep (100);
  251. WebTest.Unload ();
  252. }
  253. public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
  254. {
  255. if (e.Name != "System.Web_test")
  256. return null;
  257. return Assembly.GetExecutingAssembly ();
  258. }
  259. }
  260. }