示例#1
0
        public void GivenTwoAssetsWhereADependsOnBByDifferentlyCasedFilename_WhenSorted_ThenBIsBeforeAInBundle()
        {
            var bundle = new TestableBundle("~/test");
            var assetA = new Mock <IAsset>();

            assetA.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/a.js");
            assetA.SetupGet(a => a.References)
            .Returns(new[] { new AssetReference("~/TEST/B.js", assetA.Object, 1, AssetReferenceType.SameBundle) });
            var assetB = new Mock <IAsset>();

            assetB.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/b.js");
            bundle.Assets.Add(assetA.Object);
            bundle.Assets.Add(assetB.Object);

            var sorter = new SortAssetsByDependency();

            sorter.Process(bundle, new CassetteSettings());

            bundle.Assets[0].ShouldBeSameAs(assetB.Object);
            bundle.Assets[1].ShouldBeSameAs(assetA.Object);
        }
示例#2
0
        public void GivenTwoAssetsWhereADependsOnB_WhenSorted_ThenBIsBeforeAInBundle()
        {
            var bundle = new TestableBundle("~/test");
            var assetA = new Mock <IAsset>();

            assetA.SetupGet(a => a.Path).Returns("~/test/a.js");
            assetA.SetupGet(a => a.References)
            .Returns(new[] { new AssetReference(assetA.Object.Path, "~/test/b.js", 1, AssetReferenceType.SameBundle) });
            var assetB = new Mock <IAsset>();

            assetB.SetupGet(a => a.Path).Returns("~/test/b.js");
            bundle.Assets.Add(assetA.Object);
            bundle.Assets.Add(assetB.Object);

            var sorter = new SortAssetsByDependency();

            sorter.Process(bundle);

            bundle.Assets[0].ShouldBeSameAs(assetB.Object);
            bundle.Assets[1].ShouldBeSameAs(assetA.Object);
        }
示例#3
0
        public void WhenBundleHasSortedAssets_ThenProcessDoesNotReorderAssets()
        {
            var bundle = new TestableBundle("~/test");
            var assetA = new Mock <IAsset>();

            assetA.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/a.js");
            assetA.SetupGet(a => a.References)
            .Returns(new[] { new AssetReference("~/TEST/B.js", assetA.Object, 1, AssetReferenceType.SameBundle) });
            var assetB = new Mock <IAsset>();

            assetB.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/b.js");
            bundle.Assets.Add(assetA.Object);
            bundle.Assets.Add(assetB.Object);
            bundle.IsSorted = true;

            var sorter = new SortAssetsByDependency();

            sorter.Process(bundle, new CassetteSettings());

            bundle.Assets[0].ShouldBeSameAs(assetA.Object);
            bundle.Assets[1].ShouldBeSameAs(assetB.Object);
        }
示例#4
0
        public void GivenAssetWithCircularReferences_WhenProcess_ThenExceptionThrown()
        {
            var bundle = new TestableBundle("~/test");
            var assetA = new Mock <IAsset>();

            assetA.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/a.js");
            assetA.SetupGet(a => a.References)
            .Returns(new[] { new AssetReference("~/test/b.js", assetA.Object, 1, AssetReferenceType.SameBundle) });
            var assetB = new Mock <IAsset>();

            assetB.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/b.js");
            assetB.SetupGet(a => a.References)
            .Returns(new[] { new AssetReference("~/test/a.js", assetB.Object, 1, AssetReferenceType.SameBundle) });

            bundle.Assets.Add(assetA.Object);
            bundle.Assets.Add(assetB.Object);

            var sorter = new SortAssetsByDependency();

            Assert.Throws <InvalidOperationException>(
                () => sorter.Process(bundle, new CassetteSettings())
                );
        }