public HtmlElementBuilder(string tagName, 
     object attributes, string content)
 {
     Precondition.Defined(tagName, () => Error.ArgumentNull("tagName"));
     _name = tagName;
     _attributes = new HtmlAttributeDictionary(attributes);
     _content = content;
 }
Пример #2
0
        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");
        }
Пример #3
0
        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");
        }
Пример #4
0
        public void WithNullName_ThenArgumentException()
        {
            var target = new HtmlAttributeDictionary();

            Assert.Throws<ArgumentException>(
                () => target.Add(null, "async")
            );
        }
Пример #5
0
        public void WithDictionaryWithOneEntityAndObjectWithTwoProperties_ThenThreeKeyValuePairs()
        {
            var target = new HtmlAttributeDictionary();
            target.Add("existing", "value");

            target.Add(new { @class = "TestClass", async = "async" });

            target.Count.ShouldEqual(3);
        }
Пример #6
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);
        }
Пример #7
0
 public void WhenRemoveAttributeWithNullName_ThenThrowException()
 {
     var target = new HtmlAttributeDictionary();
     Assert.Throws<ArgumentException>(
         () => target.Remove(null)
     );
 }
Пример #8
0
 public void GivenDictionaryWithAttribute_WhenRemoveAttributeWithDifferentName_ThenReturnFalse()
 {
     var target = new HtmlAttributeDictionary { "test" };
     var removed = target.Remove("something-else");
     removed.ShouldBeFalse();
 }
Пример #9
0
 public void GivenDictionaryWithAttribute_WhenRemoveAttributeByName_ThenReturnTrue()
 {
     var target = new HtmlAttributeDictionary { "test" };
     var removed = target.Remove("test");
     removed.ShouldBeTrue();
 }
Пример #10
0
 public void WhenSetAttributeWithNullName_ThenThrowException()
 {
     var target = new HtmlAttributeDictionary();
     Assert.Throws<ArgumentException>(
         () => target[null] = "value"
     );
 }
Пример #11
0
        public void WithObjectWithTwoProperties_ThenDictionaryTwoKeyValuePairs()
        {
            var target = new HtmlAttributeDictionary().Add(new { @class = "TestClass", async = "async" });

            target.Count.ShouldEqual(2);
            target["class"].ShouldEqual("TestClass");
            target["async"].ShouldEqual("async");
        }
Пример #12
0
 public void GivenEmptyDictionary_ThenContainsAttributeIsFalse()
 {
     var target = new HtmlAttributeDictionary();
     target.ContainsAttribute("example").ShouldBeFalse();
 }
Пример #13
0
 public void GivenAttributeInDictionary_ThenContainsAttributeIsTrue()
 {
     var target = new HtmlAttributeDictionary { "example" };
     target.ContainsAttribute("example").ShouldBeTrue();
 }
Пример #14
0
        public void WhenAttributes_ThenContainsValidString()
        {
            var dictionary = new HtmlAttributeDictionary().Add(new { @class = "test", foo = "\"bar\"" } );
            dictionary.Add("async");

            dictionary.CombinedAttributes.ShouldEqual(" class=\"test\" foo=\"&quot;bar&quot;\" async");
        }
 public void Setup()
 {
     dictionary = new HtmlAttributeDictionary();
 }
Пример #16
0
 public void WhenAttributeNameIsNull_ThenContainsAttributesThrowsException()
 {
     var target = new HtmlAttributeDictionary();
     Assert.Throws<ArgumentException>(
         () => target.ContainsAttribute(null)
     );
 }
Пример #17
0
        public void CanSetAndGetValueByName()
        {
            var target = new HtmlAttributeDictionary();

            target["test"] = "value";

            target["test"].ShouldEqual("value");
        }
Пример #18
0
        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");
        }
Пример #19
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>
 public static void MergeAttributesAppendClasses(this TagBuilder tagBuilder, HtmlAttributeDictionary attributes)
 {
     MergeAttributesAppendClasses(tagBuilder, attributes, false);
 }