public void HtmlEncodeTest()
        {
            AppDomainUtils.RunInSeparateAppDomain(
                () =>
            {
                // Set HideRequestResponse to true to simulate the condition in IIS 7/7.5
                var context = new HttpContext(
                    new HttpRequest("default.cshtml", "http://localhost/default.cshtml", null),
                    new HttpResponse(new StringWriter(new StringBuilder()))
                    );
                var hideRequestResponse = typeof(HttpContext).GetField(
                    "HideRequestResponse",
                    BindingFlags.NonPublic | BindingFlags.Instance
                    );
                hideRequestResponse.SetValue(context, true);

                HttpContext.Current = context;
                var page            = new ApplicationStartPageTest().CreateStartPage(
                    p =>
                {
                    p.Write("test");
                }
                    );
                page.ExecuteStartPage();
            }
                );
        }
 public void StartPageBasicTest() {
     AppDomainUtils.RunInSeparateAppDomain(() => {
         var page = new ApplicationStartPageTest().CreateStartPage(p => {
             p.AppState["x"] = "y";
             p.WriteLiteral("test");
         });
         page.ExecuteInternal();
         Assert.AreEqual("y", page.ApplicationState["x"]);
         Assert.AreEqual("test", ApplicationStartPage.Markup.ToHtmlString());
     });
 }
Ejemplo n.º 3
0
 public void ExceptionTest()
 {
     AppDomainUtils.RunInSeparateAppDomain(() =>
     {
         var msg  = "This is an error message";
         var e    = new InvalidOperationException(msg);
         var page = new ApplicationStartPageTest().CreateStartPage(p => { throw e; });
         var ex   = Assert.Throws <HttpException>(() => page.ExecuteStartPage());
         Assert.Equal(msg, ex.InnerException.Message);
         Assert.Equal(e, ApplicationStartPage.Exception);
     });
 }
 public void ExceptionTest()
 {
     AppDomainUtils.RunInSeparateAppDomain(() =>
     {
         var msg = "This is an error message";
         var e = new InvalidOperationException(msg);
         var page = new ApplicationStartPageTest().CreateStartPage(p => { throw e; });
         var ex = Assert.Throws<HttpException>(() => page.ExecuteStartPage());
         Assert.Equal(msg, ex.InnerException.Message);
         Assert.Equal(e, ApplicationStartPage.Exception);
     });
 }
Ejemplo n.º 5
0
 public void StartPageBasicTest()
 {
     AppDomainUtils.RunInSeparateAppDomain(() => {
         var page = new ApplicationStartPageTest().CreateStartPage(p => {
             p.AppState["x"] = "y";
             p.WriteLiteral("test");
         });
         page.ExecuteInternal();
         Assert.AreEqual("y", page.ApplicationState["x"]);
         Assert.AreEqual("test", ApplicationStartPage.Markup.ToHtmlString());
     });
 }
        public void HtmlEncodeTest()
        {
            AppDomainUtils.RunInSeparateAppDomain(() =>
            {
                // Set HideRequestResponse to true to simulate the condition in IIS 7/7.5
                var context = new HttpContext(new HttpRequest("default.cshtml", "http://localhost/default.cshtml", null), new HttpResponse(new StringWriter(new StringBuilder())));
                var hideRequestResponse = typeof(HttpContext).GetField("HideRequestResponse", BindingFlags.NonPublic | BindingFlags.Instance);
                hideRequestResponse.SetValue(context, true);

                HttpContext.Current = context;
                var page = new ApplicationStartPageTest().CreateStartPage(p => { p.Write("test"); });
                page.ExecuteStartPage();
            });
        }