Exemple #1
0
        public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"1\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test.bundle"),
                    "asset"
                    );
                var bundleWithAsset = new TestableBundle("~/test");
                var asset = StubAsset();
                bundleWithAsset.Assets.Add(asset.Object);
                var sourceBundles = new[] { bundleWithAsset };

                var settings = new CassetteSettings("")
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeTrue();
                bundleWithAsset.Assets[0].OpenStream().ReadToEnd().ShouldEqual("asset");
            }
        }
Exemple #2
0
        public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"1\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test.bundle"),
                    "asset"
                    );
                var bundleWithAsset = new TestableBundle("~/test");
                var asset           = StubAsset();
                bundleWithAsset.Assets.Add(asset.Object);
                var sourceBundles = new[] { bundleWithAsset };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache  = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeTrue();
                bundleWithAsset.Assets[0].OpenStream().ReadToEnd().ShouldEqual("asset");
            }
        }
Exemple #3
0
        public void GivenCacheMissingSecondFile_WhenInitializeBundlesFromCacheIfUpToDate_ThenFirstBundleAssetsAreNotModified()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"2\"><Bundle Path=\"~/test1\" Hash=\"01\"/><Bundle Path=\"~/test2\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test1.bundle"),
                    "asset"
                    );
                var bundle1 = new TestableBundle("~/test1");
                var bundle2 = new TestableBundle("~/test2");
                var asset1  = StubAsset();
                bundle1.Assets.Add(asset1.Object);
                var asset2 = StubAsset();
                bundle2.Assets.Add(asset2.Object);
                var sourceBundles = new[] { bundle1, bundle2 };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache  = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
                bundle1.Assets[0].ShouldNotBeType <CachedAsset>();
            }
        }
Exemple #4
0
        public void GivenContainerFileIsOlderThanAnAssetFile_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\"></Container>"
                    );

                var bundleWithAsset = new TestableBundle("~/test");
                var asset           = StubAsset();
                asset.Setup(a => a.SourceFile.LastWriteTimeUtc).Returns(DateTime.UtcNow);
                bundleWithAsset.Assets.Add(asset.Object);
                var sourceBundles = new[] { bundleWithAsset };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache  = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #5
0
        public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnTrue()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test.bundle"),
                    "asset"
                    );

                var bundle        = new TestableBundle("~/test");
                var sourceBundles = new[] { bundle };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache  = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeTrue();
            }
        }
Exemple #6
0
        public void GivenContainerCacheHasFileReferenceThatIsModifiedSinceCacheWrite_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
                using (var sourceDir = new TempDirectory())
                {
                    File.WriteAllText(
                        Path.Combine(cacheDir, "container.xml"),
                        "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\">" +
                        "<Bundle Path=\"~/test\" Hash=\"01\">" +
                        "  <File Path=\"~/file.png\"/>" +
                        "</Bundle>" +
                        "</Container>"
                        );
                    Thread.Sleep(10); // Brief pause, otherwise the file write times are the same.
                    File.WriteAllText(Path.Combine(sourceDir, "file.png"), "");
                    var bundle        = new TestableBundle("~/test");
                    var sourceBundles = new[] { bundle };

                    var settings = new CassetteSettings("")
                    {
                        SourceDirectory = new FileSystemDirectory(sourceDir),
                        CacheDirectory  = new FileSystemDirectory(cacheDir)
                    };
                    var cache  = new BundleCache("VERSION", settings);
                    var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                    result.ShouldBeFalse();
                }
        }
Exemple #7
0
        public void GivenContainerCacheHasFileReferenceToMissingFile_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
                using (var sourceDir = new TempDirectory())
                {
                    File.WriteAllText(
                        Path.Combine(cacheDir, "container.xml"),
                        "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\">" +
                        "<Bundle Path=\"~/test\" Hash=\"01\">" +
                        "  <File Path=\"~/file.png\"/>" +
                        "</Bundle>" +
                        "</Container>"
                        );
                    var bundle        = new TestableBundle("~/test");
                    var sourceBundles = new[] { bundle };


                    var settings = new CassetteSettings
                    {
                        SourceDirectory = new FileSystemDirectory(sourceDir),
                        CacheDirectory  = new FileSystemDirectory(cacheDir)
                    };
                    var cache  = new BundleCache("VERSION", settings);
                    var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                    result.ShouldBeFalse();
                }
        }
Exemple #8
0
        public void GivenContainerCacheHasBundleReferences_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleReferencesAreSet()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\">" +
                    "<Bundle Path=\"~/test1\" Hash=\"01\">" +
                    "  <Reference Path=\"~/test2\"/>" +
                    "</Bundle>" +
                    "<Bundle Path=\"~/test2\" Hash=\"01\"/>" +
                    "</Container>"
                    );
                var bundle1       = new TestableBundle("~/test1");
                var bundle2       = new TestableBundle("~/test2");
                var sourceBundles = new[] { bundle1, bundle2 };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                bundle1.References.First().ShouldEqual("~/test2");
            }
        }
Exemple #9
0
        public void GivenContainerFileDoesNotExist_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            {
                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache         = new BundleCache("VERSION", settings);
                var sourceBundles = new TestableBundle[0];

                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #10
0
        public void GivenContainerFileWithDifferentVersion_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION-1\" AssetCount=\"0\"></Container>"
                    );

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of <IDirectory>(),
                    CacheDirectory  = new FileSystemDirectory(cacheDir)
                };
                var cache         = new BundleCache("VERSION-2", settings);
                var sourceBundles = new TestableBundle[0];

                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #11
0
        public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDateWithZeroAssetBundle_ThenReturnTrue()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\"><Bundle Path=\"~/test\" Hash=\"\"/></Container>"
                    );
                var bundle = new TestableBundle("~/test");
                var sourceBundles = new[] { bundle };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeTrue();
            }
        }
Exemple #12
0
        public void GivenContainerFileWithDifferentVersion_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION-1\" AssetCount=\"0\"></Container>"
                    );

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION-2", settings);
                var sourceBundles = new TestableBundle[0];

                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #13
0
        public void GivenContainerCacheHasFileReferenceThatIsModifiedSinceCacheWrite_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            using (var sourceDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\">" +
                    "<Bundle Path=\"~/test\" Hash=\"01\">" +
                    "  <File Path=\"~/file.png\"/>" +
                    "</Bundle>" +
                    "</Container>"
                );
                Thread.Sleep(10); // Brief pause, otherwise the file write times are the same.
                File.WriteAllText(Path.Combine(sourceDir, "file.png"), "");
                var bundle = new TestableBundle("~/test");
                var sourceBundles = new[] { bundle };

                var settings = new CassetteSettings("")
                {
                    SourceDirectory = new FileSystemDirectory(sourceDir),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #14
0
        public void GivenContainerFileIsOlderThanAnAssetFile_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\"></Container>"
                    );

                var bundleWithAsset = new TestableBundle("~/test");
                var asset = StubAsset();
                asset.Setup(a => a.SourceFile.LastWriteTimeUtc).Returns(DateTime.UtcNow);
                bundleWithAsset.Assets.Add(asset.Object);
                var sourceBundles = new[] { bundleWithAsset };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #15
0
        public void GivenContainerFileDoesNotExist_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            {
                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var sourceBundles = new TestableBundle[0];

                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #16
0
        public void GivenContainerCacheHasFileReferenceToMissingFile_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnFalse()
        {
            using (var cacheDir = new TempDirectory())
            using (var sourceDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\">" +
                    "<Bundle Path=\"~/test\" Hash=\"01\">" +
                    "  <File Path=\"~/file.png\"/>" +
                    "</Bundle>" +
                    "</Container>"
                );
                var bundle = new TestableBundle("~/test");
                var sourceBundles = new[] { bundle };

                var settings = new CassetteSettings
                {
                    SourceDirectory = new FileSystemDirectory(sourceDir),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
            }
        }
Exemple #17
0
        public void GivenContainerCacheHasBundleReferences_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleReferencesAreSet()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\">" +
                    "<Bundle Path=\"~/test1\" Hash=\"01\">" +
                    "  <Reference Path=\"~/test2\"/>" +
                    "</Bundle>" +
                    "<Bundle Path=\"~/test2\" Hash=\"01\"/>" +
                    "</Container>"
                    );
                var bundle1 = new TestableBundle("~/test1");
                var bundle2 = new TestableBundle("~/test2");
                var sourceBundles = new[] { bundle1, bundle2 };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                bundle1.References.First().ShouldEqual("~/test2");
            }
        }
Exemple #18
0
        public void GivenCacheMissingSecondFile_WhenInitializeBundlesFromCacheIfUpToDate_ThenFirstBundleAssetsAreNotModified()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"2\"><Bundle Path=\"~/test1\" Hash=\"01\"/><Bundle Path=\"~/test2\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test1.bundle"),
                    "asset"
                    );
                var bundle1 = new TestableBundle("~/test1");
                var bundle2 = new TestableBundle("~/test2");
                var asset1 = StubAsset();
                bundle1.Assets.Add(asset1.Object);
                var asset2 = StubAsset();
                bundle2.Assets.Add(asset2.Object);
                var sourceBundles = new[] { bundle1, bundle2 };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeFalse();
                bundle1.Assets[0].ShouldNotBeType<CachedAsset>();
            }
        }