string Download(WebHost host, string url) { using (var http = new HttpTestHarness(host)) { httpContext = http.Context.Object; http.Get(url); return(http.ResponseOutputStream.ReadToEnd()); } }
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()); } }
public void ReferencingInlineScriptBundlesMustWork() { HttpContextBase httpContext = null; using (var host = new TestableWebHost("assets", () => httpContext)) { using (var http = new HttpTestHarness(host)) { httpContext = http.Context.Object; host.Initialize(); Bundles.AddPageData("x", new { data = 1 }); } } }
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()); } }