示例#1
0
        public void CloneNode(bool deep, int expectedChildCount)
        {
            var document = new HtmlDocument();

            document.Write("<html><body><div id='p1'><span id='s'>Span text</span></div></body></html>");
            var span = document.GetElementById("s");

            document.Assert(doc =>
                            doc.Body.ChildNodes.Count == 1 &&
                            doc.GetElementById("p1").ChildNodes.Count == 1 &&
                            doc.GetElementById("s").ChildNodes.Count == 1);

            var clone = span.CloneNode(deep) as HtmlElement;

            Assert.IsNotNull(clone);

            //sate of all old elements should be the same as before
            document.Assert(doc =>
                            doc.Body.ChildNodes.Count == 1 &&
                            doc.GetElementById("p1").ChildNodes.Count == 1 &&
                            doc.GetElementById("s").ChildNodes.Count == 1);

            Assert.AreEqual(expectedChildCount, clone.ChildNodes.Count);
            Assert.IsNotNull(clone.OwnerDocument, "Clone's ownerDocument");
            Assert.AreEqual(span.OwnerDocument, clone.OwnerDocument, "Clone's ownerDocument");
            Assert.IsNull(clone.ParentNode, "Clone's parentNode");
            Assert.AreEqual("s", clone.Id);
        }
示例#2
0
        public void CloneSpan(bool deep, int expectedChildCount)
        {
            var document = new HtmlDocument();

            document.Write("<html><body><div id='p1'><span id='s'>Span text</span></div></body></html>");
            var span = document.GetElementById("s");

            document.Assert(doc =>
                            doc.Body.ChildNodes.Count == 1 &&
                            doc.GetElementById("p1").ChildNodes.Count == 1 &&
                            doc.GetElementById("s").ChildNodes.Count == 1);

            var clone = span.CloneNode(deep) as HtmlElement;

            Assert.IsNotNull(clone);

            //sate of all old elements should be the same as before
            document.Assert(doc =>
                            doc.Body.ChildNodes.Count == 1 &&
                            doc.GetElementById("p1").ChildNodes.Count == 1 &&
                            doc.GetElementById("s").ChildNodes.Count == 1);

            clone.Assert(c =>
                         c.ChildNodes.Count == expectedChildCount &&
                         c.OwnerDocument == document &&
                         c.ParentNode == null &&
                         c.Id == "s");
        }
示例#3
0
        public void UnClosedTag()
        {
            var document = new HtmlDocument();

            document.Write("<html><head><meta></head><body><div></div></body></html>");
            document.Assert(doc => doc.Body.InnerHTML == "<DIV></DIV>" && doc.Head.InnerHTML == "<META></META>");
        }