コード例 #1
0
        public void ReadAutoBundles()
        {
            var config     = ReadJson(new TestFileReader());
            var autoBundle = new AutoBundle
            {
                Id         = "full",
                OutputPath = @"bundles\auto\",
                Includes   =
                    new List <AutoBundleItem>
                {
                    new AutoBundleItem
                    {
                        Directory = @"\controllers\Root\",
                    },
                    new AutoBundleItem
                    {
                        File = "jquery-1.10.2"
                    }
                },
                Excludes         = new List <AutoBundleItem>(),
                ContainingConfig = "JsonReaderShould.ReadAutoBundles.json"
            };
            var expected = ConfigurationCreators.CreateCollectionWithAutoBundles(autoBundle);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #2
0
        public void ReadBundleWithExpandedItems()
        {
            var config = ReadJson(new TestFileReader());
            var bundle = new RequireBundle
            {
                Name        = "full",
                BundleItems =
                    new List <BundleItem>
                {
                    new BundleItem
                    {
                        ModuleName      = "bootstrap",
                        CompressionType = "none"
                    },
                    new BundleItem
                    {
                        ModuleName      = "amplify",
                        CompressionType = "standard"
                    }
                }
            };
            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundle);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public void MergeShimsWithSameKey()
        {
            var jqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "depA"
                    },
                    new RequireDependency {
                        Dependency = "depB"
                    }
                }
            };

            var altJqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "depB"
                    },
                    new RequireDependency {
                        Dependency = "depD"
                    }
                }
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithShims(jqueryShim);
            var secondCollection = ConfigurationCreators.CreateCollectionWithShims(altJqueryShim);

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

            var expectedShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "depA"
                    },
                    new RequireDependency {
                        Dependency = "depB"
                    },
                    new RequireDependency {
                        Dependency = "depD"
                    }
                }
            };

            var expected = ConfigurationCreators.CreateCollectionWithShims(expectedShim);

            CustomAssert.JsonEquals(expected, merged);
        }
コード例 #6
0
        public void ReadBundleWithOutputPath()
        {
            var config = ReadJson(new TestFileReader());
            var bundle = new RequireBundle {
                Name = "jqueryBundle", OutputPath = @"Bundles\full.min.js"
            };
            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundle);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #7
0
        public void ReadBundleWithSpecifiedVirtual()
        {
            var config = ReadJson(new TestFileReader());
            var bundle = new RequireBundle {
                Name = "jqueryBundle", IsVirtual = true
            };
            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundle);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #8
0
        public void NodeIdCompat()
        {
            var config = ReadJson(new TestFileReader());

            var expected = ConfigurationCreators.CreateEmptyCollection();

            expected.NodeIdCompat = true;

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #9
0
        public void ReadPathArray()
        {
            var config = ReadJson(new TestFileReader());

            var expected = ConfigurationCreators.CreateCollectionWithPaths(
                new RequirePath("jquery", "jquery-1.10.2", "jquery.min")
                );

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #10
0
        public void ReadCompactedPath()
        {
            var config = ReadJson(new TestFileReader());

            var expected = ConfigurationCreators.CreateCollectionWithPaths(new RequirePath
            {
                Key   = "jquery",
                Value = "jquery-1.10.2"
            });

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #11
0
        public void ReadExpandedPath()
        {
            var config = ReadJson(new TestFileReader());

            var expected = ConfigurationCreators.CreateCollectionWithPaths(
                new RequirePath("jquery-validate", "jquery.validate")
            {
                DefaultBundle = "jqValidate"
            }
                );

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #12
0
        public void SerializesPackagesInRequireJSFormat()
        {
            var expected = "var require = {\"baseUrl\":\"\",\"locale\":\"en\",\"urlArgs\":null,\"waitSeconds\":7,\"paths\":{},\"packages\":[{\"name\":\"cart\",\"main\":\"main\"},{\"name\":\"store\",\"main\":\"store\"}],\"shim\":{},\"map\":{}};";

            var config     = new RequireRendererConfiguration();
            var collection = ConfigurationCreators.CreateCollectionWithPackages(
                new RequirePackage("cart", "main"),
                new RequirePackage("store", "store")
                );
            var outputConfig = RequireJsHtmlHelpers.createOutputConfigFrom(collection, config, "en");
            var actual       = Helpers.JavaScriptHelpers.SerializeAsVariable(outputConfig, "require");

            Assert.Equal(expected, actual);
        }
コード例 #13
0
        public void ReadPackagesArray()
        {
            var expectedPackages = new[]
            {
                new RequirePackage("cart", "main"),
                new RequirePackage("store", "store")
            };
            var expectedCollection = ConfigurationCreators.CreateCollectionWithPackages(expectedPackages);

            var config = ReadJson(new TestFileReader());

            Assert.Equal(2, config.Packages.PackageList.Count);
            CustomAssert.JsonEquals(expectedCollection, config);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public void UnitePathsWhenKeysAreDifferent()
        {
            var jqueryPath  = new RequirePath("jquery", "jquery-1.06.2");
            var amplifyPath = new RequirePath("amplify", "amplify-10.3.5");

            var firstCollection  = ConfigurationCreators.CreateCollectionWithPaths(jqueryPath);
            var secondCollection = ConfigurationCreators.CreateCollectionWithPaths(amplifyPath);

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

            var expected = ConfigurationCreators.CreateCollectionWithPaths(jqueryPath, amplifyPath);

            CustomAssert.JsonEquals(expected, merged);
        }
コード例 #17
0
        public void OverridePathsWithSameKey()
        {
            var jqueryPath    = new RequirePath("jquery", "jquery-1.06.2");
            var altJqueryPath = new RequirePath("jquery", "jquery-1.05.3");

            var firstCollection  = ConfigurationCreators.CreateCollectionWithPaths(jqueryPath);
            var secondCollection = ConfigurationCreators.CreateCollectionWithPaths(altJqueryPath);

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

            var expected = ConfigurationCreators.CreateCollectionWithPaths(altJqueryPath);

            CustomAssert.JsonEquals(expected, merged);
        }
コード例 #18
0
        public void ReadBundleWithIncludes()
        {
            var config = ReadJson(new TestFileReader());
            var bundle = new RequireBundle
            {
                Name     = "full",
                Includes = new List <string>
                {
                    "jqueryBundle", "jqvalUnobtrusive", "jqValidate"
                }
            };
            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundle);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        public void ReadShimWithExports()
        {
            var config = ReadJson(new TestFileReader());
            var shim   = new ShimEntry
            {
                For          = "jquery-validate",
                Dependencies =
                    new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "jquery"
                    }
                },
                Exports = "jqVal"
            };
            var expected = ConfigurationCreators.CreateCollectionWithShims(shim);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #21
0
        public void ReadBundleWithCompactedItems()
        {
            var config = ReadJson(new TestFileReader());
            var bundle = new RequireBundle
            {
                Name        = "jqueryBundle",
                BundleItems =
                    new List <BundleItem>
                {
                    new BundleItem
                    {
                        ModuleName = "jquery"
                    }
                }
            };
            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundle);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        public void ReadMap()
        {
            var config = ReadJson(new TestFileReader());
            var map    = new RequireMapElement
            {
                For          = "controllers/root/home/complexLoad",
                Replacements =
                    new List <RequireReplacement>
                {
                    new RequireReplacement
                    {
                        OldKey = "req1",
                        NewKey = "req2"
                    }
                }
            };
            var expected = ConfigurationCreators.CreateCollectionWithMaps(map);

            CustomAssert.JsonEquals(expected, config);
        }
コード例 #24
0
        public void CreateSingleBundleListForDifferentIds()
        {
            var bundleA = new RequireBundle
            {
                Name = "bundleA",
            };
            var bundleB = new RequireBundle()
            {
                Name = "bundleB",
            };

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

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

            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundleA, bundleB);

            CustomAssert.JsonEquals(expected, merged);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        public void OverrideExportsValueForShimsWithSameKey()
        {
            var jqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>(),
                Exports      = "jqu"
            };

            var altJqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>(),
                Exports      = "jlo"
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithShims(jqueryShim);
            var secondCollection = ConfigurationCreators.CreateCollectionWithShims(altJqueryShim);

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

            Assert.Equal("jlo", merged.Shim.ShimEntries.FirstOrDefault().Exports);
        }