public void UniteShimsWithDifferentKeys()
        {
            var jqueryShim = new ShimEntry
                                 {
                                     For = "jquery",
                                     Dependencies = new List<RequireDependency>
                                                        {
                                                            new RequireDependency { Dependency = "depA" },
                                                            new RequireDependency { Dependency = "depB" }
                                                        }
                                 };

            var amplifyShim = new ShimEntry
                                  {
                                      For = "amplify",
                                      Dependencies = new List<RequireDependency>
                                                         {
                                                             new RequireDependency { Dependency = "depC" },
                                                             new RequireDependency { Dependency = "depD" }
                                                         }
                                  };

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

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

            var expected = ConfigurationCreators.CreateCollectionWithShims(jqueryShim, amplifyShim);

            CustomAssert.JsonEquals(expected, merged);
        }
        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);
        }
Example #3
0
        private RequireShim GetShim(JObject document)
        {
            var shim = new RequireShim();
            shim.ShimEntries = new List<ShimEntry>();
            if (document != null && document["shim"] != null)
            {
                shim.ShimEntries = document["shim"].Select(
                    r =>
                        {
                            var result = new ShimEntry();
                            var prop = (JProperty)r;
                            result.For = prop.Name;
                            var shimObj = (JObject)prop.Value;
                            result.Exports = shimObj["exports"] != null ? shimObj["exports"].ToString() : null;
                            var depArr = (JArray)shimObj["deps"];
                            result.Dependencies = new List<RequireDependency>();
                            if (depArr != null)
                            {
                                result.Dependencies = depArr.Select(dep => new RequireDependency
                                                                               {
                                                                                   Dependency = dep.ToString()
                                                                               })
                                                            .ToList();
                            }

                            return result;
                        })
                        .ToList();                
            }

            return shim;
        }
        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);
        }