TemplateControlCompilerTest.cs 7.7 KB

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