This class helps with relative paths that contain a search string
        /// <summary>
        /// This creates the class ready for bundling
        /// </summary>
        /// <param name="jsonDataDir">The absolute directory path to the folder that holds the BowerBundles.json and the 
        ///     optional BundlerForBower.json config file</param>
        /// <param name="getAbsPathFromVirtualPath">This is a function which given a path relative to the MVC project 
        ///     will return the absolute path. In MVC5 this is provided by System.Web.Hosting.HostingEnvironment.MapPath.</param>
        /// <param name="getChecksumFromRelPath">This is a function returns a checksum of a file referred to via an relative path
        ///     Can be null, in which case no checksum can be used.</param>
        public BundlerForBower(string jsonDataDir, Func<string, string> getAbsPathFromVirtualPath,
            Func<string, string> getChecksumFromRelPath)
        {
            _jsonDataDir = jsonDataDir;
            _getChecksumFromRelPath = getChecksumFromRelPath ??
                (s => { throw new NotImplementedException("cachebuster parameters should not be allowed in this evironment.");});
            _searcher = new RelPathSearcher(getAbsPathFromVirtualPath);

            config = ConfigInfo.ReadConfig(Path.Combine(_jsonDataDir, B4BConfigFileName));
        }
Example #2
0
 /// <summary>
 /// This requires the path to the directory of the project where all the files are stored
 /// It uses the data directory to find the BowerBundles.json and the bundlerForBower.json user config file
 /// </summary>
 /// <param name="mvcAppPath">The absolute path to the project you want to test.</param>
 /// <param name="appDataDir">optional: if App_Data directory is not at the top level then you need to supply
 /// AppDomain.CurrentDomain.GetData("DataDirectory").ToString() or an equivalent absolute directory path</param>
 /// <param name="checkForConcatFile">optional: by default it checks the concat file, 
 /// but if you go straight to the minified file then set this to false</param>
 public CheckBundles(string mvcAppPath, string appDataDir = null, bool checkForConcatFile = true)
 {
     _mvcAppPath = mvcAppPath;
     _checkForConcatFile = checkForConcatFile;
     var appDataPath = appDataDir ?? Path.Combine(_mvcAppPath, DefaultAppDataDirName);
     _config = ConfigInfo.ReadConfig(Path.Combine(appDataPath, BundlerForBower.B4BConfigFileName));
     _bundleFilePath = Path.Combine(appDataPath, _config.BundlesFileName);
     _reader = new ReadBundleFile(_bundleFilePath);
     _searcher = new RelPathSearcher(s => Path.Combine(_mvcAppPath, s));
 }
        public void TestFindAllFilesBadDirSearchOk(string relFilePath, string expectedMessage)
        {
            //SETUP
            var searcher = new RelPathSearcher(B4BSetupHelper.GetActualFilePathFromVirtualPath());
            string errorMessage = null;

            //ATTEMPT
            var foundFiles = searcher.FindAllFiles(relFilePath, s => errorMessage = s);

            //VERIFY
            foundFiles.Count().ShouldEqual(0);
            errorMessage.ShouldEqual(expectedMessage);
        }
        public void TestFindAllFilesOnlyFileNameSearchOk(string relFilePath, params string [] expectedFiles)
        {
            //SETUP
            var searcher = new RelPathSearcher(B4BSetupHelper.GetActualFilePathFromVirtualPath());

            //ATTEMPT
            var foundFiles = searcher.FindAllFiles(relFilePath);

            //VERIFY
            CollectionAssert.AreEqual(expectedFiles, foundFiles);
        }