Example #1
0
        public void ToXmlString_should_return_basic_xml()
        {
            var doc = new DomDocument();

            doc.Append(doc.CreateElement("el"));
            Assert.Equal("<el />", doc.ToXmlString());
        }
 public void test_append_multiple_noncontent_nodes()
 {
     DomDocument doc = new DomDocument();
     var docType = doc.CreateDocumentType("html");
     var ws = doc.CreateComment("time");
     var html = doc.CreateElement("html");
     doc.Append(docType, ws, html);
     Assert.That(doc.DocumentElement, Is.SameAs(html));
     Assert.That(doc.ChildNodes.Count, Is.EqualTo(3));
 }
Example #3
0
        public void Append_should_append_multiple_noncontent_nodes()
        {
            DomDocument doc     = new DomDocument();
            var         docType = doc.CreateDocumentType("html");
            var         ws      = doc.CreateComment("time");
            var         html    = doc.CreateElement("html");

            doc.Append(docType, ws, html);
            Assert.Same(html, doc.DocumentElement);
            Assert.Equal(3, doc.ChildNodes.Count);
        }
Example #4
0
        public void Append_should_move_extant_child_to_end() {
            DomDocument doc = new DomDocument();
            var html = doc.CreateElement("html");
            doc.Append(html);
            var head = doc.CreateElement("head").AppendTo(html);
            doc.CreateElement("body").AppendTo(html);

            html.Append(head);
            Assert.HasCount(2, html.ChildNodes);
            Assert.HasCount(2, html.Elements);
            Assert.Equal("head", html.Elements[1].NodeName);
        }
        public void construct_generic_dom_document_factory_methods()
        {
            DomDocument d = new DomDocument();
            var html = d.CreateElement("html");
            var body = d.CreateElement("body");
            var p = d.CreateElement("p");
            var text = d.CreateText("Hello, World");

            p.Append(text);

            d.Append(html);
            body.Append(p).AppendTo(html);
        }
        public void Set_should_remove_extant_child_first(int from, int to, string expected)
        {
            DomDocument doc = new DomDocument();
            var         r   = doc.CreateElement("r");

            doc.Append(r);
            doc.CreateElement("a").AppendTo(r);
            doc.CreateElement("b").AppendTo(r);
            doc.CreateElement("c").AppendTo(r);

            r.ChildNodes[to] = r.ChildNodes[from];
            Assert.Equal(expected, string.Join(" ", r.Elements.Select(t => t.NodeName)));
        }
Example #7
0
        public void BaseUri_should_inherit() {
            DomDocument doc = new DomDocument();
            var html = doc.CreateElement("html");
            var example = new Uri("https://example.com");
            html.BaseUri = example;

            doc.Append(html);
            var body = doc.CreateElement("body");
            html.Append(body);

            Assert.Equal(example, html.BaseUri);
            Assert.Equal(example, body.BaseUri);
        }
Example #8
0
        public void Append_implies_parent() {

            DomDocument doc = new DomDocument();
            var html = doc.CreateElement("html");
            doc.Append(html);
            var body = doc.CreateElement("body");
            html.Append(body);
            Assert.Same(doc, html.ParentNode);
            Assert.Same(html, body.ParentNode);
            Assert.Same(body, html.ChildNode(0));
            Assert.Same(body, html.ChildNodes[0]);
            Assert.Equal(new DomNode[] { body }, html.ChildNodes);
        }
Example #9
0
        public void test_base_uri_inherited()
        {
            DomDocument doc = new DomDocument();
            var html = doc.CreateElement("html");
            var example = new Uri("https://example.com");
            html.BaseUri = example;

            doc.Append(html);
            var body = doc.CreateElement("body");
            html.Append(body);

            Assert.That(html.BaseUri, Is.EqualTo(example));
            Assert.That(body.BaseUri, Is.EqualTo(example));
        }
        public void construct_generic_dom_document_processing_factory()
        {
            DomDocument d = new DomDocument();
            var xml = d.CreateProcessingInstruction("xml");
            xml.AppendData("version=\"1.0\" standalone=\"yes\"");
            var html = d.CreateElement("html");
            var body = d.CreateElement("body");
            var p = d.CreateElement("p");
            var text = d.CreateText("Hello, World");

            p.Append(text);

            d.Append(html);
            body.Append(p).AppendTo(html);
        }
Example #11
0
 public void test_append_child_implies_parent()
 {
     DomDocument doc = new DomDocument();
     var html = doc.CreateElement("html");
     doc.Append(html);
     var body = doc.CreateElement("body");
     html.Append(body);
     Assert.That(html.ParentNode, Is.SameAs(doc));
     Assert.That(body.ParentNode, Is.SameAs(html));
     Assert.That(html.ChildNode(0), Is.SameAs(body));
     Assert.That(html.ChildNodes[0], Is.SameAs(body));
     Assert.That(html.ChildNodes, Is.EquivalentTo(new[] {
                                                      body
                                                  }));
     Assert.That(html.ChildNodes.ToArray(), Is.EquivalentTo(new[] {
                                                                body
                                                            }));
 }
Example #12
0
        public void Attributes_test_detached_element_temporary_attributes()
        {
            // It is possible that DomElement might be created outside of DomDocument such as this,
            // or that initialization order of element might cause attributes to be created
            DomElement e = new DomElement("detached");

            e.Attribute("hello", "world");

            Assert.Equal("world", e.Attribute("hello"));

            DomDocument doc = new DomDocument();

            doc.Append(e);

            Assert.Equal("world", e.Attribute("hello"));
            e.Attribute("hello", "earth");

            Assert.Equal("hello", e.Attributes[0].LocalName);
            Assert.Equal("earth", e.Attributes[0].Value);
        }
Example #13
0
        public void BaseUri_should_inherit_on_base_uri_nulled_out() {
            var example1 = new Uri("https://example.com");
            var example2 = new Uri("https://test.example");

            DomDocument doc = new DomDocument();
            var html = doc.CreateElement("html");
            html.BaseUri = example1;

            var body = doc.CreateElement("body");
            body.BaseUri = example2;

            doc.Append(html);
            html.Append(body);

            // Setting this explicitly show return to the inherited balue
            Assume.Equal(example2, body.BaseUri);
            body.BaseUri = null;

            Assert.Equal(example1, body.BaseUri);
        }