Ejemplo n.º 1
0
        public void AddBeforeSelf_NullObjectInContent_ThrowsArgumentNullException()
        {
            HtmlElement element = new HtmlElement("element");

            Assert.Throws <ArgumentNullException>("content", () => element.AddBeforeSelf(new HtmlElement[] { null }));
            Assert.Throws <ArgumentNullException>("content", () => element.AddBeforeSelf((IEnumerable <HtmlElement>) new HtmlElement[] { null }));
        }
Ejemplo n.º 2
0
        public void AddBeforeSelf_SameElement_ThrowsInvalidOperationException()
        {
            HtmlElement element = new HtmlElement("html");

            Assert.Throws <InvalidOperationException>(() => element.AddBeforeSelf(element));
            Assert.Throws <InvalidOperationException>(() => element.AddBeforeSelf(new HtmlElement[] { element }));
            Assert.Throws <InvalidOperationException>(() => element.AddBeforeSelf((IEnumerable <HtmlElement>) new HtmlElement[] { element }));
        }
Ejemplo n.º 3
0
        public void AddBeforeSelf_ElementToVoidElement_ThrowsInvalidOperationException()
        {
            HtmlElement element    = new HtmlElement("br", isVoid: true);
            HtmlElement newElement = new HtmlElement("p");

            Assert.Throws <InvalidOperationException>(() => element.AddBeforeSelf(newElement));
            Assert.Throws <InvalidOperationException>(() => element.AddBeforeSelf(new HtmlElement[] { newElement }));
            Assert.Throws <InvalidOperationException>(() => element.AddBeforeSelf((IEnumerable <HtmlElement>) new HtmlElement[] { newElement }));
        }
Ejemplo n.º 4
0
        public void AddBeforeSelf_DuplicateElement_ThrowsInvalidOperationException()
        {
            HtmlElement parent  = new HtmlElement("parent");
            HtmlElement element = new HtmlElement("child");

            parent.Add(element);

            Assert.Throws <InvalidOperationException>(() => parent.AddBeforeSelf(element));
            Assert.Throws <InvalidOperationException>(() => parent.AddBeforeSelf(new HtmlElement[] { element }));
            Assert.Throws <InvalidOperationException>(() => parent.AddBeforeSelf((IEnumerable <HtmlElement>) new HtmlElement[] { element }));
        }
Ejemplo n.º 5
0
        public void AddBeforeSelf_HtmlNode()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child1");

            parent.Add(child1);

            // Element
            HtmlElement child2 = new HtmlElement("child2");

            child1.AddBeforeSelf(child2);
            Assert.Equal(parent, child2.Parent);
            Assert.Equal(new HtmlElement[] { child2, child1 }, parent.Elements());

            // Comment
            HtmlComment comment = new HtmlComment("comment");

            child1.AddBeforeSelf(comment);
            Assert.Equal(parent, comment.Parent);
            Assert.Equal(new HtmlObject[] { child2, comment, child1 }, parent.Nodes());
        }
Ejemplo n.º 6
0
        public void AddBeforeSelf_IEnumerableHtmlObject()
        {
            HtmlElement parent = new HtmlElement("parent");
            HtmlElement child1 = new HtmlElement("child1");

            parent.Add(child1);

            HtmlElement child2 = new HtmlElement("child2");
            HtmlElement child3 = new HtmlElement("child3");

            child1.AddBeforeSelf((IEnumerable <HtmlElement>) new HtmlElement[] { child2, child3 });

            Assert.Equal(parent, child2.Parent);
            Assert.Equal(parent, child3.Parent);
            Assert.Equal(new HtmlElement[] { child3, child2, child1 }, parent.Elements());
        }