public void AddNameValuePair_WithUnderscorePropertyName_ThenRemainsUnderscoreName()
        {
            var target = new HtmlAttributeDictionary();

            target.Add("data_value", "test");

            target.Where(k => k.Key == "data_value").Select(k => k.Key).FirstOrDefault().ShouldEqual("data_value");
        }
        public void AddObject_WithUnderscorePropertyName_ThenDashPropertyName()
        {
            var target = new HtmlAttributeDictionary();

            target.Add(new { data_value = "test" });

            target.Where(k => k.Key == "data-value").Select(k => k.Key).FirstOrDefault().ShouldEqual("data-value");
        }
Exemple #3
0
        /// <summary>
        /// Extends Merge Attributes to also intelligently handle clashing class attributes
        /// </summary>
        /// <param name="tagBuilder">The tag builder.</param>
        /// <param name="attributes">The attributes.</param>
        /// <param name="replaceExisting">if set to <c>true</c> [replace existing].</param>
        public static void MergeAttributesAppendClasses(this TagBuilder tagBuilder, HtmlAttributeDictionary attributes, bool replaceExisting)
        {
            var attributesWithoutClass = attributes.Where(kvp => kvp.Key.ToString() != "class").ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            if (attributes.ContainsKey("class"))
            {
                tagBuilder.AddCssClass(attributes["class"].ToString());
            }

            tagBuilder.MergeAttributes(attributesWithoutClass, replaceExisting);
        }
        public void WithUpperPropertyName_ThenLowerName()
        {
            var target = new HtmlAttributeDictionary();

            target.Add(new { ASYNC = "async" });

            target.Where(k => k.Key == "async").Select(k => k.Key).FirstOrDefault().ShouldEqual("async");
        }