Exemplo n.º 1
0
        public void AssetsWithDifferentPathsAreNotEqual()
        {
            var asset1 = new StubAsset("~/test-asset1.js");
            var asset2 = new StubAsset("~/test-asset2.js");

            comparer.Equals(asset1, asset2).ShouldBeFalse();
        }
        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>(), Mock.Of <IBundleCollectionInitializer>());
            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 });
        }
Exemplo n.º 3
0
        public void AssetsWithSamePathAreEqual()
        {
            var asset1 = new StubAsset("~/test-asset.js");
            var asset2 = new StubAsset("~/test-asset.js");

            comparer.Equals(asset1, asset2).ShouldBeTrue();
        }
        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 });
        }
Exemplo n.º 5
0
        public void ContainsRelativePathToAsset_ReturnsTrue()
        {
            var bundle = new TestableBundle("~/test");
            var asset  = new StubAsset("~/test/asset.js");

            bundle.Assets.Add(asset);

            bundle.ContainsPath("asset.js").ShouldBeTrue();
        }
Exemplo n.º 6
0
        public void FindAssetByPathReturnsAssetWithMatchingFilename()
        {
            var bundle = new TestableBundle("~/test");
            var asset  = new StubAsset("~/test/asset.js");

            bundle.Assets.Add(asset);

            bundle.FindAssetByPath("~/test/asset.js").ShouldBeSameAs(asset);
        }
Exemplo n.º 7
0
        public void GivenAssetInSubDirectory_WhenFindAssetByPath_ThenAssetWithMatchingFilenameIsReturned()
        {
            var bundle = new TestableBundle("~/test");
            var asset  = new StubAsset("~/test/sub/asset.js");

            bundle.Assets.Add(asset);

            bundle.FindAssetByPath("~/test/sub/asset.js").ShouldBeSameAs(asset);
        }
Exemplo n.º 8
0
        public void ConstructorAssignsProperties()
        {
            var asset = new StubAsset();
            var reference = new AssetReference(asset.Path, "~/path", 1, AssetReferenceType.DifferentBundle);

            reference.FromAssetPath.ShouldBeSameAs(asset.Path);
            reference.ToPath.ShouldEqual("~/path");
            reference.SourceLineNumber.ShouldEqual(1);
            reference.Type.ShouldEqual(AssetReferenceType.DifferentBundle);
        }
Exemplo n.º 9
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();
 }
Exemplo n.º 10
0
        public void ConstructorAssignsProperties()
        {
            var asset     = new StubAsset();
            var reference = new AssetReference(asset.Path, "~/path", 1, AssetReferenceType.DifferentBundle);

            reference.FromAssetPath.ShouldBeSameAs(asset.Path);
            reference.ToPath.ShouldEqual("~/path");
            reference.SourceLineNumber.ShouldEqual(1);
            reference.Type.ShouldEqual(AssetReferenceType.DifferentBundle);
        }
Exemplo n.º 11
0
        public void GivenBundleWithAssetWithRawFileReference_ThenCanAccessTheRawFilePath()
        {
            var bundle = new TestableBundle("~");
            var asset  = new StubAsset("~/test.css");

            asset.AddRawFileReference("~/test.png");
            bundle.Assets.Add(asset);
            bundles.Add(bundle);

            authorization.CanAccess("~/test.png").ShouldBeTrue();
        }
Exemplo n.º 12
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();
        }
        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()
            );
        }
Exemplo n.º 14
0
        public void GivenAssetWithReferenceToNonexistantFileAndBundleIsFromDescriptorFile_WhenConstructed_ThenAssetReferenceIsIgnored()
        {
            var bundle       = new TestableBundle("~");
            var asset        = new StubAsset();
            var badReference = new AssetReference("~/NOT-FOUND.js", asset, 1, AssetReferenceType.DifferentBundle);

            asset.References.Add(badReference);
            bundle.Assets.Add(asset);

            bundle.IsFromDescriptorFile = true;

            Assert.DoesNotThrow(
                () => new BundleContainer(new[] { bundle })
                );
        }
Exemplo n.º 15
0
        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()
                );
        }
Exemplo n.º 16
0
        public void GivenConcatenatedAsset_WhenFindAssetByPath_ThenSourceAssetsAreSearched()
        {
            var bundle = new TestableBundle("~/test");
            var asset1 = new StubAsset("~/test/asset1.js");
            var asset2 = new StubAsset("~/test/asset2.js");

            // Simulate concatenated asset. We only need the Accept method to visit each child.
            var concatenatedAsset = new Mock <IAsset>();

            concatenatedAsset.Setup(a => a.Accept(It.IsAny <IBundleVisitor>()))
            .Callback <IBundleVisitor>(v =>
            {
                v.Visit(asset1);
                v.Visit(asset2);
            });
            bundle.Assets.Add(concatenatedAsset.Object);

            bundle.FindAssetByPath("~/test/asset2.js").ShouldBeSameAs(asset2);
        }
Exemplo n.º 17
0
        public void GivenConcatenatedAsset_WhenFindAssetByPath_ThenSourceAssetsAreSearched()
        {
            var bundle = new TestableBundle("~/test");
            var asset1 = new StubAsset("~/test/asset1.js");
            var asset2 = new StubAsset("~/test/asset2.js");

            // Simulate concatenated asset. We only need the Accept method to visit each child.
            var concatenatedAsset = new Mock<IAsset>();
            concatenatedAsset.Setup(a => a.Accept(It.IsAny<IBundleVisitor>()))
                .Callback<IBundleVisitor>(v =>
                {
                    v.Visit(asset1);
                    v.Visit(asset2);
                });
            bundle.Assets.Add(concatenatedAsset.Object);

            bundle.FindAssetByPath("~/test/asset2.js").ShouldBeSameAs(asset2);
        }
Exemplo n.º 18
0
        public void GivenAssetInSubDirectory_WhenFindAssetByPath_ThenAssetWithMatchingFilenameIsReturned()
        {
            var bundle = new TestableBundle("~/test");
            var asset = new StubAsset("~/test/sub/asset.js");
            bundle.Assets.Add(asset);

            bundle.FindAssetByPath("~/test/sub/asset.js").ShouldBeSameAs(asset);
        }
Exemplo n.º 19
0
        public void FindAssetByPathReturnsAssetWithMatchingFilename()
        {
            var bundle = new TestableBundle("~/test");
            var asset = new StubAsset("~/test/asset.js");
            bundle.Assets.Add(asset);

            bundle.FindAssetByPath("~/test/asset.js").ShouldBeSameAs(asset);
        }
Exemplo n.º 20
0
        public void ContainsRelativePathToAsset_ReturnsTrue()
        {
            var bundle = new TestableBundle("~/test");
            var asset = new StubAsset("~/test/asset.js");
            bundle.Assets.Add(asset);

            bundle.ContainsPath("asset.js").ShouldBeTrue();
        }
Exemplo n.º 21
0
        public void GivenAssetWithReferenceToNonexistantFileAndBundleIsFromDescriptorFile_WhenConstructed_ThenAssetReferenceIsIgnored()
        {
            var bundle = new TestableBundle("~");
            var asset = new StubAsset();
            var badReference = new AssetReference("~/NOT-FOUND.js", asset, 1, AssetReferenceType.DifferentBundle);
            asset.References.Add(badReference);
            bundle.Assets.Add(asset);

            bundle.IsFromDescriptorFile = true;

            Assert.DoesNotThrow(
                () => new BundleContainer(new[] { bundle })
            );
        }
Exemplo n.º 22
0
 public void AssetsWithSamePathAreEqual()
 {
     var asset1 = new StubAsset("~/test-asset.js");
     var asset2 = new StubAsset("~/test-asset.js");
     comparer.Equals(asset1, asset2).ShouldBeTrue();
 }
Exemplo n.º 23
0
 public void AssetsWithDifferentPathsAreNotEqual()
 {
     var asset1 = new StubAsset("~/test-asset1.js");
     var asset2 = new StubAsset("~/test-asset2.js");
     comparer.Equals(asset1, asset2).ShouldBeFalse();
 }
Exemplo n.º 24
0
        public void GivenBundleWithAssetWithRawFileReference_ThenCanAccessTheRawFilePath()
        {
            var bundle = new TestableBundle("~");
            var asset = new StubAsset("~/test.css");
            asset.AddRawFileReference("~/test.png");
            bundle.Assets.Add(asset);
            bundles.Add(bundle);

            authorization.CanAccess("~/test.png").ShouldBeTrue();
        }