public void BundleConfigReadsBundleConfigWithOnlyScriptBundles() { // Arrange var xml = ToStream( @"<?xml version=""1.0"" ?> <bundles version=""1.0""> <scriptBundle path=""~/my-bundle-path"" cdnPath=""http://cdn.com/bundle.js"" cdnFallbackExpression=""!window.jquery""> <include path=""~/Scripts/jQuery.js""></include> </scriptBundle> <scriptBundle path=""~/Scripts/js""> <include path=""~/scripts/first.js""></include> <include path=""~/scripts/second.js""></include> </scriptBundle> </bundles>"); // Act var result = BundleManifest.ReadBundleManifest(xml); // Assert Assert.AreEqual(0, result.StyleBundles.Count); Assert.AreEqual(2, result.ScriptBundles.Count); Assert.AreEqual("~/my-bundle-path", result.ScriptBundles[0].Path); Assert.AreEqual("http://cdn.com/bundle.js", result.ScriptBundles[0].CdnPath); Assert.AreEqual("!window.jquery", result.ScriptBundles[0].CdnFallbackExpression); Assert.AreEqual(1, result.ScriptBundles[0].Includes.Count); Assert.AreEqual("~/Scripts/jQuery.js", result.ScriptBundles[0].Includes[0]); Assert.AreEqual("~/Scripts/js", result.ScriptBundles[1].Path); Assert.AreEqual(2, result.ScriptBundles[1].Includes.Count); Assert.AreEqual("~/scripts/first.js", result.ScriptBundles[1].Includes[0]); Assert.AreEqual("~/scripts/second.js", result.ScriptBundles[1].Includes[1]); }
public void BundleConfigReadsBundleConfigWithOnlyStyleBundles() { // Arrange var xml = ToStream( @"<?xml version=""1.0"" ?> <bundles version=""1.0""> <styleBundle path=""~/my-bundle-path"" cdnPath=""http://cdn.com/bundle.css""> <include path=""~/Content/jQuery.ui.css""></include> </styleBundle> <styleBundle path=""~/content/css""> <include path=""~/scripts/master.css""></include> <include path=""~/scripts/page.css""></include> </styleBundle> </bundles>"); // Act var result = BundleManifest.ReadBundleManifest(xml); // Assert Assert.AreEqual(0, result.ScriptBundles.Count); Assert.AreEqual(2, result.StyleBundles.Count); Assert.AreEqual("~/my-bundle-path", result.StyleBundles[0].Path); Assert.AreEqual("http://cdn.com/bundle.css", result.StyleBundles[0].CdnPath); Assert.AreEqual(1, result.StyleBundles[0].Includes.Count); Assert.AreEqual("~/Content/jQuery.ui.css", result.StyleBundles[0].Includes[0]); Assert.AreEqual("~/content/css", result.StyleBundles[1].Path); Assert.AreEqual(2, result.StyleBundles[1].Includes.Count); Assert.AreEqual("~/scripts/master.css", result.StyleBundles[1].Includes[0]); Assert.AreEqual("~/scripts/page.css", result.StyleBundles[1].Includes[1]); }
private string GetDesignTimeHtml() { string bundlePath = MapPath(Site, BundleManifest.BundleManifestPath); if (String.IsNullOrEmpty(bundlePath)) { return(null); } BundleManifest bundleManfiest; using (var stream = File.OpenRead(bundlePath)) { bundleManfiest = BundleManifest.ReadBundleManifest(stream); } var bundle = bundleManfiest.StyleBundles.FirstOrDefault(b => b.Path.Equals(Path, StringComparison.OrdinalIgnoreCase)); if (bundle != null) { var builder = new StringBuilder(); foreach (var item in bundle.Includes.Select(ResolveClientUrl)) { builder.AppendFormat(@"<link href=""{0}"" rel=""stylesheet""/>", item); } return(builder.ToString()); } return(null); }
public void BundleConfigReadsBundleDataCorrectly() { // Arrange var xml = ToStream(@"<?xml version=""1.0"" ?><bundles version=""1.0""><styleBundle path=""~/my-bundle-path""><include path=""~/Content/jQuery.css""></include><include path=""~/Content/jQuery.ui.css""></include></styleBundle></bundles>"); // Act var result = BundleManifest.ReadBundleManifest(xml); // Assert Assert.AreEqual(1, result.StyleBundles.Count); Assert.AreEqual("~/my-bundle-path", result.StyleBundles[0].Path); Assert.AreEqual(2, result.StyleBundles[0].Includes.Count); Assert.AreEqual("~/Content/jQuery.css", result.StyleBundles[0].Includes[0]); Assert.AreEqual("~/Content/jQuery.ui.css", result.StyleBundles[0].Includes[1]); }
public void BundleConfigAllowsSelfClosingIncludeTags() { BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles><styleBundle path=""~/my-bundle-path""><include path=""~/Content/jQuery.css""/><include path=""~/Content/jQuery.ui.css""/></styleBundle></bundles>")); }
public void BundleConfigDoesNotThrowIfVersionNotSpecified() { BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles></bundles>")); }
public void BundleConfigThrowsWithScriptBundleWithNoPath() { ExceptionHelper.ExpectException <InvalidOperationException>(() => BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles><styleBundle><include path=""jQuery.css""/></styleBundle></bundles>"))); }
public void BundleConfigThrowsWithIncludeWithNoPath() { ExceptionHelper.ExpectException <InvalidOperationException>(() => BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles><styleBundle path=""~/my-bundle-path""><include /></styleBundle></bundles>"))); }
public void BundleConfigThrowsWithPascalCasing() { ExceptionHelper.ExpectException <InvalidOperationException>(() => BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles><StyleBundle path=""~/bundle/css""><include path=""jQuery.css""></include></StyleBundle></bundles>"))); }
public void BundleConfigThrowsWithUnknownAttribute() { ExceptionHelper.ExpectException <InvalidOperationException>(() => BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles version=""1.0"" unknown=""oops""></bundles>"))); }
public void BundleConfigThrowsIfBundlesHasUnknownElement() { ExceptionHelper.ExpectException <InvalidOperationException>(() => BundleManifest.ReadBundleManifest(ToStream(@"<?xml version=""1.0"" ?><bundles version=""1.0""><Blah /></bundles>"))); }