Beispiel #1
0
        public void GivenDebugMode_BundleAUrlShouldServeConcatenatedScripts()
        {
            using (var host = new TestableWebHost("assets", () => httpContext, isAspNetDebuggingEnabled: true))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                    bundles.AddPerSubDirectory<ScriptBundle>("scripts")
                ));
                host.Initialize();

                string bundleUrl;
                using (var http = new HttpTestHarness(host))
                {
                    httpContext = http.Context.Object;
                    Bundles.Reference("scripts/bundle-a");
                    bundleUrl = Bundles.Url("scripts/bundle-a");
                }

                var separator = System.Environment.NewLine + ";" + System.Environment.NewLine;

                var expectedContent = File.ReadAllText("assets\\scripts\\bundle-a\\asset-2.js") + separator +
                                      File.ReadAllText("assets\\scripts\\bundle-a\\asset-1.js");

                Download(host, bundleUrl).ShouldEqual(expectedContent);
            }
        }
        public void PageThatReferencesStylesBundleAGetsStylesBundleA()
        {
            using (var host = new TestableWebHost("assets", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                                                                    bundles.AddPerSubDirectory <StylesheetBundle>("styles")
                                                                    ));
                host.Initialize();

                var urls = GetPageHtmlResourceUrls(host, "styles/bundle-a");

                Download(host, urls[0]).ShouldEqual("a{color:red}p{border:1px solid red}body{color:#abc}");
            }
        }
        public void HtmlTemplatesServedAsJavaScript()
        {
            using (var host = new TestableWebHost(".", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(
                                                bundles => bundles.Add <HtmlTemplateBundle>("~/templates", b => b.AsJavaScript())
                                                ));

                host.Initialize();

                var javaScript = DownloadJavaScript(host, "/cassette.axd/htmltemplate/hash/templates");
                javaScript.ShouldEqual(@"(function(n){var t=function(t,i){var r=n.createElement(""script""),u;r.type=""text/html"",r.id=t,typeof r.textContent!=""undefined""?r.textContent=i:r.innerText=i,u=n.getElementsByTagName(""script"")[0],u.parentNode.insertBefore(r,u)};t(""asset-1"",""<p>asset 1<\/p>""),t(""asset-2"",""<p>asset 2<\/p>"")})(document)");
            }
        }
        public void HtmlTemplatesServedAsJavaScript()
        {
            using (var host = new TestableWebHost(".", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(
                    bundles => bundles.Add<HtmlTemplateBundle>("~/templates", b => b.AsJavaScript())
                ));

                host.Initialize();

                var javaScript = DownloadJavaScript(host, "/cassette.axd/htmltemplate/hash/templates");
                javaScript.ShouldEqual(@"(function(n){var t=function(t,i){var r=n.createElement(""script""),u;r.type=""text/html"",r.id=t,typeof r.textContent!=""undefined""?r.textContent=i:r.innerText=i,u=n.getElementsByTagName(""script"")[0],u.parentNode.insertBefore(r,u)};t(""asset-1"",""<p>asset 1<\/p>""),t(""asset-2"",""<p>asset 2<\/p>"")})(document)");
            }
        }
        public void PageThatReferencesScriptsBundleCGetsScriptsBundleBAndScriptsBundleC()
        {
            using (var host = new TestableWebHost("assets", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                    bundles.AddPerSubDirectory<ScriptBundle>("scripts")
                ));
                host.Initialize();

                var scriptUrls = GetPageHtmlResourceUrls(host, "scripts/bundle-c");

                scriptUrls[0].ShouldMatch(new Regex(@"^/cassette\.axd/script/[^/]+/scripts/bundle-c"));
                Download(host, scriptUrls[0]).ShouldEqual(@"(function(){var n;n=1}).call(this)");
            }
        }
        public void PageThatReferencesScriptsBundleCGetsScriptsBundleBAndScriptsBundleC()
        {
            using (var host = new TestableWebHost("assets", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                                                                    bundles.AddPerSubDirectory <ScriptBundle>("scripts")
                                                                    ));
                host.Initialize();

                var scriptUrls = GetPageHtmlResourceUrls(host, "scripts/bundle-c");

                scriptUrls[0].ShouldMatch(new Regex(@"^/cassette\.axd/script/[^/]+/scripts/bundle-c"));
                Download(host, scriptUrls[0]).ShouldEqual(@"(function(){var n;n=1}).call(this)");
            }
        }
        public void PageThatReferencesStylesAndTemplatesDoNotGetDuplicateResources()
        {
            using (var host = new TestableWebHost("assets", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                {
                    bundles.AddPerSubDirectory <ScriptBundle>("scripts");
                    bundles.AddPerIndividualFile <HtmlTemplateBundle>("templates");
                }));
                host.Initialize();

                var scriptUrls = GetPageHtmlResourceUrls(host, "scripts/bundle-a", "templates/asset-1.htm");
                Assert.Equal(scriptUrls.Distinct(), scriptUrls);
            }
        }
Beispiel #8
0
        public void PageThatReferencesStylesAndTemplatesDoNotGetDuplicateResources()
        {
            using (var host = new TestableWebHost("assets", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                {
                    bundles.AddPerSubDirectory<ScriptBundle>("scripts");
                    bundles.AddPerIndividualFile<HtmlTemplateBundle>("templates");
                }));
                host.Initialize();

                var scriptUrls = GetPageHtmlResourceUrls(host, "scripts/bundle-a", "templates/asset-1.htm");
                Assert.Equal(scriptUrls.Distinct(), scriptUrls);
            }
        }
Beispiel #9
0
        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 });
                }
            }
        }
Beispiel #10
0
        public void GivenDebugMode_PageThatReferencesScriptsBundleAGetsAssetsForScriptsBundleBAndScriptsBundleA()
        {
            using (var host = new TestableWebHost("assets", () => httpContext, isAspNetDebuggingEnabled: true))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                    bundles.AddPerSubDirectory<ScriptBundle>("scripts")
                ));
                host.Initialize();

                var scriptUrls = GetPageHtmlResourceUrls(host, "scripts/bundle-a");

                scriptUrls[0].ShouldStartWith("/cassette.axd/asset/scripts/bundle-b/asset-3.js?");
                Download(host, scriptUrls[0]).ShouldEqual(File.ReadAllText("assets\\scripts\\bundle-b\\asset-3.js"));

                scriptUrls[1].ShouldStartWith("/cassette.axd/asset/scripts/bundle-a/asset-2.js?");
                Download(host, scriptUrls[1]).ShouldEqual(File.ReadAllText("assets\\scripts\\bundle-a\\asset-2.js"));

                scriptUrls[2].ShouldStartWith("/cassette.axd/asset/scripts/bundle-a/asset-1.js?");
                Download(host, scriptUrls[2]).ShouldEqual(File.ReadAllText("assets\\scripts\\bundle-a\\asset-1.js"));
            }
        }
Beispiel #11
0
        public void GivenDebugMode_PageThatReferencesScriptsBundleAGetsAssetsForScriptsBundleBAndScriptsBundleA()
        {
            using (var host = new TestableWebHost("assets", () => httpContext, isAspNetDebuggingEnabled: true))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                                                                    bundles.AddPerSubDirectory <ScriptBundle>("scripts")
                                                                    ));
                host.Initialize();

                var scriptUrls = GetPageHtmlResourceUrls(host, "scripts/bundle-a");

                scriptUrls[0].ShouldStartWith("/cassette.axd/asset/scripts/bundle-b/asset-3.js?");
                Download(host, scriptUrls[0]).ShouldEqual(File.ReadAllText("assets\\scripts\\bundle-b\\asset-3.js"));

                scriptUrls[1].ShouldStartWith("/cassette.axd/asset/scripts/bundle-a/asset-2.js?");
                Download(host, scriptUrls[1]).ShouldEqual(File.ReadAllText("assets\\scripts\\bundle-a\\asset-2.js"));

                scriptUrls[2].ShouldStartWith("/cassette.axd/asset/scripts/bundle-a/asset-1.js?");
                Download(host, scriptUrls[2]).ShouldEqual(File.ReadAllText("assets\\scripts\\bundle-a\\asset-1.js"));
            }
        }
Beispiel #12
0
        public void PageThatReferencesStylesBundleAGetsStylesBundleA()
        {
            using (var host = new TestableWebHost("assets", () => httpContext))
            {
                host.AddBundleConfiguration(new BundleConfiguration(bundles =>
                    bundles.AddPerSubDirectory<StylesheetBundle>("styles")
                ));
                host.Initialize();

                var urls = GetPageHtmlResourceUrls(host, "styles/bundle-a");

                Download(host, urls[0]).ShouldEqual("a{color:red}p{border:1px solid red}body{color:#abc}");
            }
        }
Beispiel #13
0
 public TestableWebHostSettingsConfiguration(TestableWebHost host) 
     : base(host.AppDomainAppVirtualPath)
 {
     this.host = host;
 }
Beispiel #14
0
 public TestableWebHostSettingsConfiguration(TestableWebHost host)
     : base(host.AppDomainAppVirtualPath)
 {
     this.host = host;
 }