public BundleCollectionCache_Write_Tests()
        {
            path = new TempDirectory();
            directory = new FileSystemDirectory(path);

            var bundles = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>());
            scriptBundle = new Mock<ScriptBundle>("~/test1");
            scriptBundle.CallBase = true;
            scriptBundle.Object.Hash = new byte[] { 1, 2, 3 };
            scriptBundle.Object.Assets.Add(new StubAsset("~/test/asset.js", "script-bundle-content"));
            scriptBundle.Object.Renderer = new ScriptBundleHtmlRenderer(Mock.Of<IUrlGenerator>());
            scriptBundle.Setup(b => b.Render()).Returns("");
            bundles.Add(scriptBundle.Object);

            stylesheetBundle = new Mock<StylesheetBundle>("~/test2");
            stylesheetBundle.CallBase = true;
            stylesheetBundle.Object.Hash = new byte[] { 4, 5, 6 };
            stylesheetBundle.Object.Assets.Add(new StubAsset("~/test2/asset.css", "stylesheet-bundle-content"));
            stylesheetBundle.Object.Renderer = new StylesheetHtmlRenderer(Mock.Of<IUrlGenerator>());
            stylesheetBundle.Setup(b => b.Render()).Returns("");
            bundles.Add(stylesheetBundle.Object);

            var cache = new BundleCollectionCache(directory, b => null);
            cache.Write(new Manifest(bundles, "VERSION"));
        }
 public void GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         dir.DirectoryExists("sub").ShouldBeFalse();
     }
 }
 public void WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         dir.DirectoryExists("~").ShouldBeTrue();
     }
 }
 public void GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         dir.DirectoryExists("sub").ShouldBeFalse();
     }
 }
 public void WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         dir.DirectoryExists("~").ShouldBeTrue();
     }
 }
 public void GivenSubDirectoryDoesNotExist_WhenGetFile_ThenReturnNonExistentFile()
 {
     using (var path = new TempDirectory())
     {
         var dir  = new FileSystemDirectory(path);
         var file = dir.GetFile("sub\\test.txt");
         file.ShouldBeType <NonExistentFile>();
     }
 }
 public void GivenFileDoesNotExist_WhenGetFile_ThenReturnFileSystemFile()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         var file = dir.GetFile("test.txt");
         file.ShouldBeType<FileSystemFile>();
     }
 }
 public void GivenEmptyDirectory_ThenCacheReadFails()
 {
     using (var path = new TempDirectory())
     {
         var directory = new FileSystemDirectory(path);
         var cache = new BundleCollectionCache(directory, b => deserializers[b]);
         var result = cache.Read();
         result.IsSuccess.ShouldBeFalse();
     }
 }
        public void GivenSubDirectoryExists_WhenCallDirectoryExistsWithApplicationAbsolutePath_ThenReturnTrue()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub"));

                var dir = new FileSystemDirectory(path);
                dir.DirectoryExists("~/sub").ShouldBeTrue();
            }
        }
        public void GivenSubDirectoryDoesNotExist_WhenGetDirectoryWithCreateTrue_ThenDirectoryIsCreated()
        {
            using (var path = new TempDirectory())
            {
                var dir = new FileSystemDirectory(path);
                dir.GetDirectory("sub", true);

                Directory.Exists(Path.Combine(path, "sub")).ShouldBeTrue();
            }
        }
        public void GivenSubDirectoryExists_WhenCallDirectoryExistsWithApplicationAbsolutePath_ThenReturnTrue()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub"));

                var dir = new FileSystemDirectory(path);
                dir.DirectoryExists("~/sub").ShouldBeTrue();
            }
        }
 public void GivenFileDoesNotExist_WhenGetFile_ThenReturnFileSystemFileThatDoesNotExist()
 {
     using (var path = new TempDirectory())
     {
         var dir  = new FileSystemDirectory(path);
         var file = dir.GetFile("test.txt");
         file.ShouldBeType <FileSystemFile>();
         file.Exists.ShouldBeFalse();
     }
 }
        public void ReturnsFilesWithApplicationAbsolutePaths()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(Path.Combine(path, "file.js"), "");
                var dir = new FileSystemDirectory(path);

                var files = dir.GetFiles("*", SearchOption.AllDirectories).ToArray();
                files[0].FullPath.ShouldEqual("~/file.js");
            }
        }
Exemple #14
0
 protected override void RegisterBundleCollectionInitializer()
 {
     Container.Register<IBundleCollectionInitializer, BundleCollectionInitializer>();
     Container.Register<IBundleCollectionCache>((c, p) =>
     {
         var cacheDirectory = new FileSystemDirectory(Path.GetFullPath(outputDirectory));
         return new BundleCollectionCache(
             cacheDirectory,
             bundleTypeName => ResolveBundleDeserializer(bundleTypeName, c)
         );
     });
 }
        public void GivenFileExists_WhenGetFile_ThenReturnFileSystemFile()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(Path.Combine(path, "test.txt"), "");

                var dir  = new FileSystemDirectory(path);
                var file = dir.GetFile("test.txt");
                file.ShouldBeType <FileSystemFile>();
                PathUtilities.PathsEqual(file.FullPath, "~/test.txt").ShouldBeTrue();
            }
        }
        public void FullPathsReturned()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "test"));
                File.WriteAllText(PathUtilities.Combine(path, "test", "asset.js"), "");

                var dir = new FileSystemDirectory(path);
                var filePaths = dir.GetFiles("*.js", SearchOption.AllDirectories).ToArray();
                filePaths[0].FullPath.ShouldEqual("~/test/asset.js");
            }
        }
        public void GivenNavigatedToSubDirectory_WhenGetFilePaths_ThenFullPathStillReturned()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "test"));
                File.WriteAllText(Path.Combine(path, "test", "asset.js"), "");

                var testDir   = new FileSystemDirectory(path).GetDirectory("test");
                var filePaths = testDir.GetFiles("*.js", SearchOption.AllDirectories).ToArray();
                filePaths[0].FullPath.ShouldEqual("~/test/asset.js");
            }
        }
        public void FullPathsReturned()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "test"));
                File.WriteAllText(Path.Combine(path, "test", "asset.js"), "");

                var dir       = new FileSystemDirectory(path);
                var filePaths = dir.GetFiles("*.js", SearchOption.AllDirectories).ToArray();
                filePaths[0].FullPath.ShouldEqual("~/test/asset.js");
            }
        }
        public void GivenPathStartsWithTilde_WhenGetDirectoryFromSubDirectory_ThenPathIsFromRoot()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub1"));
                Directory.CreateDirectory(Path.Combine(path, "sub2"));
                var top = new FileSystemDirectory(path);
                var sub1 = top.GetDirectory("sub1");

                var sub2 = sub1.GetDirectory("~/sub2");

                sub2.FullPath.ShouldEqual("~/sub2");
            }
        }
        public void GivenPathStartsWithTilde_WhenGetDirectoryFromSubDirectory_ThenPathIsFromRoot()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub1"));
                Directory.CreateDirectory(Path.Combine(path, "sub2"));
                var top  = new FileSystemDirectory(path);
                var sub1 = top.GetDirectory("sub1");

                var sub2 = sub1.GetDirectory("~/sub2");

                sub2.FullPath.ShouldEqual("~/sub2");
            }
        }
        public void GivenDirectoryWithManifest_ThenCacheReadSucceeds()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(path, "manifest.xml"),
                    "<?xml version=\"1.0\"?><BundleCollection Version=\"1\" IsStatic=\"false\"></BundleCollection>"
                );

                var directory = new FileSystemDirectory(path);
                var cache = new BundleCollectionCache(directory, b => deserializers[b]);
                var result = cache.Read();
                result.IsSuccess.ShouldBeTrue();
            }
        }
        public void GivenFilesAndSubDirectories_WhenDeleteAll_ThenEverythingIsDeleted()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub"));
                File.WriteAllText(Path.Combine(path, "file1.txt"), "1");
                File.WriteAllText(Path.Combine(path, "sub\\file2.txt"), "2");

                var dir = new FileSystemDirectory(path);
                dir.DeleteContents();

                Directory.GetFiles(path).Length.ShouldEqual(0);
                Directory.GetDirectories(path).Length.ShouldEqual(0);
            }
        }
        public void GivenFilesAndSubDirectories_WhenDeleteAll_ThenEverythingIsDeleted()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub"));
                File.WriteAllText(Path.Combine(path, "file1.txt"), "1");
                File.WriteAllText(Path.Combine(path, "sub\\file2.txt"), "2");

                var dir = new FileSystemDirectory(path);
                dir.DeleteContents();

                Directory.GetFiles(path).Length.ShouldEqual(0);
                Directory.GetDirectories(path).Length.ShouldEqual(0);
            }
        }
        public void CreationDateTimeEqualsManifestFileLastWriteTimeUtc()
        {
            using (var path = new TempDirectory())
            {
                var manifestFilename = Path.Combine(path, "manifest.xml");
                File.WriteAllText(
                    manifestFilename,
                    "<?xml version=\"1.0\"?><BundleCollection Version=\"1\" IsStatic=\"false\"></BundleCollection>"
                );

                var directory = new FileSystemDirectory(path);
                var cache = new BundleCollectionCache(directory, b => deserializers[b]);
                var result = cache.Read();
                result.Manifest.CreationDateTime.ShouldEqual(File.GetLastWriteTimeUtc(manifestFilename));
            }
        }
Exemple #25
0
        public Asset_CreateCacheManifest_Tests()
        {
            root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
            root.CreateSubdirectory("module");
            filename = Path.Combine(root.FullName, "module", "test.js");
            // Write some testable content to the file.
            File.WriteAllText(filename, "asset content");
            var fileSystem = new FileSystemDirectory(root.FullName);

            var module = new Module("~/module");
            asset = new Asset("~/module/test.js", module, fileSystem.GetFile("module\\test.js"));
            module.Assets.Add(asset);

            File.WriteAllText(Path.Combine(root.FullName, "module", "another.js"), "");
            var another = new Asset("~/module/another.js", module, fileSystem.GetFile("module\\another.js"));
            module.Assets.Add(another);
        }
        public void ItDeletesAllFilesInCacheDirectory()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "script/test1"));
                Directory.CreateDirectory(Path.Combine(path, "stylesheet/test2"));
                File.WriteAllText(Path.Combine(path, "manifest.xml"), "");
                File.WriteAllText(Path.Combine(path, "script/test1/010203.js"), "");
                File.WriteAllText(Path.Combine(path, "stylesheet/test2/040506.css"), "");

                var directory = new FileSystemDirectory(path);

                var cache = new BundleCollectionCache(directory, b => null);
                cache.Clear();

                Directory.GetFiles(path).Length.ShouldEqual(0);
                Directory.GetDirectories(path).Length.ShouldEqual(0);
            }
        }
Exemple #27
0
        /// <remarks>
        /// This method is a bit of a hack. An independently created FileSystemDirectory could be a sub-directory.
        /// This method converts it to a proper sub-directory object if possible, otherwise returns null.
        /// </remarks>
        internal IDirectory TryGetAsSubDirectory(FileSystemDirectory directory)
        {
            // Example:
            // fullSystemPath == "c:\example"
            // directory.fullSystemPath == "c:\example\sub"
            // return GetDirectory("sub")

            var isSubDirectory =
                directory.fullSystemPath.Length >= fullSystemPath.Length &&
                directory.fullSystemPath.Substring(0, fullSystemPath.Length).Equals(fullSystemPath, StringComparison.OrdinalIgnoreCase);

            if (isSubDirectory)
            {
                var subPath = directory.fullSystemPath.Substring(fullSystemPath.Length + 1);
                return(GetDirectory(subPath));
            }
            else
            {
                return(null);
            }
        }
 protected void ProcessAllBundles(IList<Bundle> bundles)
 {
     Trace.Source.TraceInformation("Processing bundles...");
     if (!settings.IsDebuggingEnabled)
     {
         foreach (var bundle in bundles)
         {
             bundle.Process(settings);
         }
     }
     else
     {
         var hasher = new AssignHash();
         var diskBacker = new FileHelper();
         var bundlesToSort = new List<Bundle>();
         var directory = new FileSystemDirectory(DiskBackedBundleCache.CacheDirectory);
         for (var i = 0; i < bundles.Count; i++)
         {
             bundles[i] = ProcessSingleBundle(diskBacker, directory, bundlesToSort,
                 CassetteSettings.uncachedToCachedFiles, bundles[i], hasher);
             if (typeof(StylesheetBundle).IsAssignableFrom(bundles[i].GetType()))
             {
                 ((StylesheetBundle)bundles[i]).Renderer = new DebugStylesheetHtmlRenderer(settings.UrlGenerator);
             }
             else if (typeof(ScriptBundle).IsAssignableFrom(bundles[i].GetType()))
             {
                 ((ScriptBundle)bundles[i]).Renderer = new DebugScriptBundleHtmlRenderer(settings.UrlGenerator);
             }
             else if (typeof(HtmlTemplateBundle).IsAssignableFrom(bundles[i].GetType()))
             {
                 ((HtmlTemplateBundle)bundles[i]).Renderer = new DebugHtmlTemplateBundleRenderer(settings.UrlGenerator);
                 bundles[i].ContentType = "text/javascript";
             }
         }
         CassetteSettings.bundles.FixReferences(CassetteSettings.uncachedToCachedFiles, bundles);
         bundlesToSort.ForEach(b => b.SortAssetsByDependency());
     }
     Trace.Source.TraceInformation("Bundle processing completed.");
 }
 public void GivenSubDirectoryDoesNotExist_WhenGetFile_ThenReturnNonExistentFile()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         var file = dir.GetFile("sub\\test.txt");
         file.Exists.ShouldBeFalse();
     }
 }
Exemple #30
0
 public FileSearch_Tests()
 {
     temp = new TempDirectory();
     directory = new FileSystemDirectory(temp);
 }
Exemple #31
0
        public void Variable_defined_by_nested_import_is_replaced_in_CSS_output()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(Path.Combine(path, "main.less"), "@import 'first.less';\np { color: @c }");
                File.WriteAllText(Path.Combine(path, "first.less"), "@import 'second.less';");
                File.WriteAllText(Path.Combine(path, "second.less"), "@c: red;");
                var directory = new FileSystemDirectory(path);
                var file = directory.GetFile("main.less");

                compileContext.RootDirectory = directory;
                compileContext.SourceFilePath = "~/main.less";
                var css = compiler.Compile(file.OpenRead().ReadToEnd(), compileContext);

                css.Output.ShouldContain("color: red;");
            }
        }
        public void GivenNavigatedToSubDirectory_WhenGetFilePaths_ThenFullPathStillReturned()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "test"));
                File.WriteAllText(PathUtilities.Combine(path, "test", "asset.js"), "");

                var testDir = new FileSystemDirectory(path).GetDirectory("test");
                var filePaths = testDir.GetFiles("*.js", SearchOption.AllDirectories).ToArray();
                filePaths[0].FullPath.ShouldEqual("~/test/asset.js");
            }
        }
Exemple #33
0
 public FileSearch_SpecialMinifiedFileDetection()
 {
     temp = new TempDirectory();
     directory = new FileSystemDirectory(temp);
 }
        /// <remarks>
        /// This method is a bit of a hack. An independently created FileSystemDirectory could be a sub-directory.
        /// This method converts it to a proper sub-directory object if possible, otherwise returns null.
        /// </remarks>
        internal IDirectory TryGetAsSubDirectory(FileSystemDirectory directory)
        {
            // Example:
            // fullSystemPath == "c:\example"
            // directory.fullSystemPath == "c:\example\sub"
            // return GetDirectory("sub")

            var isSubDirectory =
                directory.fullSystemPath.Length >= fullSystemPath.Length &&
                directory.fullSystemPath.Substring(0, fullSystemPath.Length).Equals(fullSystemPath, StringComparison.OrdinalIgnoreCase);

            if (isSubDirectory)
            {
                var subPath = directory.fullSystemPath.Substring(fullSystemPath.Length + 1);
                return GetDirectory(subPath);
            }
            else
            {
                return null;
            }
        }
        public void GivenManifestAndBundleContentInDirectory_ThenCacheReadContainsBundle()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "script/test"));
                File.WriteAllText(
                    Path.Combine(path, "manifest.xml"),
                    "<?xml version=\"1.0\"?>" +
                    "<BundleCollection Version=\"1\" IsStatic=\"false\">" +
                    "<ScriptBundle Path=\"~/test\" Hash=\"010203\"/>" +
                    "</BundleCollection>"
                );
                File.WriteAllText(Path.Combine(path, "script/test/010203.js"), "");

                var directory = new FileSystemDirectory(path);
                var cache = new BundleCollectionCache(directory, b => deserializers[b]);
                cache.Read();

                scriptBundleDeserializer.VerifyAll();
            }
        }
        public void ReturnsFilesWithApplicationAbsolutePaths()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(Path.Combine(path, "file.js"), "");
                var dir = new FileSystemDirectory(path);

                var files = dir.GetFiles("*", SearchOption.AllDirectories).ToArray();
                files[0].FullPath.ShouldEqual("~/file.js");
            }
        }
        public void GivenFileExists_WhenGetFile_ThenReturnFileSystemFile()
        {
            using (var path = new TempDirectory())
            {
                File.WriteAllText(Path.Combine(path, "test.txt"), "");

                var dir = new FileSystemDirectory(path);
                var file = dir.GetFile("test.txt");
                file.ShouldBeType<FileSystemFile>();
                PathUtilities.PathsEqual(file.FullPath, "~/test.txt").ShouldBeTrue();
            }
        }