string DownloadJavaScript(WebHost host, string url)
        {
            using (var http = new HttpTestHarness(host))
            {
                httpContext = http.Context.Object;

                http.Get(url);
                http.Response.VerifySet(r => r.ContentType = "text/javascript");
                return http.ResponseOutputStream.ReadToEnd();
            }
        }
예제 #2
0
        public HttpTestHarness(WebHost host)
        {
            this.host = host;
            Context = new Mock<HttpContextBase>();
            Request = new Mock<HttpRequestBase>();
            Response = new Mock<HttpResponseBase>();
            RequestHeaders = new NameValueCollection();
            ResponseOutputStream = new MemoryStream();
            ResponseCache = new Mock<HttpCachePolicyBase>();

            Context.SetupGet(c => c.Request).Returns(Request.Object);
            Context.SetupGet(c => c.Response).Returns(Response.Object);
            Context.SetupGet(c => c.Items).Returns(new Dictionary<string, object>());

            Request.SetupGet(r => r.PathInfo).Returns("");
            Request.SetupGet(r => r.Headers).Returns(RequestHeaders);

            Response.Setup(r => r.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(r => r);
            Response.SetupGet(r => r.OutputStream).Returns(ResponseOutputStream);
            Response.SetupGet(r => r.Cache).Returns(ResponseCache.Object);
            Response.SetupProperty(r => r.ContentType);
        }
예제 #3
0
        string[] GetPageHtmlResourceUrls(WebHost host, params string[] references)
        {
            using (var http = new HttpTestHarness(host))
            {
                httpContext = http.Context.Object;

                foreach (var reference in references)
                {
                    Bundles.Reference(reference);
                }

                var htmlString =
                    "<html>" +
                    Bundles.RenderScripts().ToHtmlString() +
                    Bundles.RenderStylesheets().ToHtmlString() +
                    Bundles.RenderHtmlTemplates().ToHtmlString() +
                    "</html>";

                var html = XElement.Parse(htmlString);
                var scripts = html.Elements("script").Where((s => s.Attribute("src") != null)).Select(s => s.Attribute("src").Value);
                var links = html.Elements("link").Select(s => s.Attribute("href").Value);
                return links.Concat(scripts).ToArray();
            }
        }
예제 #4
0
        string Download(WebHost host, string url)
        {
            using (var http = new HttpTestHarness(host))
            {
                httpContext = http.Context.Object;

                http.Get(url);
                return http.ResponseOutputStream.ReadToEnd();
            }
        }
예제 #5
0
 void InitWithoutTraceLogging()
 {
     _host = new WebHost();
     _host.Initialize();
 }