コード例 #1
0
        public void TestGetCssElement()
        {
            HElement element = null;
            var      style   = element.Css();

            Assert.Equal(0, style.Count);

            element = new HElement("div");

            style = element.Css();
            Assert.Equal(0, style.Count);

            element.Attr("id", "test").Attr("style", "");
            style = element.Css();
            Assert.Equal(0, style.Count);

            element.Attr("style", "font-size=12px;color=blue;");
            style = element.Css();
            Assert.Equal(2, style.Count);
            Assert.Equal("12px", style["font-size"]);
            Assert.Equal("blue", style["color"]);

            element.Attr("style", "font-size=12px;other=;empty;color=blue");
            style = element.Css();
            Assert.Equal(4, style.Count);
            Assert.Equal("12px", style["font-size"]);
            Assert.Equal("blue", style["color"]);
            Assert.Equal("", style["other"]);
            Assert.Equal("", style["empty"]);
        }
コード例 #2
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestPrependElementsByCallback()
        {
            var element1 = new HElement("div", new HElement("p"));
            var element2 = new HElement("div", new HElement("p"), new HElement("div"), new HAttribute("attr1", "val1"));

            var elements = new HElement[] { element1, null, element2 };

            Assert.Same(elements, elements.Prepend((e, i) => {
                return(new object[] {
                    new HAttribute("a" + i.ToString(), i.ToString()),
                    "Content"
                });
            }));
            Assert.Equal(2, element1.Nodes().Count());
            Assert.Equal("0", element1.Attr("a0"));
            Assert.Equal(3, element2.Nodes().Count());
            Assert.Equal("2", element2.Attr("a2"));

            elements = null;
            Assert.Null(elements.Prepend((e, i) => {
                return(new object[] {
                    new HAttribute("a" + i.ToString(), i.ToString()),
                    "Content"
                });
            }));
        }
コード例 #3
0
        public void TestRemoveAttr()
        {
            var element1 = new HElement("div").Attr(new { style = "style", @class = "class1" });
            var element2 = new HElement("div").Attr(new { name = "name", @class = "class2" });

            var elements = new HElement[] { element1, null, element2 };

            Assert.Same(elements, elements.RemoveAttr("class"));

            Assert.Equal(null, element1.Attr("class"));
            Assert.Equal(null, element2.Attr("class"));
            Assert.Equal("style", element1.Attr("style"));
            Assert.Equal(null, element2.Attr("style"));
            Assert.Equal(null, element1.Attr("name"));
            Assert.Equal("name", element2.Attr("name"));
        }
コード例 #4
0
        public void TestAttrPoco()
        {
            var elements = new HElement[] {
                new HElement("div", new HAttribute("class", "one")),
                new HElement("div"),
                new HElement("div", new HAttribute("style", "font-size:red"))
            };

            elements.Attr(new { style = "", @class = "two" });
            Assert.Null(elements[0].Attribute("style"));
            Assert.Null(elements[1].Attribute("style"));
            Assert.Null(elements[2].Attribute("style"));
            Assert.Equal("two", elements.Attr("class"));

            // Create the attribute
            elements.Attr(new { style = "font-size:red", data_value = "data" });
            Assert.Equal("font-size:red", elements[0].Attr("style"));
            Assert.Equal("font-size:red", elements[1].Attr("style"));
            Assert.Equal("font-size:red", elements[2].Attr("style"));
            Assert.Equal("data", elements.Attr("data-value"));

            elements.Attr(new TestPoco()
            {
                data_int = 123, data_str = "str"
            });
            Assert.Equal("123", elements.Attr("data-int"));
            Assert.Equal("str", elements.Attr("data-str"));
        }
コード例 #5
0
        public void TestGetCssPropertiesElement()
        {
            HElement element = null;

            Assert.Equal(new String[] { "", "" }, element.Css(new String[] { "color", "font-size" }).ToArray());

            element = new HElement("div");

            Assert.Equal(new String[] { "", "" }, element.Css(new String[] { "color", "font-size" }).ToArray());

            element.Attr("id", "test").Attr("style", "");
            Assert.Equal(new String[] { "", "" }, element.Css(new String[] { "color", "font-size" }).ToArray());

            element.Attr("style", "color=blue;");
            Assert.Equal(new String[] { "blue", "" }, element.Css(new String[] { "color", "font-size" }).ToArray());

            element.Attr("style", "font-size=12px;other=;empty;color=blue");
            Assert.Equal(new String[] { "blue", "12px" }, element.Css(new String[] { "color", "font-size" }).ToArray());
        }
コード例 #6
0
        public void TestGetCssPropertyElement()
        {
            HElement element = null;

            Assert.Equal(String.Empty, element.Css("color"));

            element = new HElement("div");

            Assert.Equal(String.Empty, element.Css("color"));

            element.Attr("id", "test").Attr("style", "");
            Assert.Equal(String.Empty, element.Css("color"));

            element.Attr("style", "font-size=12px;color=blue;");
            Assert.Equal("blue", element.Css("color"));

            element.Attr("style", "font-size=12px;other=;empty;color=blue");
            Assert.Equal("blue", element.Css("color"));
        }
コード例 #7
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestAppendElement()
        {
            var element = new HElement("div", new HElement("p"));

            Assert.Same(element, element.Append(new HElement("span"), "test", null, new HAttribute("attr", "value")));
            Assert.Equal(3, element.Nodes().Count());
            Assert.Equal("value", element.Attr("attr"));

            element = null;
            Assert.Null(element.Append(new HElement("span"), "test", null, new HAttribute("attr", "value")));
        }
コード例 #8
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestPrependElement()
        {
            var element = new HElement("div", new HElement("p"));

            Assert.Same(element, element.Prepend(new HElement("span"), "test", null, new HAttribute("attr", "value")));
            Assert.Equal(3, element.Nodes().Count());
            Assert.Equal("value", element.Attr("attr"));
            Assert.Equal("<div attr=\"value\"><span></span>test<p></p></div>", element.ToString());

            element = null;
            Assert.Null(element.Prepend(new HElement("span"), "test", null, new HAttribute("attr", "value")));
        }
コード例 #9
0
        public void TestAttrElements()
        {
            var elements = new HElement[] {
                new HElement("div", new HAttribute("class", "one")),
                new HElement("div"),
                new HElement("div", new HAttribute("style", "font-size:red"))
            };

            Assert.Equal("one", elements.Attr("class"));
            Assert.Equal(null, elements.Attr("style"));
            Assert.Equal(null, elements.Attr("id"));

            // Remove all style attributes
            elements.Attr("style", "");
            Assert.Null(elements[0].Attribute("style"));
            Assert.Null(elements[1].Attribute("style"));
            Assert.Null(elements[2].Attribute("style"));

            // Create the attribute
            elements.Attr("style", "font-size:red");
            Assert.Equal("font-size:red", elements[0].Attr("style"));
            Assert.Equal("font-size:red", elements[1].Attr("style"));
            Assert.Equal("font-size:red", elements[2].Attr("style"));

            elements = null;
            Assert.Equal(null, elements.Attr("id"));
        }
コード例 #10
0
        public void TestAttrByCallback()
        {
            var elements = new HElement[] {
                new HElement("div", new HAttribute("class", "one")),
                new HElement("div"),
                new HElement("div", new HAttribute("style", "font-size:red"))
            };

            elements.Attr("style", (elm, idx) => String.Format("color-{0}", idx));
            Assert.Equal("color-0", elements[0].Attr("style"));
            Assert.Equal("color-1", elements[1].Attr("style"));
            Assert.Equal("color-2", elements[2].Attr("style"));
        }
コード例 #11
0
ファイル: ElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestPrependElements()
        {
            var element1 = new HElement("div", new HElement("p"));
            var element2 = new HElement("div", new HElement("p"), new HElement("div"), new HAttribute("attr1", "val1"));

            var elements = new HElement[] { element1, null, element2 };

            Assert.Same(elements, elements.Prepend(new HElement("span"), "test", null, new HAttribute("attr", "value")));
            Assert.Equal(3, element1.Nodes().Count());
            Assert.Equal("value", element1.Attr("attr"));
            Assert.Equal(4, element2.Nodes().Count());
            Assert.Equal("value", element2.Attr("attr"));

            elements = null;
            Assert.Null(elements.Prepend(new HElement("span"), "test", null, new HAttribute("attr", "value")));
        }
コード例 #12
0
        public void TestAttrElement()
        {
            var element = new HElement("div");

            // The value is null so the attribute is not created
            element.Attr("style", (String)null);
            Assert.Null(element.Attr("Style"));

            // Create the attribute
            element.Attr("style", "font-size:red");
            Assert.Equal("font-size:red", element.Attr("Style"));

            // Update the attribute
            element.Attr("style", "font-size:blue");
            Assert.Equal("font-size:blue", element.Attr("Style"));

            // Delete the attribute
            element.Attr("style", "");
            Assert.Null(element.Attr("Style"));
        }