Esempio n. 1
0
        public void NewCassetteManifestHasEmptyButNotNullBundleManifestList()
        {
            var manifest = new CassetteManifest();

            manifest.BundleManifests.ShouldNotBeNull();
            manifest.BundleManifests.ShouldBeEmpty();
        }
Esempio n. 2
0
 void WriteBundleManifests(CassetteManifest manifest)
 {
     foreach (var bundleManifest in manifest.BundleManifests)
     {
         WriteBundleManifest(bundleManifest);
     }
 }
Esempio n. 3
0
 public void Write(CassetteManifest manifest)
 {
     cassetteElement.Add(new XAttribute("Version", manifest.Version));
     cassetteElement.Add(new XAttribute("LastWriteTimeUtc", DateTime.UtcNow.ToString("r")));
     WriteBundleManifests(manifest);
     WriteToOutputStream();
 }
Esempio n. 4
0
        public void EmptyManifestsAreEqual()
        {
            var manifest1 = new CassetteManifest();
            var manifest2 = new CassetteManifest();

            manifest1.ShouldEqual(manifest2);
        }
Esempio n. 5
0
        public void CassetteManifestsAreEqualIfBundleManifestsAreEqualButInDifferentOrder()
        {
            var manifest1 = new CassetteManifest
            {
                BundleManifests =
                {
                    new ScriptBundleManifest {
                        Path = "~/A", Hash = new byte[0]
                    },
                    new ScriptBundleManifest {
                        Path = "~/B", Hash = new byte[0]
                    }
                }
            };
            var manifest2 = new CassetteManifest
            {
                BundleManifests =
                {
                    new ScriptBundleManifest {
                        Path = "~/B", Hash = new byte[0]
                    },
                    new ScriptBundleManifest {
                        Path = "~/A", Hash = new byte[0]
                    }
                }
            };

            manifest1.ShouldEqual(manifest2);
        }
Esempio n. 6
0
 public void SaveCassetteManifest(CassetteManifest cassetteManifest)
 {
     using (var fileStream = file.Open(FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
     {
         var writer = new CassetteManifestWriter(fileStream);
         writer.Write(cassetteManifest);
     }
 }
Esempio n. 7
0
 public void SaveCassetteManifest(CassetteManifest cassetteManifest)
 {
     using (var fileStream = file.Open(FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
     {
         var writer = new CassetteManifestWriter(fileStream);
         writer.Write(cassetteManifest);
     }
 }
 public void CassetteManifestsWithDifferentNumberOfBundleManifestsAreNotEqual()
 {
     var manifest1 = new CassetteManifest();
     var manifest2 = new CassetteManifest
     {
         BundleManifests = { new ScriptBundleManifest { Path = "~", Hash = new byte[0] } }
     };
     manifest1.ShouldNotEqual(manifest2);
 }
        public GivenManifestWrittenToStream_WhenReadStreamIntoNewManifest()
        {
            startTime = UtcNowToTheSecond();
            using (var stream = new MemoryStream())
            {
                originalManifest = CreateOriginalManifest();

                WriteManifestToStream(originalManifest, stream);
                newManifest = ReadManifestFromStream(stream);
            }
        }
Esempio n. 10
0
        public GivenManifestWrittenToStream_WhenReadStreamIntoNewManifest()
        {
            startTime = UtcNowToTheSecond();
            using (var stream = new MemoryStream())
            {
                originalManifest = CreateOriginalManifest();

                WriteManifestToStream(originalManifest, stream);
                newManifest = ReadManifestFromStream(stream);
            }
        }
Esempio n. 11
0
        public void ManifestsWithDifferentVersionsAreNotEquals()
        {
            var manifest1 = new CassetteManifest {
                Version = "v1"
            };
            var manifest2 = new CassetteManifest {
                Version = "v2"
            };

            manifest1.ShouldNotEqual(manifest2);
        }
Esempio n. 12
0
 public void CassetteManifestsAreEqualIfBundleManifestsAreEqual()
 {
     var manifest1 = new CassetteManifest
     {
         BundleManifests = { new ScriptBundleManifest { Path = "~", Hash = new byte[0] } }
     };
     var manifest2 = new CassetteManifest
     {
         BundleManifests = { new ScriptBundleManifest { Path = "~", Hash = new byte[0] } }
     };
     manifest1.ShouldEqual(manifest2);
 }
Esempio n. 13
0
        public void CassetteManifestsWithDifferentNumberOfBundleManifestsAreNotEqual()
        {
            var manifest1 = new CassetteManifest();
            var manifest2 = new CassetteManifest
            {
                BundleManifests = { new ScriptBundleManifest {
                                        Path = "~", Hash = new byte[0]
                                    } }
            };

            manifest1.ShouldNotEqual(manifest2);
        }
        public CassetteManifest Read()
        {
            cassetteManifest = new CassetteManifest();

            var document = XDocument.Load(inputStream);
            var cassetteElement = document.Root;

            cassetteManifest.LastWriteTimeUtc = GetLastWriteTimeUtc(cassetteElement);
            cassetteManifest.Version = GetVersion(cassetteElement);
            AddBundleManifests(cassetteElement);

            return cassetteManifest;
        }
Esempio n. 15
0
        public void CreateBundlesReturnsOneBundlePerBundleManifest()
        {
            var manifest = new CassetteManifest("", new BundleManifest[]
            {
                new ScriptBundleManifest { Path = "~/js", Hash = new byte[0], Html = () => "" },
                new StylesheetBundleManifest { Path = "~/css", Hash = new byte[0], Html = () => "" }
            });

            var bundles = manifest.CreateBundleCollection(new CassetteSettings("")).ToArray();

            bundles.Length.ShouldEqual(2);
            bundles[0].ShouldBeType<ScriptBundle>();
            bundles[1].ShouldBeType<StylesheetBundle>();
        }
        void CompileTimeManifestWithBundleExists(string rootDirectory)
        {
            var bundle = StubBundle();
            var bundleManifest = bundle.CreateBundleManifest(true);

            var cassetteManifest = new CassetteManifest("", new[] { bundleManifest });

            var manifestFilename = Path.Combine(rootDirectory, "App_Data", "cassette.xml");
            Directory.CreateDirectory(Path.Combine(rootDirectory, "App_Data"));
            using (var outputStream = File.Open(manifestFilename, FileMode.Create, FileAccess.Write))
            {
                var writer = new CassetteManifestWriter(outputStream);
                writer.Write(cassetteManifest);
            }
        }
 Bundle[] CreateBundles(CassetteManifest cachedManifest, CassetteManifest currentManifest)
 {
     var canUseCachedBundles = cachedManifest.Equals(currentManifest)
                            && cachedManifest.IsUpToDateWithFileSystem(settings.SourceDirectory);
     if (canUseCachedBundles)
     {
         Trace.Source.TraceInformation("Using cache.");
         UseCachedBundles(cachedManifest);
     }
     else
     {
         CacheAndUseCurrentBundles();
     }
     return bundlesArray;
 }
Esempio n. 18
0
        public void GivenManifestWithBundle_WhenSaveCassetteManifest_ThenXmlLastWriteTimeUtcAttributeIsNow()
        {
            var now = DateTime.UtcNow;

            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, DateTimeKind.Utc);

            var manifest = new CassetteManifest("", new BundleManifest[0]);

            cache.SaveCassetteManifest(manifest);

            var xml = SavedXml();
            var lastWriteTimeUtc = DateTime.Parse(xml.Root.Attribute("LastWriteTimeUtc").Value).ToUniversalTime();

            (lastWriteTimeUtc >= now).ShouldBeTrue();
        }
Esempio n. 19
0
        public void GivenManifestWithBundle_WhenSaveCassetteManifest_ThenXmlContainsBundleElement()
        {
            var manifest = new CassetteManifest(
                "",
                new[] { new ScriptBundleManifest {
                            Path = "~", Hash = new byte[0]
                        } }
                );

            cache.SaveCassetteManifest(manifest);

            var xml = SavedXml();

            xml.Root.Elements("ScriptBundle").Count().ShouldEqual(1);
        }
        public CassetteManifest Read()
        {
            cassetteManifest = new CassetteManifest();
            #if NET35
            var reader = XmlReader.Create(inputStream);
            var document = XDocument.Load(reader);
            #else
            var document = XDocument.Load(inputStream);
            #endif
            var cassetteElement = document.Root;

            cassetteManifest.LastWriteTimeUtc = GetLastWriteTimeUtc(cassetteElement);
            cassetteManifest.Version = GetVersion(cassetteElement);
            AddBundleManifests(cassetteElement);

            return cassetteManifest;
        }
Esempio n. 21
0
        public void CassetteManifestsAreEqualIfBundleManifestsAreEqual()
        {
            var manifest1 = new CassetteManifest
            {
                BundleManifests = { new ScriptBundleManifest {
                                        Path = "~", Hash = new byte[0]
                                    } }
            };
            var manifest2 = new CassetteManifest
            {
                BundleManifests = { new ScriptBundleManifest {
                                        Path = "~", Hash = new byte[0]
                                    } }
            };

            manifest1.ShouldEqual(manifest2);
        }
Esempio n. 22
0
        public CassetteManifest Read()
        {
            cassetteManifest = new CassetteManifest();
#if NET35
            var reader   = XmlReader.Create(inputStream);
            var document = XDocument.Load(reader);
#else
            var document = XDocument.Load(inputStream);
#endif
            var cassetteElement = document.Root;

            cassetteManifest.LastWriteTimeUtc = GetLastWriteTimeUtc(cassetteElement);
            cassetteManifest.Version          = GetVersion(cassetteElement);
            AddBundleManifests(cassetteElement);

            return(cassetteManifest);
        }
Esempio n. 23
0
        public void CreateBundlesReturnsOneBundlePerBundleManifest()
        {
            var manifest = new CassetteManifest("", new BundleManifest[]
            {
                new ScriptBundleManifest {
                    Path = "~/js", Hash = new byte[0], Html = () => ""
                },
                new StylesheetBundleManifest {
                    Path = "~/css", Hash = new byte[0], Html = () => ""
                }
            });

            var bundles = manifest.CreateBundleCollection(new CassetteSettings("")).ToArray();

            bundles.Length.ShouldEqual(2);
            bundles[0].ShouldBeType <ScriptBundle>();
            bundles[1].ShouldBeType <StylesheetBundle>();
        }
        public void GivenCachedManifestWithOneBundle_WhenCreateWithMatchingUpToDateBundle_ThenCachedBundleIsReturned()
        {
            var cachedManifest = new CassetteManifest(
                "",
                new[]
                {
                    new ScriptBundleManifest { Path = "~", Hash = new byte[] { 1, 2, 3 } }
                }
            );
            cache.Setup(c => c.LoadCassetteManifest()).Returns(cachedManifest);

            var factory = CreateFactory();
            var container = factory.Create(new[] { new ScriptBundle("~") });

            var bundle = container.Bundles.Single();
            bundle.Hash.ShouldEqual(new byte[] { 1, 2, 3 });
            bundle.IsFromCache.ShouldBeTrue();
            bundle.IsProcessed.ShouldBeTrue();
        }
Esempio n. 25
0
 public void CassetteManifestsAreEqualIfBundleManifestsAreEqualButInDifferentOrder()
 {
     var manifest1 = new CassetteManifest
     {
         BundleManifests =
             {
                 new ScriptBundleManifest { Path = "~/A", Hash = new byte[0] },
                 new ScriptBundleManifest { Path = "~/B", Hash = new byte[0] }
             }
     };
     var manifest2 = new CassetteManifest
     {
         BundleManifests =
             {
                 new ScriptBundleManifest { Path = "~/B", Hash = new byte[0] },
                 new ScriptBundleManifest { Path = "~/A", Hash = new byte[0] }
             }
     };
     manifest1.ShouldEqual(manifest2);
 }
        public void GivenCachedManifestWithOneBundle_WhenCreateWithMatchingUpToDateBundle_ThenCachedBundleIsReturned()
        {
            var cachedManifest = new CassetteManifest(
                "",
                new[]
                {
                    new ScriptBundleManifest
                    {
                        Path = "~",
                        Hash = new byte[] { 1, 2, 3 },
                        Html = () => ""
                    }
                }
            );
            cache.Setup(c => c.LoadCassetteManifest()).Returns(cachedManifest);

            var scriptBundle = new ScriptBundle("~") { Renderer = new ConstantHtmlRenderer<ScriptBundle>("") };
            var factory = CreateFactory(new[] { scriptBundle });
            var container = factory.CreateBundleContainer();

            var bundle = container.Bundles.Single();
            bundle.Hash.ShouldEqual(new byte[] { 1, 2, 3 });
        }
Esempio n. 27
0
 public void EmptyManifestsAreEqual()
 {
     var manifest1 = new CassetteManifest();
     var manifest2 = new CassetteManifest();
     manifest1.ShouldEqual(manifest2);
 }
 void UseCachedBundles(CassetteManifest cachedManifest)
 {
     bundlesArray = cachedManifest.CreateBundles().ToArray();
     ProcessAllBundles(bundlesArray);
 }
Esempio n. 29
0
 bool BundleManifestsEqual(CassetteManifest other)
 {
     return(BundleManifests.OrderBy(b => b.Path).SequenceEqual(other.BundleManifests.OrderBy(b => b.Path)));
 }
Esempio n. 30
0
        void WriteManifestToStream(CassetteManifest manifest, Stream stream)
        {
            var writer = new CassetteManifestWriter(stream);

            writer.Write(manifest);
        }
Esempio n. 31
0
 public void NewCassetteManifestVersionIsEmptyString()
 {
     var manifest = new CassetteManifest();
     manifest.Version.ShouldEqual("");
 }
Esempio n. 32
0
        public void NewCassetteManifestVersionIsEmptyString()
        {
            var manifest = new CassetteManifest();

            manifest.Version.ShouldEqual("");
        }
Esempio n. 33
0
 public void ManifestsWithDifferentVersionsAreNotEquals()
 {
     var manifest1 = new CassetteManifest { Version = "v1" };
     var manifest2 = new CassetteManifest { Version = "v2" };
     manifest1.ShouldNotEqual(manifest2);
 }
        public void GivenManifestWithBundle_WhenSaveCassetteManifest_ThenXmlLastWriteTimeUtcAttributeIsNow()
        {
            var now = DateTime.UtcNow;
            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, DateTimeKind.Utc);

            var manifest = new CassetteManifest("", new BundleManifest[0]);
            cache.SaveCassetteManifest(manifest);

            var xml = SavedXml();
            var lastWriteTimeUtc = DateTime.Parse(xml.Root.Attribute("LastWriteTimeUtc").Value).ToUniversalTime();
            (lastWriteTimeUtc >= now).ShouldBeTrue();
        }
        public void GivenManifestWithBundle_WhenSaveCassetteManifest_ThenXmlContainsBundleElement()
        {
            var manifest = new CassetteManifest(
                "",
                new[] { new ScriptBundleManifest { Path = "~", Hash = new byte[0] } }
            );
            cache.SaveCassetteManifest(manifest);

            var xml = SavedXml();
            xml.Root.Elements("ScriptBundle").Count().ShouldEqual(1);
        }
 void WriteManifest()
 {
     var manifest = new CassetteManifest("", bundles.Select(bundle => bundle.CreateBundleManifest(true)));
     manifestWriter.Write(manifest);
 }
 void WriteManifestToStream(CassetteManifest manifest, Stream stream)
 {
     var writer = new CassetteManifestWriter(stream);
     writer.Write(manifest);
 }
Esempio n. 38
0
 public void NewCassetteManifestHasEmptyButNotNullBundleManifestList()
 {
     var manifest = new CassetteManifest();
     manifest.BundleManifests.ShouldNotBeNull();
     manifest.BundleManifests.ShouldBeEmpty();
 }
Esempio n. 39
0
 bool BundleManifestsEqual(CassetteManifest other)
 {
     return BundleManifests.OrderBy(b => b.Path).SequenceEqual(other.BundleManifests.OrderBy(b => b.Path));
 }