public FileSystemWatchingBundleRebuilder_Tests()
        {
            tempDirectory = new TempDirectory();
            Directory.CreateDirectory(Path.Combine(tempDirectory, "cache"));
            var settings = new CassetteSettings
            {
                SourceDirectory = new FileSystemDirectory(tempDirectory),
                CacheDirectory = new FileSystemDirectory(Path.Combine(tempDirectory, "cache")),
                IsFileSystemWatchingEnabled = true
            };
            bundles = new BundleCollection(settings, Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>());
            bundleConfiguration = new Mock<IConfiguration<BundleCollection>>();

            var bundle = new TestableBundle("~");
            var asset1 = new StubAsset("~/test.js");
            var asset2 = new StubAsset("~/sub/test2.js");
            asset1.AddRawFileReference("~/image.png");
            bundle.Assets.Add(asset1);
            bundle.Assets.Add(asset2);
            bundles.Add(bundle);

            fileSearch = new Mock<IFileSearch>();
            fileSearch
                .Setup(s => s.IsMatch(It.IsAny<string>()))
                .Returns<string>(path => path.EndsWith(".js"));

            var initializer = new BundleCollectionInitializer(new[] { bundleConfiguration.Object }, new ExternalBundleGenerator(Mock.Of<IBundleFactoryProvider>(), settings));
            rebuilder = new FileSystemWatchingBundleRebuilder(settings, bundles, initializer, new[] { fileSearch.Object });
        }
Пример #2
0
 public void StoresReferences()
 {
     var bundle = new TestableBundle("~/bundle");
     bundle.AddReference("~\\test");
     bundle.AddReference("~\\other");
     bundle.References.SequenceEqual(new[] { "~/test", "~/other" }).ShouldBeTrue();
 }
 public BundleCollection_AddPerSubDirectory_Tests()
 {
     factory
         .Setup(f => f.CreateBundle(It.IsAny<string>(), It.IsAny<IEnumerable<IFile>>(), It.IsAny<BundleDescriptor>()))
         .Returns<string, IEnumerable<IFile>, BundleDescriptor>(
             (path, files, d) => createdBundle = new TestableBundle(path)
         );
 }
Пример #4
0
        public void CreateBundleUrlCallsBundleUrlProperty()
        {
            var bundle = new TestableBundle("~") { Hash = new byte[] {} };

            var url = UrlGenerator.CreateBundleUrl(bundle, false);

            url.ShouldEqual("_cassette/testablebundle/_");
        }
        public void CreateBundleUrlCallsBundleUrlProperty()
        {
            var bundle = new TestableBundle("~") { Hash = new byte[] { 1, 2, 3 } };

            var url = UrlGenerator.CreateBundleUrl(bundle);

            url.ShouldEqual("cassette.axd/" + bundle.Url);
        }
Пример #6
0
        public void GivenBundleAdded_WhenAddAnotherWithSamePath_ThenExceptionIsThrown()
        {
            var bundle = new TestableBundle("~/test");
            bundles.Add(bundle);

            Assert.Throws<ArgumentException>(
                () => bundles.Add(new TestableBundle("~/test"))
            );
        }
Пример #7
0
        public void GivenBundleAdded_WhenGetByPartialPath_ThenBundleReturned()
        {
            var bundle = new TestableBundle("~/test");
            bundles.Add(bundle);

            var actualBundle = bundles.Get("test");

            actualBundle.ShouldBeSameAs(bundle);
        }
Пример #8
0
 public void BundlesWithSamePathButDifferentAssetsAreNotEqual()
 {
     var bundle1 = new TestableBundle("~/bundle");
     var asset1 = new StubAsset("~/bundle/asset1.js");
     bundle1.Assets.Add(asset1);
     var bundle2 = new TestableBundle("~/bundle");
     var asset2 = new StubAsset("~/bundle/asset2.js");
     bundle2.Assets.Add(asset2);
     bundle1.Equals(bundle2).ShouldBeFalse();
 }
Пример #9
0
        public void GivenBundlesWithNoDependenciesAreReferencedInNonAlphaOrder_WhenIncludeReferencesAndSortBundles_ThenReferenceOrderIsMaintained()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            var bundle2 = new TestableBundle("~/bundle2");
            var container = new BundleContainer(new[] { bundle1, bundle2 });

            var sorted = container.IncludeReferencesAndSortBundles(new[] { bundle2, bundle1 });

            sorted.SequenceEqual(new[] { bundle2, bundle1 }).ShouldBeTrue();
        }
Пример #10
0
        public void GivenBundleWithReferenceToAnotherBundle_BundlesAreSortedInDependencyOrder()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            var bundle2 = new TestableBundle("~/bundle2");
            bundle1.AddReference("~/bundle2");

            var container = new BundleContainer(new[] { bundle1, bundle2 });
            var sorted = container.IncludeReferencesAndSortBundles(new[] { bundle1, bundle2 });
            sorted.SequenceEqual(new[] { bundle2, bundle1 }).ShouldBeTrue();
        }
 public void FindBundleContainingPathOfBundleWherePathIsMissingRootPrefixReturnsTheBundle()
 {
     var expectedBundle = new TestableBundle("~/test");
     var collection = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>())
     {
         expectedBundle
     };
     var actualBundle = collection.FindBundlesContainingPath("test").First();
     actualBundle.ShouldBeSameAs(expectedBundle);
 }
        public void GivenBundleWithReferenceToAnotherBundle_BundlesAreSortedInDependencyOrder()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            var bundle2 = new TestableBundle("~/bundle2");
            bundle1.AddReference("~/bundle2");

            var collection = CreateBundleCollection(new[] { bundle1, bundle2 });
            collection.BuildReferences();
            var sorted = collection.SortBundles(new[] { bundle1, bundle2 });
            sorted.SequenceEqual(new[] { bundle2, bundle1 }).ShouldBeTrue();
        }
        public void GivenBundlesWithNoDependenciesAreReferencedInNonAlphaOrder_WhenSortBundles_ThenReferenceOrderIsMaintained()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            var bundle2 = new TestableBundle("~/bundle2");
            var collection = CreateBundleCollection(new[] { bundle1, bundle2 });

            collection.BuildReferences();
            var sorted = collection.SortBundles(new[] { bundle2, bundle1 });

            sorted.SequenceEqual(new[] { bundle2, bundle1 }).ShouldBeTrue();
        }
Пример #14
0
        public void GivenBundlesAdded_WhenEnumerated_ThenBundlesReturned()
        {
            var bundle1 = new TestableBundle("~/test1");
            var bundle2 = new TestableBundle("~/test2");
            bundles.Add(bundle1);
            bundles.Add(bundle2);

            var set = new HashSet<Bundle>(bundles);

            set.SetEquals(new[] { bundle1, bundle2 }).ShouldBeTrue();
        }
        public void GivenBundlesWithCyclicReferences_WhenBuildReferences_ThenExceptionThrown()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            var bundle2 = new TestableBundle("~/bundle2");
            bundle1.AddReference("~/bundle2");
            bundle2.AddReference("~/bundle1");
            var collection = CreateBundleCollection(new[] { bundle1, bundle2 });

            Assert.Throws<InvalidOperationException>(
                () => collection.BuildReferences()
            );
        }
        public void GivenBundleWithInvalid_BuildReferencesThrowsException()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            bundle1.AddReference("~\\bundle2");
            collection.Add(bundle1);

            var exception = Assert.Throws<AssetReferenceException>(delegate
            {
                collection.BuildReferences();
            });
            exception.Message.ShouldEqual("Reference error in bundle descriptor for \"~/bundle1\". Cannot find \"~/bundle2\".");
        }
Пример #17
0
        public void BundleAssetsAreSortedByPathBeforeBeingComparedForEquality()
        {
            var bundle1 = new TestableBundle("~/bundle");
            bundle1.Assets.Add(new StubAsset("~/bundle/asset1.js"));
            bundle1.Assets.Add(new StubAsset("~/bundle/asset2.js"));

            var bundle2 = new TestableBundle("~/bundle");
            bundle2.Assets.Add(new StubAsset("~/bundle/asset2.js"));
            bundle2.Assets.Add(new StubAsset("~/bundle/asset1.js"));

            bundle1.Equals(bundle2).ShouldBeTrue();
        }
Пример #18
0
        public void GivenBundleReferencedInOneLocationAlsoUsedInAnother_WhenGetBundlesForSecondLocation_ThenBundleForFirstLocationIsNotIncluded()
        {
            var bundle1 = new TestableBundle("~/test1") { PageLocation = "head" };
            var bundle2 = new TestableBundle("~/test2");
            bundle2.AddReference("~/test1");
            bundleContainer.Setup(c => c.FindBundlesContainingPath("~/test2"))
                           .Returns(new Bundle[] { bundle2 });
            bundleContainer.Setup(c => c.IncludeReferencesAndSortBundles(It.IsAny<IEnumerable<Bundle>>()))
                           .Returns<IEnumerable<Bundle>>(ms => new[] { bundle1, bundle2 });

            builder.Reference("~/test2");
            builder.GetBundles(null).Count().ShouldEqual(1);
        }
Пример #19
0
        public void GivenBundlesWithCyclicReferences_WhenIncludeReferencesAndSortBundles_ThenExceptionThrown()
        {
            var bundle1 = new TestableBundle("~/bundle1");
            var bundle2 = new TestableBundle("~/bundle2");
            bundle1.AddReference("~/bundle2");
            bundle2.AddReference("~/bundle1");
            var container = new BundleContainer(new[] { bundle1, bundle2 });

            Assert.Throws<InvalidOperationException>(delegate
            {
                container.IncludeReferencesAndSortBundles(new[] { bundle2, bundle1 });
            });
        }
        public void GivenAssetWithReferenceToNonexistantFileAndBundleIsFromDescriptorFile_WhenBuildReferences_ThenAssetReferenceIsIgnored()
        {
            var bundle = new TestableBundle("~");
            var asset = new StubAsset();
            var badReference = new AssetReference(asset.Path, "~/NOT-FOUND.js", 1, AssetReferenceType.DifferentBundle);
            asset.ReferenceList.Add(badReference);
            bundle.Assets.Add(asset);
            bundle.DescriptorFilePath = "~/bundle.txt";
            collection.Add(bundle);

            Assert.DoesNotThrow(
                () => collection.BuildReferences()
            );
        }
Пример #21
0
        public void AcceptCallsAcceptForEachAsset()
        {
            var visitor = new Mock<IBundleVisitor>();
            var bundle = new TestableBundle("~/test");
            var asset1 = new Mock<IAsset>();
            var asset2 = new Mock<IAsset>();
            bundle.Assets.Add(asset1.Object);
            bundle.Assets.Add(asset2.Object);

            bundle.Accept(visitor.Object);

            asset1.Verify(a => a.Accept(visitor.Object));
            asset2.Verify(a => a.Accept(visitor.Object));
        }
 public void FindBundleContainingPathOfAssetReturnsTheBundle()
 {
     var expectedBundle = new TestableBundle("~/test");
     var asset = new Mock<IAsset>();
     AssetAcceptsVisitor(asset);
     asset.SetupGet(a => a.Path).Returns("~/test/test.js");
     expectedBundle.Assets.Add(asset.Object);
     var bundles = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>())
     {
         expectedBundle
     };
     var actualBundle = bundles.FindBundlesContainingPath("~/test/test.js").First();
     actualBundle.ShouldBeSameAs(expectedBundle);
 }
Пример #23
0
        public void BundleWithConcatenatedAssetsEqualsBundleWithUnconcatenatedAssets()
        {
            var bundle1 = new TestableBundle("~/bundle");
            bundle1.Assets.Add(
                new ConcatenatedAsset(
                    new[] { new StubAsset("~/bundle/asset1.js"), new StubAsset("~/bundle/asset2.js") },
                    ";"
                )
            );

            var bundle2 = new TestableBundle("~/bundle");
            bundle2.Assets.Add(new StubAsset("~/bundle/asset2.js"));
            bundle2.Assets.Add(new StubAsset("~/bundle/asset1.js"));

            bundle1.Equals(bundle2).ShouldBeTrue();
        }
        public void ChangeEventArgsContainsReadOnlyCopyOfBundlesCollection()
        {
            IEnumerable<Bundle> readOnlyBundleCollection = null;
            bundles.Changed += (sender, args) =>
            {
                readOnlyBundleCollection = args.Bundles;
            };

            var bundle = new TestableBundle("~");

            using (bundles.GetWriteLock())
            {
                bundles.Add(bundle);
            }

            readOnlyBundleCollection.First().ShouldBeSameAs(bundle);
        }
        public void GivenAssetWithUnknownDifferentBundleReferenceHavingLineNumber_ThenBuildReferencesThrowsAssetReferenceException()
        {
            var bundle = new TestableBundle("~/bundle-1");
            var asset = new Mock<IAsset>();
            AssetAcceptsVisitor(asset);
            asset.SetupGet(a => a.Path).Returns("~/bundle-1/a.js");
            asset.SetupGet(a => a.References)
                  .Returns(new[] { new AssetReference(asset.Object.Path, "~\\fail\\fail.js", 42, AssetReferenceType.DifferentBundle) });
            bundle.Assets.Add(asset.Object);
            collection.Add(bundle);

            var exception = Assert.Throws<AssetReferenceException>(delegate
            {
                collection.BuildReferences();
            });
            exception.Message.ShouldEqual("Reference error in \"~/bundle-1/a.js\", line 42. Cannot find \"~\\fail\\fail.js\".");
        }
        public void ChangeEventArgsIsSnapshotOfBundlesCollection()
        {
            List<IEnumerable<Bundle>> readOnlyBundleCollections = new List<IEnumerable<Bundle>>();
            bundles.Changed += (sender, args) =>
            {
                readOnlyBundleCollections.Add(args.Bundles);
            };

            var bundle1 = new TestableBundle("~/1");
            var bundle2 = new TestableBundle("~/2");
            using (bundles.GetWriteLock())
            {
                bundles.Add(bundle1);
            }
            using (bundles.GetWriteLock())
            {
                bundles.Add(bundle2);
            }

            readOnlyBundleCollections.First().ShouldNotContain(bundle2);
        }
        public void GivenDiamondReferencing_ThenConcatDependenciesReturnsEachReferencedBundleOnlyOnceInDependencyOrder()
        {
            var bundle1 = new TestableBundle("~/bundle-1");
            var asset1 = new Mock<IAsset>();
            SetupAsset("~/bundle-1/a.js", asset1);
            asset1.SetupGet(a => a.References)
                  .Returns(new[] {
                      new AssetReference(asset1.Object.Path, "~/bundle-2/b.js", 1, AssetReferenceType.DifferentBundle),
                      new AssetReference(asset1.Object.Path, "~/bundle-3/c.js", 1, AssetReferenceType.DifferentBundle)
                  });
            bundle1.Assets.Add(asset1.Object);

            var bundle2 = new TestableBundle("~/bundle-2");
            var asset2 = new Mock<IAsset>();
            SetupAsset("~/bundle-2/b.js", asset2);
            asset2.SetupGet(a => a.References)
                  .Returns(new[] { new AssetReference(asset2.Object.Path, "~/bundle-4/d.js", 1, AssetReferenceType.DifferentBundle) });
            bundle2.Assets.Add(asset2.Object);

            var bundle3 = new TestableBundle("~/bundle-3");
            var asset3 = new Mock<IAsset>();
            SetupAsset("~/bundle-3/c.js", asset3);
            asset3.SetupGet(a => a.References)
                  .Returns(new[] { new AssetReference(asset3.Object.Path, "~/bundle-4/d.js", 1, AssetReferenceType.DifferentBundle) });
            bundle3.Assets.Add(asset3.Object);

            var bundle4 = new TestableBundle("~/bundle-4");
            var asset4 = new Mock<IAsset>();
            SetupAsset("~/bundle-4/d.js", asset4);
            bundle4.Assets.Add(asset4.Object);

            var collection = CreateBundleCollection(new[] { bundle1, bundle2, bundle3, bundle4 });

            collection.BuildReferences();
            collection
                .SortBundles(new[] { bundle1, bundle2, bundle3, bundle4 })
                .SequenceEqual(new[] { bundle4, bundle2, bundle3, bundle1 })
                .ShouldBeTrue();
        }
        public void ChangeEventArgsIsSnapshotOfBundlesCollection()
        {
            List <IEnumerable <Bundle> > readOnlyBundleCollections = new List <IEnumerable <Bundle> >();

            bundles.Changed += (sender, args) =>
            {
                readOnlyBundleCollections.Add(args.Bundles);
            };

            var bundle1 = new TestableBundle("~/1");
            var bundle2 = new TestableBundle("~/2");

            using (bundles.GetWriteLock())
            {
                bundles.Add(bundle1);
            }
            using (bundles.GetWriteLock())
            {
                bundles.Add(bundle2);
            }

            readOnlyBundleCollections.First().ShouldNotContain(bundle2);
        }
Пример #29
0
        public void GivenNoAssets_ThenHashIsZeroLengthArray()
        {
            var bundle = new TestableBundle("~");

            bundle.Hash.Length.ShouldEqual(0);
        }
Пример #30
0
        public void WhenFindAssetByPathNotFound_ThenNullReturned()
        {
            var bundle = new TestableBundle("~/test");

            bundle.FindAssetByPath("~/test/notfound.js").ShouldBeNull();
        }
Пример #31
0
 public void BundlePathIsConvertedToBeApplicationRelative()
 {
     var bundle = new TestableBundle("test");
     bundle.Path.ShouldEqual("~/test");
 }
Пример #32
0
        public void GivenPathIsRoot_ThenPathWithoutPrefixReturnsEmptyString()
        {
            var bundle = new TestableBundle("~");

            bundle.PathWithoutPrefix.ShouldEqual("");
        }
Пример #33
0
        public void ContainsPathOfAssetNotInBundle_ReturnsFalse()
        {
            var bundle = new TestableBundle("~/test");

            bundle.ContainsPath("~\\test\\not-in-bundle.js").ShouldBeFalse();
        }
Пример #34
0
        public void BundlePathIsConvertedToBeApplicationRelative()
        {
            var bundle = new TestableBundle("test");

            bundle.Path.ShouldEqual("~/test");
        }
Пример #35
0
        public void ConstructorDoesNotNormalizeUrls()
        {
            var bundle = new TestableBundle("http://test.com/api.js");

            bundle.Path.ShouldEqual("http://test.com/api.js");
        }
Пример #36
0
        public void GivenNewBundle_ThenEmptyHtmlAttributes()
        {
            var bundle = new TestableBundle("~/test");

            bundle.HtmlAttributes.ShouldBeEmpty();
        }
Пример #37
0
        public void ConstructorNormalizesToForwardSlashes()
        {
            var bundle = new TestableBundle("~/test/foo\\bar");

            bundle.Path.ShouldEqual("~/test/foo/bar");
        }
Пример #38
0
        public void ConstructorNormalizesDirectoryPathByRemovingTrailingForwardSlash()
        {
            var bundle = new TestableBundle("~/test/");

            bundle.Path.ShouldEqual("~/test");
        }
Пример #39
0
 public void UrlIsNotConverted()
 {
     var bundle = new TestableBundle("~/bundle");
     bundle.AddReference("http://test.com/");
     bundle.References.Single().ShouldEqual("http://test.com/");
 }
Пример #40
0
        public void PathWithoutPrefixRemovesTildeSlashFromStart()
        {
            var bundle = new TestableBundle("~/test");

            bundle.PathWithoutPrefix.ShouldEqual("test");
        }
Пример #41
0
        public void AcceptCallsVisitOnVistor()
        {
            var visitor = new Mock<IBundleVisitor>();
            var bundle = new TestableBundle("~/test");

            bundle.Accept(visitor.Object);

            visitor.Verify(v => v.Visit(bundle));
        }
Пример #42
0
        public void ContainsPathOfJustTheBundleItself_ReturnsTrue()
        {
            var bundle = new TestableBundle("~/test");

            bundle.ContainsPath("~/test").ShouldBeTrue();
        }
Пример #43
0
        public void ContainsPathOfJustTheBundleItselfWithDifferentCasing_ReturnsTrue()
        {
            var bundle = new TestableBundle("~/test");

            bundle.ContainsPath("~\\TEST").ShouldBeTrue();
        }
Пример #44
0
        public void ContainsPathOfJustTheBundleItselfWithTrailingSlash_ReturnsTrue()
        {
            var bundle = new TestableBundle("~/test");

            bundle.ContainsPath("~\\test\\").ShouldBeTrue();
        }