示例#1
0
        public void TestWrapInnerElement()
        {
            var n1   = new HElement("span", "Content");
            var n2   = new HElement("span");
            var root = new HElement("div", n1, n2);

            Assert.Same(n1, n1.WrapInner(new HElement("strong", new HElement("em"))));
            Assert.Equal("<div><span><strong><em>Content</em></strong></span><span></span></div>", root.ToString());

            Assert.Same(n2, n2.WrapInner(new HElement("p", new HElement("a"))));
            Assert.Equal("<div><span><strong><em>Content</em></strong></span><span><p><a></a></p></span></div>", root.ToString());

            n1 = null;
            Assert.Null(n1.WrapInner(new HElement("strong", new HElement("em"))));
            Assert.Equal("<div><span><strong><em>Content</em></strong></span><span><p><a></a></p></span></div>", root.ToString());
        }
示例#2
0
        public void TestWrapInnerElementsByCallback()
        {
            var n1 = new HElement("span", "Content 1");
            var n2 = new HElement("span", "Content 2");
            var n3 = new HElement("div", n1, n2);

            Assert.Equal("<div><span>Content 1</span><span>Content 2</span></div>", n3.ToString());

            var elements = new HElement[] { n1, n2 };

            Assert.Same(elements, elements.WrapInner((e, i) => new HElement("strong", "C" + i.ToString(), new HElement("em"))));
            Assert.Equal("<div><span><strong>C0<em>Content 1</em></strong></span><span><strong>C1<em>Content 2</em></strong></span></div>", n3.ToString());

            elements = null;
            Assert.Null(elements.WrapInner((e, i) => new HElement("strong", "C" + i.ToString(), new HElement("em"))));
            Assert.Equal("<div><span><strong>C0<em>Content 1</em></strong></span><span><strong>C1<em>Content 2</em></strong></span></div>", n3.ToString());
        }