public void WhenPathIsPrefixedWithTilde_ThenCallsUrlGeneratorCreateRawFileUrlWithPath()
        {
            urlGenerator.Setup(g => g.CreateRawFileUrl("~/test.png")).Returns("URL");

            var url = Bundles.FileUrl("~/test.png");

            url.ShouldEqual("URL");
        }
        public void WhenPathIsRelative_ThenCallsUrlGeneratorCreateRawFileUrlWithPrefixedPath()
        {
            urlGenerator.Setup(g => g.CreateRawFileUrl("~/test.png", hashOfFileContent)).Returns("URL");

            var url = Bundles.FileUrl("test.png");

            url.ShouldEqual("URL");
        }
        public void WhenFilePathStartsWithSlash_ThenPrefixPathWithTilde()
        {
            urlGenerator.Setup(g => g.CreateRawFileUrl("~/test.png", hashOfFileContent)).Returns("URL");

            var url = Bundles.FileUrl("/test.png");

            url.ShouldEqual("URL");
        }
        public void WhenSettingsDoNotAllowRawFileRequest_ThenThrowException()
        {
            fileSystem.Add("~/web.config");
            fileAccessAuthorization.Setup(a => a.CanAccess("~/web.config")).Returns(false);
            var exception = Assert.Throws <Exception>(() => Bundles.FileUrl("~/web.config"));

            exception.Message.ShouldStartWith("The file ~/web.config cannot be requested.");
        }
Exemple #5
0
        public void WhenGetReferencedBundlesByLocation_ThenReturnReferenceBuilderReferencedBundlesWithLocation()
        {
            var bundles = new Bundle[0];

            referenceBuilder
            .Setup(b => b.GetBundles("body"))
            .Returns(bundles);

            Bundles.GetReferencedBundles("body").ShouldBeSameAs(bundles);
        }
Exemple #6
0
        public void WhenGetReferencedBundles_ThenReturnReferenceBuilderReferencedBundles()
        {
            var bundles = new Bundle[0];

            referenceBuilder
            .Setup(b => b.GetBundles(null))
            .Returns(bundles);

            Bundles.GetReferencedBundles().ShouldBeSameAs(bundles);
        }
Exemple #7
0
        public void RenderHtmlTemplatesWithLocationCallsReferenceBuilderRenderWithHtmlTemplateBundleTypeAndLocation()
        {
            var expectedHtml = "html";

            referenceBuilder.Setup(b => b.Render <HtmlTemplateBundle>("body")).Returns(expectedHtml);

            var html = Bundles.RenderHtmlTemplates("body").ToHtmlString();

            html.ShouldEqual(expectedHtml);
        }
Exemple #8
0
        public void RenderHtmlTemplatesCallsReferenceBuilderRenderWithHtmlTemplateBundleType()
        {
            var expectedHtml = "html";

            referenceBuilder.Setup(b => b.Render <HtmlTemplateBundle>(null)).Returns(expectedHtml);

            var html = Bundles.RenderHtmlTemplates().ToHtmlString();

            html.ShouldEqual(expectedHtml);
        }
Exemple #9
0
        public void RenderStylesheetsWithLocationCallsReferenceBuilderRenderWithStylesheetBundleTypeAndLocation()
        {
            var expectedHtml = "html";

            referenceBuilder.Setup(b => b.Render <StylesheetBundle>("head")).Returns(expectedHtml);

            var html = Bundles.RenderStylesheets("head").ToHtmlString();

            html.ShouldEqual(expectedHtml);
        }
Exemple #10
0
        public static IHtmlString RenderScripts(params string[] initialModulePaths)
        {
            // Reference the require.js configuration script asset.
            // This was inserted into the main bundle, which includes require.js itself.
            Bundles.Reference("~/Cassette.RequireJs");

            return(new HtmlString(
                       Bundles.RenderScripts().ToHtmlString() +
                       CreateRequireCallJavaScript(initialModulePaths)
                       ));
        }
Exemple #11
0
        public void AddInlineScriptWithLambdaAddsReferenceToInlineScriptBundle()
        {
            Bundle bundle = null;

            referenceBuilder.Setup(b => b.Reference(It.IsAny <Bundle>(), "location"))
            .Callback <Bundle, string>((b, s) => bundle = b);

            Bundles.AddInlineScript(_ => "content", "location");

            bundle.ShouldBeType <InlineScriptBundle>();
            bundle.Render().ShouldContain("content");
        }
Exemple #12
0
        public void AddInlineScriptWithCustomizeAction_ThenCustomizeActionCalledWithTheBundle()
        {
            Bundle bundle                = null;
            Bundle customizedBundle      = null;
            Action <ScriptBundle> action = b => customizedBundle = b;

            referenceBuilder.Setup(b => b.Reference(It.IsAny <Bundle>(), "location"))
            .Callback <Bundle, string>((b, s) => bundle = b);

            Bundles.AddInlineScript("content", "location", action);

            customizedBundle.ShouldNotBeNull().ShouldBeSameAs(bundle);
        }
Exemple #13
0
        public void AddInlineWithLambdaAndNoLocationCreatesBundleWithPageLocationNull()
        {
            Bundle bundle = null;

            referenceBuilder.Setup(b => b.Reference(It.IsAny <Bundle>(), null))
            .Callback <Bundle, string>((b, s) => bundle = b);

            Bundles.AddInlineScript(_ => "content");

            bundle.ShouldBeType <InlineScriptBundle>();
            bundle.Render().ShouldContain("content");
            bundle.PageLocation.ShouldBeNull();
        }
Exemple #14
0
        public void TypedUrlUsesGetBundleUrlDelegate()
        {
            var bundle = new TestableBundle("~/test");

            bundles.Add(bundle);
            urlGenerator
            .Setup(g => g.CreateBundleUrl(bundle))
            .Returns("URL");

            var url = Bundles.Url <TestableBundle>("~/test");

            url.ShouldEqual("URL");
        }
Exemple #15
0
        public void GivenNotDebugModeAndReferencedBundle_WhenGetReferencedBundleUrlsWithLocation_ThenReturnUrlInArray()
        {
            settings.IsDebuggingEnabled = false;
            referenceBuilder
            .Setup(b => b.GetBundles("body"))
            .Returns(new[] { new TestableBundle("~") });
            urlGenerator
            .Setup(g => g.CreateBundleUrl(It.IsAny <Bundle>()))
            .Returns("/url");

            var urls = Bundles.GetReferencedBundleUrls <TestableBundle>("body");

            urls.ShouldEqual(new[] { "/url" });
        }
Exemple #16
0
        public void TypedUrlUsesGetBundleUrlDelegate()
        {
            var bundle = new TestableBundle("~/test");

            bundleContainer
            .Setup(c => c.FindBundlesContainingPath("~/test"))
            .Returns(new[] { bundle });
            urlGenerator
            .Setup(g => g.CreateBundleUrl(bundle))
            .Returns("URL");

            var url = Bundles.Url <TestableBundle>("~/test");

            url.ShouldEqual("URL");
        }
Exemple #17
0
        public void GivenDebugModeAndReferencedBundleWithAssets_WhenGetReferencedBundleUrls_ThenReturnEachAssetUrlInArray()
        {
            settings.IsDebuggingEnabled = true;
            var bundle = new TestableBundle("~");

            bundle.Assets.Add(new StubAsset());
            bundle.Assets.Add(new StubAsset());

            referenceBuilder
            .Setup(b => b.GetBundles(null))
            .Returns(new[] { bundle });
            var urls = new Queue <string>(new[] { "/asset1", "/asset2" });

            urlGenerator
            .Setup(g => g.CreateAssetUrl(It.IsAny <IAsset>()))
            .Returns(urls.Dequeue);

            var returnedUrls = Bundles.GetReferencedBundleUrls <TestableBundle>();

            returnedUrls.ShouldEqual(new[] { "/asset1", "/asset2" });
        }
Exemple #18
0
 public void WhenReferenceUrlSpecifyingTheBundleType_ThenReferenceBuilderIsCalledWithTypeParameter()
 {
     Bundles.Reference <ScriptBundle>("http://example.com/");
     referenceBuilder.Verify(b => b.Reference <ScriptBundle>("http://example.com/", null));
 }
        public void WhenFileNotFound_ThenThrowFileNotFoundException()
        {
            var exception = Assert.Throws <FileNotFoundException>(() => Bundles.FileUrl("not-found.png"));

            exception.FileName.ShouldEqual("~/not-found.png");
        }
Exemple #20
0
 public void AddPageDataWithObjectAddsReference()
 {
     Bundles.AddPageData("content", new { test = "test" });
     referenceBuilder.Verify(b => b.Reference(It.Is <Bundle>(bundle => bundle is PageDataScriptBundle), null));
 }
Exemple #21
0
 public void AddPageDataWithDictionaryAddsReference()
 {
     Bundles.AddPageData("content", new Dictionary <string, object>());
     referenceBuilder.Verify(b => b.Reference(It.Is <Bundle>(bundle => bundle is PageDataScriptBundle), null));
 }
Exemple #22
0
// ReSharper disable ParameterTypeCanBeEnumerable.Global
        public void AddPageData(string globalVariable, IDictionary <string, object> data, string pageLocation = null)
// ReSharper restore ParameterTypeCanBeEnumerable.Global
        {
            Bundles.AddPageData(globalVariable, data, pageLocation);
        }
Exemple #23
0
 public void AddPageData(string globalVariable, object data, string pageLocation = null)
 {
     Bundles.AddPageData(globalVariable, data, pageLocation);
 }
Exemple #24
0
 public void AddInline(string scriptContent, string pageLocation = null)
 {
     Bundles.AddInlineScript(scriptContent, pageLocation);
 }
Exemple #25
0
 public string ModuleUrl(string path)
 {
     return(Bundles.Url(path));
 }
Exemple #26
0
 public void Reference(string path, string pageLocation = null)
 {
     Bundles.Reference(path, pageLocation);
 }
Exemple #27
0
 public void WhenReference_ThenReferenceBuilderReferenceIsCalled()
 {
     Bundles.Reference("~/test");
     referenceBuilder.Verify(b => b.Reference("~/test", null));
 }
Exemple #28
0
 public void RebuildCacheCallsBundleCacheRebuilder()
 {
     Bundles.RebuildCache();
     bundleCacheRebuilder.Verify(r => r.RebuildCache());
 }
Exemple #29
0
 public void WhenReferenceWithLocation_ThenReferenceBuilderReferenceIsCalledWithLocation()
 {
     Bundles.Reference("~/test", "body");
     referenceBuilder.Verify(b => b.Reference("~/test", "body"));
 }
Exemple #30
0
 public void AddPageDataWithDataObjectAddsReferenceToPageDataScriptBundle()
 {
     Bundles.AddPageData("content", new { data = 1 }, "location");
     referenceBuilder.Verify(b => b.Reference(It.Is <Bundle>(bundle => bundle is PageDataScriptBundle), "location"));
 }