This contains the object information and methods for handling a cdn
Пример #1
0
        /// <summary>
        /// This returns an array of strings from the setting
        /// </summary>
        /// <param name="bundleName">The name of the setting</param>
        /// <param name="prefix">This string is added to the start of each string in the array</param>
        /// <param name="errorHandler">used by CheckBundles to get any errors rather than throwing exception</param>
        /// <returns></returns>
        public IEnumerable <string> GetBundleDebugFiles(string bundleName, string prefix = "~/", Action <string> errorHandler = null)
        {
            if (errorHandler == null)
            {
                errorHandler = s => { throw new InvalidOperationException(s); }
            }
            ;

            var bundle = _settings[bundleName];

            if (bundle == null)
            {
                throw new ArgumentException($"Could not find the setting {bundleName}");
            }
            if (bundle.Type != JTokenType.Array)
            {
                throw new ArgumentException($"The setting [{bundleName}] is not an array");
            }

            var result = new List <string>();
            var i      = 0;

            foreach (var item in bundle)
            {
                switch (item.Type)
                {
                case JTokenType.String:
                    result.Add(item.Value <string>());
                    break;

                case JTokenType.Object:
                    var cdnInfo = new CdnInfo(bundleName, item.Value <JObject>());
                    if (cdnInfo.Development == null)
                    {
                        errorHandler(
                            $"The CDN bundle {bundleName}, array element {i}, is missing a property called '{CdnInfo.CdnObjectDevelopmentPropertyName}'.");
                    }
                    else
                    {
                        result.Add(cdnInfo.Development);
                    }
                    break;

                default:
                    errorHandler($"The CDN bundle {bundleName}, array element {i}, contained an invalid type {item.Type}");
                    break;
                }
                i++;
            }

            return(string.IsNullOrEmpty(prefix) ? result : result.Select(x => prefix + x));
        }
Пример #2
0
        public void TestFormCdnInfoOk()
        {
            //SETUP
            var jObject = JObject.Parse(@"{
              ""development"": ""lib/jquery/dist/jquery.js"",
              ""production"": ""jquery.min.js"",
              ""cdnUrl"": ""https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"",
              ""cdnSuccessTest"": ""window.jQuery""
            }");

            //ATTEMPT
            var cdn = new CdnInfo("Unit Test", jObject);

            //VERIFY
            cdn.Development.ShouldEqual("lib/jquery/dist/jquery.js");
            cdn.Production.ShouldEqual("jquery.min.js");
        }
Пример #3
0
        public void TestBuildCdnIncludeOk()
        {
            //SETUP
            var jObject = JObject.Parse(@"{
              ""development"": ""lib/jquery/dist/jquery.js"",
              ""production"": ""jquery.min.js"",
              ""cdnUrl"": ""https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"",
              ""cdnSuccessTest"": ""window.jQuery""
            }");
            var cdn = new CdnInfo("Unit Test", jObject);

            //ATTEMPT
            var html =
                cdn.BuildCdnIncludeString( JsCdnHtmlInclude, "http:localhost:1234/js/jquery.min.js", () => "123");

            //VERIFY
            html.ShouldEqual("<script src='https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js'></script><script>window.jQuery||document.write(\"\\x3Cscript src='http:localhost:1234/js/jquery.min.js?v=123'>\\x3C/script>\")</script>");
        }
Пример #4
0
        public void TestValidateCdnInfoOk()
        {
            //SETUP
            var jObject = JObject.Parse(@"{
              ""development"": ""lib/jquery/dist/jquery.js"",
              ""production"": ""jquery.min.js"",
              ""cdnUrl"": ""https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"",
              ""cdnSuccessTest"": ""window.jQuery""
            }");
            var cdn = new CdnInfo("Unit Test", jObject);

            //ATTEMPT
            var missingParams = cdn.FindMissingPropertiesNeededByHtmlInclude(JsCdnHtmlInclude);

            //VERIFY
            missingParams.Any().ShouldEqual(false);
        }
Пример #5
0
        public void TestValidateCdnInfoMissingCdnSuccessTest()
        {
            //SETUP
            var jObject = JObject.Parse(@"{
              ""development"": ""lib/jquery/dist/jquery.js"",
              ""production"": ""jquery.min.js"",
              ""cdnUrl"": ""https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js""
            }");
            var cdn = new CdnInfo("Unit Test", jObject);

            //ATTEMPT
            var missingParams = cdn.FindMissingPropertiesNeededByHtmlInclude(JsCdnHtmlInclude);

            //VERIFY
            CollectionAssert.AreEquivalent(new string[] { "cdnSuccessTest" }, missingParams);
        }