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 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);
        }
        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 ReadBundleWithSpecifiedVirtual()
        {
            var config = ReadJson(new TestFileReader());
            var bundle = new RequireBundle {
                Name = "jqueryBundle", IsVirtual = true
            };
            var expected = ConfigurationCreators.CreateCollectionWithBundles(bundle);

            CustomAssert.JsonEquals(expected, config);
        }
        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);
        }
        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 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);
        }
        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);
        }
        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);
        }
Esempio n. 10
0
        private RequireBundles GetBundles(JObject document)
        {
            var bundles = new RequireBundles();

            bundles.BundleEntries = new List <RequireBundle>();
            if (document != null && document["bundles"] != null)
            {
                bundles.BundleEntries = document["bundles"].Select(
                    r =>
                {
                    var bundle  = new RequireBundle();
                    var prop    = (JProperty)r;
                    bundle.Name = prop.Name;
                    if (prop.Value is JArray)
                    {
                        bundle.IsVirtual   = false;
                        var arr            = prop.Value as JArray;
                        bundle.BundleItems = arr.Select(x => new BundleItem {
                            ModuleName = x.ToString()
                        }).ToList();
                    }
                    else if (prop.Value is JObject)
                    {
                        var obj           = prop.Value as JObject;
                        bundle.OutputPath = obj["outputPath"] != null ? obj["outputPath"].ToString() : null;
                        var inclArr       = obj["includes"] as JArray;
                        if (inclArr != null)
                        {
                            bundle.Includes = inclArr.Select(x => x.ToString()).ToList();
                        }

                        var itemsArr = obj["items"] as JArray;
                        if (itemsArr != null)
                        {
                            bundle.BundleItems = itemsArr.Select(
                                x =>
                            {
                                var result = new BundleItem();
                                if (x is JObject)
                                {
                                    result.ModuleName      = x["path"] != null ? x["path"].ToString() : null;
                                    result.CompressionType = x["compression"] != null ? x["compression"].ToString() : null;
                                }
                                else if (x is JValue && x.Type == JTokenType.String)
                                {
                                    result.ModuleName = x.ToString();
                                }

                                return(result);
                            }).ToList();
                        }

                        var isVirtual    = obj["virtual"];
                        bundle.IsVirtual = isVirtual is JValue &&
                                           isVirtual.Type == JTokenType.Boolean &&
                                           (bool)((JValue)isVirtual).Value;
                    }

                    return(bundle);
                })
                                        .ToList();
            }

            return(bundles);
        }
Esempio n. 11
0
        private RequireBundles GetBundles(JObject document)
        {
            var bundles = new RequireBundles();

            bundles.BundleEntries = new List <RequireBundle>();
            string parseSection = "bundles";

            if (document != null && document[parseSection] != null)
            {
                JToken bundlesParent = JsonParseOrThrow <JObject>(document[parseSection], parseSection, Path, null);
                bundles.BundleEntries = bundlesParent.Select(
                    r =>
                {
                    var bundle              = new RequireBundle();
                    var prop                = (JProperty)r;
                    bundle.Name             = prop.Name;
                    string parseSectionHint = $"{parseSection}.{prop.Name}";
                    if (prop.Value is JArray)
                    {
                        bundle.IsVirtual   = false;
                        JArray arr         = JsonParseOrThrow <JArray>(prop.Value, parseSectionHint, Path, null);
                        bundle.BundleItems = arr.Select(x => new BundleItem {
                            ModuleName = x.ToString()
                        }).ToList();
                    }
                    else if (prop.Value is JObject)
                    {
                        var obj           = prop.Value as JObject;
                        bundle.OutputPath = JsonParseStringOrThrow(obj, "outputPath", parseSectionHint, Path);
                        JArray inclArr    = JsonParseArrayOrThrow(obj, "includes", parseSectionHint, Path);
                        if (inclArr != null)
                        {
                            bundle.Includes = inclArr.Select(x => x.ToString()).ToList();
                        }

                        JArray itemsArr = JsonParseArrayOrThrow(obj, "items", parseSectionHint, Path);
                        if (itemsArr != null)
                        {
                            string parseSectionHint2 = $"{parseSectionHint}.items";
                            bundle.BundleItems       = itemsArr.Select(
                                x =>
                            {
                                var result = new BundleItem();
                                if (x is JObject)
                                {
                                    result.ModuleName      = JsonParseStringOrThrow(x as JObject, "path", parseSectionHint2, Path);
                                    result.CompressionType = JsonParseStringOrThrow(x as JObject, "compression", parseSectionHint2, Path);
                                }
                                else if (x is JValue && x.Type == JTokenType.String)
                                {
                                    result.ModuleName = x.ToString();
                                }

                                return(result);
                            }).ToList();
                        }

                        var isVirtual = obj["virtual"];
                        if (isVirtual != null && !(isVirtual is JValue))
                        {
                            throw new JsonReaderException($"Element 'virtual' in {parseSectionHint} is expected to be 'JValue'; found instead: '{isVirtual.GetType()}'. Value: {isVirtual}");
                        }
                        bundle.IsVirtual = isVirtual is JValue &&
                                           isVirtual.Type == JTokenType.Boolean &&
                                           (bool)((JValue)isVirtual).Value;
                    }

                    return(bundle);
                })
                                        .ToList();
            }

            return(bundles);
        }