public void OverrideOutputPathForSameId()
        {
            var bundleA = new RequireBundle()
            {
                Name       = "bundleA",
                OutputPath = "bundleA"
            };
            var secondBundleA = new RequireBundle
            {
                Name       = "bundleA",
                OutputPath = "bundleAgain"
            };

            var firstConfig  = ConfigurationCreators.CreateCollectionWithBundles(bundleA);
            var secondConfig = ConfigurationCreators.CreateCollectionWithBundles(secondBundleA);

            var merger = ConfigurationCreators.CreateBundleProcessingConfigMerger(firstConfig, secondConfig);
            var merged = merger.GetMerged();

            var expected = ConfigurationCreators.CreateEmptyCollection();

            expected.Bundles.BundleEntries = new List <RequireBundle>
            {
                new RequireBundle
                {
                    Name           = "bundleA",
                    ParsedIncludes = true,
                    OutputPath     = "bundleAgain"
                }
            };

            CustomAssert.JsonEquals(expected, merged);
        }
        public void SetVirtualToFalseForResultingBundleIfAnyHasFalse()
        {
            var bundleA = new RequireBundle()
            {
                Name      = "bundleA",
                IsVirtual = true
            };
            var secondBundleA = new RequireBundle
            {
                Name      = "bundleA",
                IsVirtual = false
            };

            var firstConfig  = ConfigurationCreators.CreateCollectionWithBundles(bundleA);
            var secondConfig = ConfigurationCreators.CreateCollectionWithBundles(secondBundleA);

            var merger = ConfigurationCreators.CreateBundleProcessingConfigMerger(firstConfig, secondConfig);
            var merged = merger.GetMerged();

            var expected = ConfigurationCreators.CreateEmptyCollection();

            expected.Bundles.BundleEntries = new List <RequireBundle>
            {
                new RequireBundle
                {
                    Name           = "bundleA",
                    ParsedIncludes = true,
                    IsVirtual      = false
                }
            };

            CustomAssert.JsonEquals(expected, merged);
        }
        public void NodeIdCompat()
        {
            var config = ReadJson(new TestFileReader());

            var expected = ConfigurationCreators.CreateEmptyCollection();

            expected.NodeIdCompat = true;

            CustomAssert.JsonEquals(expected, config);
        }
        public void UnifyBundleItemsForSameId()
        {
            var bundleA = new RequireBundle
            {
                Name        = "bundleA",
                BundleItems = new List <BundleItem> {
                    new BundleItem {
                        ModuleName = "jquery"
                    }
                }
            };
            var bundleB = new RequireBundle()
            {
                Name        = "bundleA",
                BundleItems = new List <BundleItem> {
                    new BundleItem {
                        ModuleName = "amplify"
                    }
                }
            };

            var firstConfig  = ConfigurationCreators.CreateCollectionWithBundles(bundleA);
            var secondConfig = ConfigurationCreators.CreateCollectionWithBundles(bundleB);

            var merger = ConfigurationCreators.CreateBundleProcessingConfigMerger(firstConfig, secondConfig);
            var merged = merger.GetMerged();

            var expected = ConfigurationCreators.CreateEmptyCollection();

            expected.Bundles.BundleEntries = new List <RequireBundle>
            {
                new RequireBundle
                {
                    Name           = "bundleA",
                    ParsedIncludes = true,
                    BundleItems    = new List <BundleItem>
                    {
                        new BundleItem {
                            ModuleName = "jquery", RelativePath = "jquery"
                        },
                        new BundleItem {
                            ModuleName = "amplify", RelativePath = "amplify"
                        }
                    }
                }
            };

            CustomAssert.JsonEquals(expected, merged);
        }
        public void CreateSingleAutoBundleListForDifferentBundleIds()
        {
            var firstBundle = new AutoBundle
            {
                Id         = "bundleA",
                OutputPath = @"\Scripts\bundleA.js",
                Includes   = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                },
                Excludes = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                }
            };
            var secondBundle = new AutoBundle
            {
                Id         = "bundleB",
                OutputPath = @"\Scripts\bundleB.js",
                Includes   = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                },
                Excludes = new List <AutoBundleItem> {
                    new AutoBundleItem {
                        File = "jquery"
                    }
                }
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithAutoBundles(firstBundle);
            var secondCollection = ConfigurationCreators.CreateCollectionWithAutoBundles(secondBundle);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedCollection = ConfigurationCreators.CreateEmptyCollection();

            expectedCollection.AutoBundles.Bundles = new List <AutoBundle>
            {
                firstBundle,
                secondBundle
            };

            CustomAssert.JsonEquals(expectedCollection, merged);
        }
        public void UniteMapElementsForSingleScript()
        {
            var firstMap = new RequireMapElement
            {
                For          = "scriptA",
                Replacements = new List <RequireReplacement>
                {
                    new RequireReplacement {
                        OldKey = "jquery", NewKey = "jquery.min"
                    }
                }
            };

            var secondMap = new RequireMapElement
            {
                For          = "scriptA",
                Replacements = new List <RequireReplacement>
                {
                    new RequireReplacement {
                        OldKey = "amplify", NewKey = "amplify.min"
                    }
                }
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithMaps(firstMap);
            var secondCollection = ConfigurationCreators.CreateCollectionWithMaps(secondMap);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedCollection = ConfigurationCreators.CreateEmptyCollection();

            expectedCollection.Map.MapElements.Add(new RequireMapElement
            {
                For          = "scriptA",
                Replacements = new List <RequireReplacement>
                {
                    new RequireReplacement {
                        OldKey = "jquery", NewKey = "jquery.min"
                    },
                    new RequireReplacement {
                        OldKey = "amplify", NewKey = "amplify.min"
                    }
                }
            });

            CustomAssert.JsonEquals(expectedCollection, merged);
        }
        public void ReplacePackagesWithSameName()
        {
            var packageA1 = new RequirePackage("a", "main");
            var packageA2 = new RequirePackage("a", "start", "/somewhere");

            var firstConfig  = ConfigurationCreators.CreateCollectionWithPackages(packageA1);
            var secondConfig = ConfigurationCreators.CreateCollectionWithPackages(packageA2);

            var merger = ConfigurationCreators.CreateBundleProcessingConfigMerger(firstConfig, secondConfig);
            var merged = merger.GetMerged();

            var expected = ConfigurationCreators.CreateEmptyCollection();

            expected.Packages.PackageList = new List <RequirePackage>
            {
                new RequirePackage("a", "start", "/somewhere")
            };

            CustomAssert.JsonEquals(expected, merged);
        }
        public void OverrideOutputPathForAutoBundleWithSameId()
        {
            var firstBundle = new AutoBundle
            {
                Id         = "bundleA",
                OutputPath = @"\Scripts\bundleA.js",
                Includes   = new List <AutoBundleItem>(),
                Excludes   = new List <AutoBundleItem>()
            };

            var secondBundle = new AutoBundle
            {
                Id         = "bundleA",
                OutputPath = @"\Scripts\bundleB.js",
                Includes   = new List <AutoBundleItem>(),
                Excludes   = new List <AutoBundleItem>()
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithAutoBundles(firstBundle);
            var secondCollection = ConfigurationCreators.CreateCollectionWithAutoBundles(secondBundle);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedCollection = ConfigurationCreators.CreateEmptyCollection();

            expectedCollection.AutoBundles.Bundles = new List <AutoBundle>
            {
                new AutoBundle
                {
                    Id         = "bundleA",
                    OutputPath = @"\Scripts\bundleB.js",
                    Includes   = new List <AutoBundleItem>(),
                    Excludes   = new List <AutoBundleItem>()
                }
            };

            CustomAssert.JsonEquals(expectedCollection, merged);
        }
        public void CreateSingleMapListForDifferentScripts()
        {
            var scriptAMap = new RequireMapElement
            {
                For          = "scriptA",
                Replacements = new List <RequireReplacement>
                {
                    new RequireReplacement {
                        OldKey = "jquery", NewKey = "jquery.min"
                    }
                }
            };

            var scriptBMap = new RequireMapElement
            {
                For          = "scriptB",
                Replacements = new List <RequireReplacement>
                {
                    new RequireReplacement {
                        OldKey = "jquery", NewKey = "jquery.custom"
                    }
                }
            };


            var firstCollection  = ConfigurationCreators.CreateCollectionWithMaps(scriptAMap);
            var secondCollection = ConfigurationCreators.CreateCollectionWithMaps(scriptBMap);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedCollection = ConfigurationCreators.CreateEmptyCollection();

            expectedCollection.Map.MapElements.Add(scriptAMap);
            expectedCollection.Map.MapElements.Add(scriptBMap);

            CustomAssert.JsonEquals(expectedCollection, merged);
        }