public void Prepend_should_apply_correct_order_three() { var doc = new DomDocument(); var element = doc.AppendElement("html"); element.Prepend(doc.CreateElement("head"), doc.CreateElement("body"), doc.CreateElement("tail")); Assert.Equal("head body tail", string.Join(" ", doc.DocumentElement.Elements.Select(t => t.Name))); }
public void Prepend_should_apply_correct_order_two() { var doc = new DomDocument(); var element = doc.AppendElement("html"); element.Prepend(doc.CreateElement("head"), doc.CreateElement("body")); Assert.Equal("head", doc.DocumentElement.Elements[0].LocalName); Assert.Equal("body", doc.DocumentElement.Elements[1].LocalName); }
public void Insert_should_add_to_end_given_index_empty(bool useLinkedList) { DomDocument doc = new DomDocument(useLinkedList); var r = doc.CreateElement("r"); var a = doc.CreateElement("a"); r.ChildNodes.Insert(0, a); Assert.Equal(1, r.ChildNodes.Count); Assert.Same(a, r.ChildNodes[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 ReplaceWith_should_replace_elements() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); var h1 = body.AppendElement("h1"); var h3 = doc.CreateElement("h3"); var result = h1.ReplaceWith(h3, doc.CreateElement("h4"), doc.CreateElement("h5")); Assert.Equal("<html><body><h3 /><h4 /><h5 /></body></html>", doc.ToXmlString()); }
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 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); }
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))); }
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); }
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); }
public void ToXmlString_should_return_basic_xml() { var doc = new DomDocument(); doc.Append(doc.CreateElement("el")); Assert.Equal("<el />", doc.ToXmlString()); }
public void Attribute_illegal_arguments(string attr) { DomDocument doc = new DomDocument(); var html = doc.CreateElement("html"); Assert.Throws<ArgumentException>(() => { html.Attribute(attr); }); }
public void LocalName_is_element_name_unqualif() { DomDocument doc = new DomDocument(); var title = doc.CreateElement("title"); Assert.Equal("title", title.LocalName); }
public void ElementPosition_of_unlinked_node_is_negative_1() { DomDocument doc = new DomDocument(); var dd = doc.CreateElement("html"); Assert.Equal(-1, dd.ElementPosition); }
public void NodeName_is_element_name() { DomDocument doc = new DomDocument(); var title = doc.CreateElement("title"); Assert.Equal("title", title.NodeName); }
public void NodeValue_is_null() { DomDocument doc = new DomDocument(); var dd = doc.CreateElement("html"); Assert.Null(dd.NodeValue); }
public void CreateElement_implies_owner_document() { DomDocument doc = new DomDocument(); var html = doc.CreateElement("html"); Assert.Null(html.ParentNode); Assert.Same(doc, html.OwnerDocument); }
public void Prepend_should_apply_correct_order_enumeration() { var doc = new DomDocument(); var element = doc.AppendElement("html"); var items = Enumerable.Range(1, 6).Select(t => doc.CreateElement("x" + t)); element.Prepend(items); Assert.Equal("x1 x2 x3 x4 x5 x6", string.Join(" ", doc.DocumentElement.Elements.Select(t => t.Name))); }
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 })); }
public void RemoveAnnotation_will_detach_node() { var doc = new DomDocument(); var anno = new FLifecycleAnnotation(); doc.CreateElement("a").RemoveAnnotation(anno); Assert.Equal(1, anno.DetachingCallCount); }
public void Wrap_should_apply_to_unlinked_nodes() { DomDocument doc = new DomDocument(); var title = doc.CreateElement("title"); var head = title.Wrap("head"); Assert.Equal("head", head.LocalName); Assert.Equal("<head><title /></head>", head.ToXmlString()); }
public void Clone_will_clone_annotations_copied_to_new_node() { var doc = new DomDocument(); var element = doc.CreateElement("a").AddAnnotation(new object()); var clone = element.Clone(); Assert.HasCount(1, clone.AnnotationList.OfType <object>()); }
public void ReplaceWith_should_replace_element_with_element() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); var head = (DomElement)body.ReplaceWith(doc.CreateElement("head")); Assert.Equal("head", ((DomElement)html.ChildNode(0)).LocalName); Assert.Equal("head", head.LocalName); }
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)); }
public void ReplaceWith_element() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("leading"); var head = doc.CreateElement("head"); var result = html.ReplaceWith(head); Assert.Equal("<head />", doc.ToXmlString()); Assert.Same(head, result); }
// Just process children protected override DomNode Convert(DomDocument document, DomElement element, IScriptGenerator gen) { var e = document.CreateElement(element.Name); // Copy annotations to the new element e.AddAnnotations(element.Annotations <object>().Except(HxlAnnotations.Retained)); return(ProcessChildren(e, element, gen)); }
public void AddAnnotation_will_attach_node() { var doc = new DomDocument(); var anno = new FLifecycleAnnotation(); var element = doc.CreateElement("a").AddAnnotation(anno); Assert.Same(element, anno.LastAttachingArguments); Assert.Equal(1, anno.AttachingCallCount); }
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); }
public void DomObject_Clone_will_clone_annotations_copied_to_new_node() { var doc = new DomDocument(); var anno = new FLifecycleAnnotation(); var element = doc.CreateElement("a").AddAnnotation(anno); var clone = element.Clone(); Assert.NotNull(clone.Annotation <FLifecycleAnnotation>()); Assert.NotSame(anno, clone.Annotation <FLifecycleAnnotation>()); }
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); }
public void Add_should_add_to_end_nominal(bool useLinkedList) { DomDocument doc = new DomDocument(useLinkedList); var a = doc.CreateElement("a"); doc.ChildNodes.Add(a); Assert.Equal(1, doc.ChildNodes.Count); Assert.Same(a, doc.ChildNodes[0]); Assert.Equal(0, a.NodePosition); }
public void NodePosition_should_update_with_insert(bool useLinkedList) { DomDocument doc = new DomDocument(useLinkedList); var head = doc.CreateElement("head"); doc.ChildNodes.Add(doc.CreateText(" ")); doc.ChildNodes.Add(doc.CreateText(" ")); doc.ChildNodes.Insert(0, head); Assert.Equal(0, head.NodePosition); }
public void IndexOf_should_obtain_index_nominal(bool useLinkedList) { DomDocument doc = new DomDocument(useLinkedList); var a = doc.CreateElement("a"); var b = doc.CreateText(" "); doc.ChildNodes.Add(a); doc.ChildNodes.Add(b); Assert.Equal(0, doc.ChildNodes.IndexOf(a)); Assert.Equal(1, doc.ChildNodes.IndexOf(b)); }
public void Clear_should_reset_siblings(bool useLinkedList) { DomDocument doc = new DomDocument(useLinkedList); var a = doc.CreateElement("a"); doc.ChildNodes.Add(a); doc.ChildNodes.Clear(); Assert.Equal(0, doc.ChildNodes.Count); Assert.Null(a.PreviousSibling); Assert.Null(a.NextSibling); }
public void test_replace_element_with_element() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); var head = (DomElement) body.ReplaceWith(doc.CreateElement("head")); Assert.That(((DomElement) html.ChildNode(0)).Name, Is.EqualTo("head")); Assert.That(head.Name, Is.EqualTo("head")); }
public void test_replace_with_document_element() { DomDocument doc = new DomDocument(); var html = doc.AppendText("leading ws"); var head = doc.CreateElement("head"); var result = html.ReplaceWith(head); Assert.That(doc.ToXml(), Is.EqualTo("<head />")); Assert.That(result, Is.SameAs(head)); }
public void test_replace_with_many_nominal() { DomDocument doc = new DomDocument(); var html = doc.AppendElement("html"); var body = html.AppendElement("body"); var h1 = body.AppendElement("h1"); var h3 = doc.CreateElement("h3"); var result = h1.ReplaceWith(h3, doc.CreateElement("h4"), doc.CreateElement("h5")); Assert.That(doc.ToXml(), Is.EqualTo("<html><body><h3 /><h4 /><h5 /></body></html>")); Assert.That(result, Is.SameAs(h3)); }
public void test_create_child_implies_owner_document() { DomDocument doc = new DomDocument(); var html = doc.CreateElement("html"); Assert.That(html.ParentNode, Is.Null); Assert.That(html.OwnerDocument, Is.SameAs(doc)); }