TemplateControlCompilerTest.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. public class BindTestDataItem
  21. {
  22. int data;
  23. public int Data {
  24. get { return data; }
  25. set { data = value; }
  26. }
  27. public BindTestDataItem (int data)
  28. {
  29. this.data = data;
  30. }
  31. }
  32. public class BindTestDataSource
  33. {
  34. public IList <BindTestDataItem> GetData ()
  35. {
  36. return new List <BindTestDataItem> {new BindTestDataItem (0), new BindTestDataItem (1)};
  37. }
  38. }
  39. [TestFixture]
  40. public class TemplateControlCompilerTest
  41. {
  42. [TestFixtureSetUp]
  43. public void TemplateControlCompiler_Init ()
  44. {
  45. WebTest.CopyResource (GetType (), "ReadOnlyPropertyBind.aspx", "ReadOnlyPropertyBind.aspx");
  46. WebTest.CopyResource (GetType (), "ReadOnlyPropertyControl.ascx", "ReadOnlyPropertyControl.ascx");
  47. WebTest.CopyResource (GetType (), "TemplateControlParsingTest.aspx", "TemplateControlParsingTest.aspx");
  48. WebTest.CopyResource (GetType (), "ServerSideControlsInScriptBlock.aspx", "ServerSideControlsInScriptBlock.aspx");
  49. WebTest.CopyResource (GetType (), "ServerControlInClientSideComment.aspx", "ServerControlInClientSideComment.aspx");
  50. WebTest.CopyResource (GetType (), "UnquotedAngleBrackets.aspx", "UnquotedAngleBrackets.aspx");
  51. WebTest.CopyResource (GetType (), "FullTagsInText.aspx", "FullTagsInText.aspx");
  52. WebTest.CopyResource (GetType (), "TagsExpressionsAndCommentsInText.aspx", "TagsExpressionsAndCommentsInText.aspx");
  53. WebTest.CopyResource (GetType (), "NewlineInCodeExpression.aspx", "NewlineInCodeExpression.aspx");
  54. WebTest.CopyResource (GetType (), "DuplicateControlsInClientComment.aspx", "DuplicateControlsInClientComment.aspx");
  55. WebTest.CopyResource (GetType (), "TagsNestedInClientTag.aspx", "TagsNestedInClientTag.aspx");
  56. WebTest.CopyResource (GetType (), "ConditionalClientComments.aspx", "ConditionalClientComments.aspx");
  57. WebTest.CopyResource (GetType (), "InvalidPropertyBind1.aspx", "InvalidPropertyBind1.aspx");
  58. WebTest.CopyResource (GetType (), "InvalidPropertyBind2.aspx", "InvalidPropertyBind2.aspx");
  59. WebTest.CopyResource (GetType (), "InvalidPropertyBind3.aspx", "InvalidPropertyBind3.aspx");
  60. WebTest.CopyResource (GetType (), "InvalidPropertyBind4.aspx", "InvalidPropertyBind4.aspx");
  61. WebTest.CopyResource (GetType (), "ValidPropertyBind1.aspx", "ValidPropertyBind1.aspx");
  62. WebTest.CopyResource (GetType (), "ValidPropertyBind2.aspx", "ValidPropertyBind2.aspx");
  63. WebTest.CopyResource (GetType (), "ValidPropertyBind3.aspx", "ValidPropertyBind3.aspx");
  64. WebTest.CopyResource (GetType (), "ValidPropertyBind4.aspx", "ValidPropertyBind4.aspx");
  65. WebTest.CopyResource (GetType (), "ValidPropertyBind5.aspx", "ValidPropertyBind5.aspx");
  66. WebTest.CopyResource (GetType (), "NoBindForMethodsWithBindInName.aspx", "NoBindForMethodsWithBindInName.aspx");
  67. WebTest.CopyResource (GetType (), "ReadWritePropertyControl.ascx", "ReadWritePropertyControl.ascx");
  68. WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.aspx", "ContentPlaceHolderInTemplate.aspx");
  69. WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.master", "ContentPlaceHolderInTemplate.master");
  70. WebTest.CopyResource (GetType (), "LinkInHeadWithEmbeddedExpression.aspx", "LinkInHeadWithEmbeddedExpression.aspx");
  71. WebTest.CopyResource (GetType (), "ExpressionInListControl.aspx", "ExpressionInListControl.aspx");
  72. WebTest.CopyResource (GetType (), "PreprocessorDirectivesInMarkup.aspx", "PreprocessorDirectivesInMarkup.aspx");
  73. WebTest.CopyResource (GetType (), "OneLetterIdentifierInCodeRender.aspx", "OneLetterIdentifierInCodeRender.aspx");
  74. WebTest.CopyResource (GetType (), "NestedParserFileText.aspx", "NestedParserFileText.aspx");
  75. WebTest.CopyResource (GetType (), "TagWithExpressionWithinAttribute.aspx", "TagWithExpressionWithinAttribute.aspx");
  76. WebTest.CopyResource (GetType (), "EnumConverter_Bug578586.aspx", "EnumConverter_Bug578586.aspx");
  77. }
  78. [Test]
  79. [NUnit.Framework.Category ("NunitWeb")]
  80. [NUnit.Framework.Category ("NotWorking")]
  81. public void ReadOnlyPropertyBindTest ()
  82. {
  83. new WebTest ("ReadOnlyPropertyBind.aspx").Run ();
  84. }
  85. // Test for bug #449970
  86. [Test]
  87. public void MasterPageContentPlaceHolderInTemplate ()
  88. {
  89. new WebTest ("ContentPlaceHolderInTemplate.aspx").Run ();
  90. }
  91. [Test]
  92. [ExpectedException ("System.Web.Compilation.CompilationException")]
  93. public void InvalidPropertyBindTest1 ()
  94. {
  95. new WebTest ("InvalidPropertyBind1.aspx").Run ();
  96. }
  97. [Test]
  98. [ExpectedException (typeof (HttpParseException))]
  99. public void InvalidPropertyBindTest2 ()
  100. {
  101. new WebTest ("InvalidPropertyBind2.aspx").Run ();
  102. }
  103. [Test]
  104. [ExpectedException ("System.Web.Compilation.CompilationException")]
  105. public void InvalidPropertyBindTest3 ()
  106. {
  107. new WebTest ("InvalidPropertyBind3.aspx").Run ();
  108. }
  109. [Test]
  110. [ExpectedException (typeof (HttpParseException))]
  111. public void InvalidPropertyBindTest4 ()
  112. {
  113. new WebTest ("InvalidPropertyBind4.aspx").Run ();
  114. }
  115. [Test]
  116. public void ValidPropertyBindTest1 ()
  117. {
  118. new WebTest ("ValidPropertyBind1.aspx").Run ();
  119. }
  120. [Test]
  121. public void ValidPropertyBindTest2 ()
  122. {
  123. new WebTest ("ValidPropertyBind2.aspx").Run ();
  124. }
  125. [Test]
  126. public void ValidPropertyBindTest3 ()
  127. {
  128. new WebTest ("ValidPropertyBind3.aspx").Run ();
  129. }
  130. [Test]
  131. public void ValidPropertyBindTest4 ()
  132. {
  133. new WebTest ("ValidPropertyBind4.aspx").Run ();
  134. }
  135. [Test]
  136. public void ValidPropertyBindTest5 ()
  137. {
  138. new WebTest ("ValidPropertyBind5.aspx").Run ();
  139. }
  140. // bug #493639
  141. [Test]
  142. public void NoBindForMethodsWithBindInNameTest ()
  143. {
  144. string pageHtml = new WebTest ("NoBindForMethodsWithBindInName.aspx").Run ();
  145. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  146. string originalHtml = "<span id=\"grid_ctl02_lblTest\">Test</span>";
  147. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  148. }
  149. // bug #498637
  150. [Test]
  151. public void LinkInHeadWithEmbeddedExpression ()
  152. {
  153. string pageHtml = new WebTest ("LinkInHeadWithEmbeddedExpression.aspx").Run ();
  154. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  155. string originalHtml = "<link href=\"Themes/Default/Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />";
  156. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  157. }
  158. [Test]
  159. public void ExpressionInListControl ()
  160. {
  161. string pageHtml = new WebTest ("ExpressionInListControl.aspx").Run ();
  162. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  163. string originalHtml = @"<select name=""DropDown1"" id=""DropDown1"">
  164. <option value=""strvalue"">str</option>
  165. </select>";
  166. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  167. }
  168. [Test (Description="Bug #508888")]
  169. public void ServerSideControlsInScriptBlock ()
  170. {
  171. string pageHtml = new WebTest ("ServerSideControlsInScriptBlock.aspx").Run ();
  172. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  173. string originalHtml = @"<script type=""text/javascript"">alert (escape(""reporting/location?report=ViewsByDate&minDate=minDate&maxDate=maxDate""));</script>";
  174. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  175. }
  176. [Test (Description="Bug #520024")]
  177. public void PreprocessorDirectivesInMarkup ()
  178. {
  179. // Just test if it doesn't throw an exception
  180. new WebTest ("PreprocessorDirectivesInMarkup.aspx").Run ();
  181. }
  182. [Test (Description="Bug #526449")]
  183. public void NewlineInCodeExpression ()
  184. {
  185. string pageHtml = new WebTest ("NewlineInCodeExpression.aspx").Run ();
  186. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  187. string originalHtml = "<a href=\"test\">bla</a>";
  188. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  189. }
  190. [Test (Description="Bug #524358")]
  191. public void DuplicateControlsInClientComment ()
  192. {
  193. // Just test if it throws an exception
  194. string pageHtml = new WebTest ("DuplicateControlsInClientComment.aspx").Run ();
  195. Assert.IsTrue (pageHtml.IndexOf ("[System.Web.Compilation.ParseException]:") != -1, "#A1");
  196. }
  197. [Test (Description="Bug #367723")]
  198. public void ConditionalClientComments ()
  199. {
  200. string pageHtml = new WebTest ("ConditionalClientComments.aspx").Run ();
  201. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  202. string originalHtml = @"<!--[if IE 6]>
  203. <link rel=""styleheet"" type=""text/css"" href=""~/compat-ie6.css""></link>
  204. <![endif]-->";
  205. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  206. }
  207. [Test (Description="Bug #400807")]
  208. public void OneLetterIdentifierInCodeRender ()
  209. {
  210. string pageHtml = new WebTest ("OneLetterIdentifierInCodeRender.aspx").Run ();
  211. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  212. string originalHtml = @"bDoR called";
  213. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  214. }
  215. [Test (Description="Bug #562286")]
  216. public void NestedParserFileText ()
  217. {
  218. // Just test if it doesn't throw an exception
  219. new WebTest ("NestedParserFileText.aspx").Run ();
  220. }
  221. [Test (Description="Bug #568631")]
  222. public void TagWithExpressionWithinAttribute ()
  223. {
  224. // Just test if it doesn't throw an exception
  225. new WebTest ("TagWithExpressionWithinAttribute.aspx").Run ();
  226. }
  227. [Test (Description="Bug #578586")]
  228. public void EnumConverter_Bug578586 ()
  229. {
  230. WebTest t = new WebTest ("EnumConverter_Bug578586.aspx");
  231. string pageHtml = t.Run ();
  232. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  233. string originalHtml = @"<input type=""text"" value=""FlagOne"" name=""test"" id=""test"" />";
  234. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  235. }
  236. [Test (Description="Bug #323719")]
  237. public void TagsNestedInClientTag ()
  238. {
  239. string pageHtml = new WebTest ("TagsNestedInClientTag.aspx").Run ();
  240. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  241. string originalHtml = @"<script language=""javascript"" src=""/js/test.js"" type=""text/javascript""></script>
  242. <sometag language=""javascript"" src=""/js/test.js"" type=""text/javascript""></sometag>";
  243. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  244. }
  245. [Test (Description="Bug #517656")]
  246. public void ServerControlInClientSideComment ()
  247. {
  248. string pageHtml = new WebTest ("ServerControlInClientSideComment.aspx").Run ();
  249. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  250. string originalHtml = @"<!-- comment start
  251. <input id=""testBox"" type=""checkbox"" name=""testBox"" />
  252. comment end -->";
  253. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  254. }
  255. [Test]
  256. public void UnquotedAngleBrackets ()
  257. {
  258. // We just test if it doesn't throw an exception
  259. new WebTest ("UnquotedAngleBrackets.aspx").Run ();
  260. }
  261. [Test]
  262. public void FullTagsInText ()
  263. {
  264. // We just test if it doesn't throw an exception
  265. new WebTest ("FullTagsInText.aspx").Run ();
  266. }
  267. [Test]
  268. public void TagsExpressionsAndCommentsInText ()
  269. {
  270. // We just test if it doesn't throw an exception
  271. new WebTest ("TagsExpressionsAndCommentsInText.aspx").Run ();
  272. }
  273. [Test]
  274. public void ChildTemplatesTest ()
  275. {
  276. try {
  277. WebTest.Host.AppDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
  278. new WebTest ("TemplateControlParsingTest.aspx").Run ();
  279. } finally {
  280. WebTest.Host.AppDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
  281. }
  282. }
  283. [TestFixtureTearDown]
  284. public void TearDown ()
  285. {
  286. Thread.Sleep (100);
  287. WebTest.Unload ();
  288. }
  289. public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
  290. {
  291. if (e.Name != "System.Web_test")
  292. return null;
  293. return Assembly.GetExecutingAssembly ();
  294. }
  295. }
  296. }