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."); }
public void WhenGetReferencedBundlesByLocation_ThenReturnReferenceBuilderReferencedBundlesWithLocation() { var bundles = new Bundle[0]; referenceBuilder .Setup(b => b.GetBundles("body")) .Returns(bundles); Bundles.GetReferencedBundles("body").ShouldBeSameAs(bundles); }
public void WhenGetReferencedBundles_ThenReturnReferenceBuilderReferencedBundles() { var bundles = new Bundle[0]; referenceBuilder .Setup(b => b.GetBundles(null)) .Returns(bundles); Bundles.GetReferencedBundles().ShouldBeSameAs(bundles); }
public void RenderHtmlTemplatesWithLocationCallsReferenceBuilderRenderWithHtmlTemplateBundleTypeAndLocation() { var expectedHtml = "html"; referenceBuilder.Setup(b => b.Render <HtmlTemplateBundle>("body")).Returns(expectedHtml); var html = Bundles.RenderHtmlTemplates("body").ToHtmlString(); html.ShouldEqual(expectedHtml); }
public void RenderHtmlTemplatesCallsReferenceBuilderRenderWithHtmlTemplateBundleType() { var expectedHtml = "html"; referenceBuilder.Setup(b => b.Render <HtmlTemplateBundle>(null)).Returns(expectedHtml); var html = Bundles.RenderHtmlTemplates().ToHtmlString(); html.ShouldEqual(expectedHtml); }
public void RenderStylesheetsWithLocationCallsReferenceBuilderRenderWithStylesheetBundleTypeAndLocation() { var expectedHtml = "html"; referenceBuilder.Setup(b => b.Render <StylesheetBundle>("head")).Returns(expectedHtml); var html = Bundles.RenderStylesheets("head").ToHtmlString(); html.ShouldEqual(expectedHtml); }
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) )); }
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"); }
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); }
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(); }
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"); }
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" }); }
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"); }
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" }); }
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"); }
public void AddPageDataWithObjectAddsReference() { Bundles.AddPageData("content", new { test = "test" }); referenceBuilder.Verify(b => b.Reference(It.Is <Bundle>(bundle => bundle is PageDataScriptBundle), null)); }
public void AddPageDataWithDictionaryAddsReference() { Bundles.AddPageData("content", new Dictionary <string, object>()); referenceBuilder.Verify(b => b.Reference(It.Is <Bundle>(bundle => bundle is PageDataScriptBundle), null)); }
// 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); }
public void AddPageData(string globalVariable, object data, string pageLocation = null) { Bundles.AddPageData(globalVariable, data, pageLocation); }
public void AddInline(string scriptContent, string pageLocation = null) { Bundles.AddInlineScript(scriptContent, pageLocation); }
public string ModuleUrl(string path) { return(Bundles.Url(path)); }
public void Reference(string path, string pageLocation = null) { Bundles.Reference(path, pageLocation); }
public void WhenReference_ThenReferenceBuilderReferenceIsCalled() { Bundles.Reference("~/test"); referenceBuilder.Verify(b => b.Reference("~/test", null)); }
public void RebuildCacheCallsBundleCacheRebuilder() { Bundles.RebuildCache(); bundleCacheRebuilder.Verify(r => r.RebuildCache()); }
public void WhenReferenceWithLocation_ThenReferenceBuilderReferenceIsCalledWithLocation() { Bundles.Reference("~/test", "body"); referenceBuilder.Verify(b => b.Reference("~/test", "body")); }
public void AddPageDataWithDataObjectAddsReferenceToPageDataScriptBundle() { Bundles.AddPageData("content", new { data = 1 }, "location"); referenceBuilder.Verify(b => b.Reference(It.Is <Bundle>(bundle => bundle is PageDataScriptBundle), "location")); }