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 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.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.Setup(b => b.Render()).Returns("");
            bundles.Add(stylesheetBundle.Object);

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

            cache.Write(new Manifest(bundles, "VERSION"));
        }
 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 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 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 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 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));
            }
        }
        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 #9
0
        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);
            }
        }
        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);
            }
        }
        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 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();
            }
        }