/// <summary> /// This returns the appropriate html string to include in the web page such that the requested bundle will be loaded. /// </summary> /// <param name="bundleName"></param> /// <param name="cssOrJs"></param> /// <param name="inDevelopment">This controls whether we supply individual files or development mode /// or single minified files/CDNs in non-development mode</param> /// <param name="getContentUrl">method to get url of content</param> /// <returns></returns> public string CalculateHtmlIncludes(string bundleName, CssOrJs cssOrJs, bool inDevelopment, Func<string, string> getContentUrl) { var settingFilePath = Path.Combine(_jsonDataDir, config.BundlesFileName); var reader = new ReadBundleFile(settingFilePath); var fileTypeInfo = config.GetFileTypeData(cssOrJs); if (inDevelopment) { var sb = new StringBuilder(); //we send the individual files as found in the bundle json file foreach (var relFilePath in _searcher.UnpackBundle(reader.GetBundleDebugFiles(bundleName))) { sb.AppendLine(fileTypeInfo.DebugHtmlFormatString .Replace(FileTypeConfigInfo.FileUrlParam, getContentUrl(relFilePath))); } return sb.ToString(); } //We are in nonDebug, i.e. production mode var cdnLinks = reader.GetBundleCdnInfo(bundleName); return cdnLinks.Any() ? FormCdnIncludes(cdnLinks, bundleName, cssOrJs, fileTypeInfo, getContentUrl) : FormSingleMinifiedFileInclude(bundleName, cssOrJs, fileTypeInfo, getContentUrl); }
public void TestGetBundleDebugFilesCndFileBundleListOk(string bundleName, params string[] expectedfiles) { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json")); //ATTEMPT var files = reader.GetBundleDebugFiles(bundleName, ""); //VERIFY CollectionAssert.AreEqual(expectedfiles, files); }
public void TestGetBundleDebugFilesBadCndFileBundleSingleOk() { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles03*.json")); //ATTEMPT var ex = Assert.Throws <InvalidOperationException>(() => reader.GetBundleDebugFiles("missingDevelopmentJs")); //VERIFY ex.Message.ShouldEqual("The CDN bundle missingDevelopmentJs, array element 0, is missing a property called 'development'."); }
public void TestGetBundleDebugFilesNonCndFileBundleSingleOk(string bundleName, string expectedfile) { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json")); //ATTEMPT var files = reader.GetBundleDebugFiles(bundleName, "").ToList(); //VERIFY files.Count().ShouldEqual(1); files[0].ShouldEqual(expectedfile); }
/// <summary> /// Thic checks a specific bundle by name /// </summary> /// <param name="bundleName"></param> /// <returns>empty list if no error, otherwise a list of errors</returns> public ReadOnlyCollection <string> CheckSingleBundleIsValid(string bundleName) { var errors = new List <string>(); var allBundleDebugLines = _reader.GetBundleDebugFiles(bundleName, "", s => errors.Add(s)); var allCdns = _reader.GetBundleCdnInfo(bundleName); if (errors.Any()) { return(errors.AsReadOnly()); } if (!allCdns.Any()) { return(CheckNonCdnBundle(bundleName, allBundleDebugLines).AsReadOnly()); } //It has Cdns if (allBundleDebugLines.Count() != allCdns.Count()) { return new List <string> { $"The Bundle called {bundleName} contained both cdn and non cdn entries, which is not supported." } }
public void TestGetBundleDebugFilesBadCndFileBundleSingleOk() { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles03*.json")); //ATTEMPT var ex = Assert.Throws<InvalidOperationException>( () => reader.GetBundleDebugFiles("missingDevelopmentJs")); //VERIFY ex.Message.ShouldEqual("The CDN bundle missingDevelopmentJs, array element 0, is missing a property called 'development'."); }
public void TestGetBundleDebugFilesNonCndFileBundleListOk(string bundleName, params string [] expectedfiles) { //SETUP var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json")); //ATTEMPT var files = reader.GetBundleDebugFiles(bundleName, ""); //VERIFY CollectionAssert.AreEqual(expectedfiles, files); }