Пример #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);
            }
        }
Пример #2
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}");
            }
        }
        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)");
            }
        }
Пример #5
0
        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)");
            }
        }
Пример #6
0
        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)");
            }
        }
Пример #7
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);
            }
        }
Пример #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);
            }
        }
Пример #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 });
                }
            }
        }
Пример #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"));
            }
        }
Пример #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"));
            }
        }
Пример #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}");
            }
        }