示例#1
0
        public void CreateAttribute_requires_name_argument()
        {
            DomDocument doc = new DomDocument();

            Assert.Throws <ArgumentNullException>(() => doc.CreateAttribute((DomName)null));
            Assert.Throws <ArgumentException>(() => doc.CreateAttribute((string)null));
        }
示例#2
0
        public void After_should_preserve_order_of_list()
        {
            DomDocument doc   = new DomDocument();
            var         html  = doc.AppendElement("html");
            var         attr  = html.AppendAttribute("first", "");
            var         attr1 = doc.CreateAttribute("lang", "en");
            var         attr2 = doc.CreateAttribute("profile", "dotcom");

            attr.After(attr1, attr2);
            Assert.Equal("<html first=\"\" lang=\"en\" profile=\"dotcom\"/>", doc.OuterXml);
        }
示例#3
0
        public void AppendAttribute_duplicate_name_error()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");
            var         attr = html.AppendAttribute("lang", "en");

            Assert.Throws <ArgumentException>(() => {
                html.Append(doc.CreateAttribute("lang", "fr"));
            });

            Assert.Throws <ArgumentException>(() => {
                html.Attributes.Add(doc.CreateAttribute("lang", "fr"));
            });
        }
示例#4
0
        public void NodeName_equals_attribute_name()
        {
            var doc  = new DomDocument();
            var attr = doc.CreateAttribute("lang");

            Assert.Equal("lang", attr.NodeName);
        }
示例#5
0
        public void CreateAttribute_is_unlinked()
        {
            DomDocument doc  = new DomDocument();
            var         attr = doc.CreateAttribute("lang", "en");

            Assert.Same(doc, attr.OwnerDocument);
        }
示例#6
0
        public void ChildNodes_is_a_empty_collection()
        {
            DomDocument doc  = new DomDocument();
            var         attr = doc.CreateAttribute("lang", "en");

            Assert.True(attr.ChildNodes.IsReadOnly);
            Assert.Empty(attr.ChildNodes);
        }
 public void test_create_attribute_unlinked_implies_owner_document()
 {
     DomDocument doc = new DomDocument();
     var html = doc.CreateAttribute("class");
     Assert.That(html.OwnerElement, Is.Null);
     Assert.That(html.ParentNode, Is.Null);
     Assert.That(html.OwnerDocument, Is.SameAs(doc));
 }
示例#8
0
        public void NextAttribute_and_PreviousAttribute_adjacent_unlinkd()
        {
            DomDocument doc  = new DomDocument();
            var         attr = doc.CreateAttribute("att");

            Assert.Null(attr.NextAttribute);
            Assert.Null(attr.PreviousAttribute);
        }
示例#9
0
        public void NodeName_equals_attribute_value()
        {
            var doc  = new DomDocument();
            var attr = doc.CreateAttribute("lang");

            attr.Value = "en-us";
            Assert.Equal("en-us", attr.NodeValue);
        }
示例#10
0
        static DomAttribute Attribute(string text)
        {
            var doc  = new DomDocument();
            var attr = doc.CreateAttribute("hello");

            attr.Value = text;
            return(attr);
        }
示例#11
0
        public void TextContent_gets_and_sets_text()
        {
            DomDocument doc  = new DomDocument();
            var         attr = doc.CreateAttribute("s");

            attr.TextContent = "text";

            Assert.Equal("text", attr.TextContent);
        }
示例#12
0
        public void CreateAttribute_unlinked_implies_owner_document()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.CreateAttribute("class");

            Assert.Null(html.OwnerElement);
            Assert.Null(html.ParentNode);
            Assert.Same(doc, html.OwnerDocument);
        }
示例#13
0
        public void Append_to_element_should_add_attribute()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");
            var         attr = doc.CreateAttribute("lang");

            html.Append(attr);
            Assert.Equal(1, html.Attributes.Count);
        }
示例#14
0
 public void test_create_attribute_implies_owner_document()
 {
     DomDocument doc = new DomDocument();
     var html = doc.AppendElement("html");
     var attr = doc.CreateAttribute("class");
     html.Attributes.Add(attr);
     Assert.That(attr.OwnerElement, Is.SameAs(html));
     Assert.That(attr.ParentNode, Is.Null);
     Assert.That(attr.OwnerDocument, Is.SameAs(doc));
 }
示例#15
0
        public void After_sets_attributes_after()
        {
            DomDocument doc   = new DomDocument();
            var         html  = doc.AppendElement("html");
            var         attr1 = html.AppendAttribute("lang", "en");
            var         attr2 = doc.CreateAttribute("profile", "dotcom");

            attr1.After(attr2);
            Assert.Equal("<html lang=\"en\" profile=\"dotcom\"/>", doc.OuterXml);
        }
示例#16
0
        public void CreateAttribute_implies_owner_document()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");
            var         attr = doc.CreateAttribute("class");

            html.Attributes.Add(attr);
            Assert.Same(html, attr.OwnerElement);
            Assert.Null(attr.ParentNode);
            Assert.Same(doc, attr.OwnerDocument);
        }
示例#17
0
        public void Append_new_attributes_implies_add()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");
            var         attr = doc.CreateAttribute("lang", "en");

            html.Append(attr);

            Assert.Equal(1, html.Attributes.Count);
            Assert.Equal("en", html.Attribute("lang"));
            Assert.Same(doc, attr.OwnerDocument);
        }
示例#18
0
        public void test_append_attribute_implies_add()
        {
            DomDocument doc = new DomDocument();
            var html = doc.AppendElement("html");
            var attr = doc.CreateAttribute("lang", "en");

            html.Append(attr);

            Assert.That(html.Attributes.Count, Is.EqualTo(1));
            Assert.That(html.Attribute("lang"), Is.EqualTo("en"));
            Assert.That(attr.OwnerDocument, Is.SameAs(doc));
        }
示例#19
0
        public void AppendAttribute_appends_to_existing_attribute()
        {
            DomDocument doc  = new DomDocument();
            var         e    = doc.AppendElement("t");
            var         attr = doc.CreateAttribute("class", "me");

            e.Attributes.Add(attr);
            e.AppendAttribute("class", "you");

            Assert.Same(attr, e.Attributes[0]);
            Assert.Equal("meyou", e.Attributes[0].Value);
        }
示例#20
0
        public void CreateAttribute_uses_primitive_value_specified_by_schema()
        {
            var schema  = new DomSchema("custom");
            var attrDef = schema.AttributeDefinitions.AddNew("lcid");

            attrDef.ValueType = typeof(int);

            var doc = new DomDocument().WithSchema(schema);

            Assert.IsInstanceOf <DomValue <int> >(
                doc.CreateAttribute("lcid").DomValue
                );
        }
示例#21
0
        public void ReplaceWith_attribute_replace_with_attribute_and_unlinks()
        {
            DomDocument doc   = new DomDocument();
            var         html  = doc.AppendElement("html");
            var         attr  = html.AppendAttribute("lang", "en");
            var         attr2 = doc.CreateAttribute("dir", "ltr");

            Assert.Same(attr2, attr.ReplaceWith(attr2));
            Assert.Equal(1, html.Attributes.Count);
            Assert.Equal(attr2, html.Attributes[0]);
            Assert.DoesNotContain(attr2, doc.UnlinkedNodes);
            Assert.Contains(attr, doc.UnlinkedNodes);
        }
示例#22
0
        public void Append_to_element_should_unparent_old()
        {
            DomDocument doc  = new DomDocument();
            var         root = doc.AppendElement("html");
            var         head = root.AppendElement("head");
            var         body = root.AppendElement("body");
            var         attr = doc.CreateAttribute("lang");

            head.Append(attr);
            body.Append(attr);
            Assert.Equal(0, head.Attributes.Count);
            Assert.Equal(1, body.Attributes.Count);
            Assert.Same(body, attr.OwnerElement);
        }
示例#23
0
        public void Append_to_element_should_unparent_old_diff_documents()
        {
            DomDocument doc1 = new DomDocument();
            DomDocument doc2 = new DomDocument();
            var         head = doc1.AppendElement("head");
            var         body = doc2.AppendElement("body");
            var         attr = doc1.CreateAttribute("lang");

            head.Append(attr);
            body.Append(attr);
            Assert.Equal(0, head.Attributes.Count);
            Assert.Equal(1, body.Attributes.Count);
            Assert.Same(body, attr.OwnerElement);
            Assert.Same(doc2, attr.OwnerDocument);
        }
示例#24
0
        public void ReplaceWith_updates_attribute_at_same_index()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");

            html.Attribute("lang", "en");
            html.Attribute("dir", "rtl");
            var attr = html.Attributes[0];

            attr.ReplaceWith(doc.CreateAttribute("lang", "fr"));

            Assert.Equal(2, html.Attributes.Count);
            Assert.Equal("lang", html.Attributes[0].LocalName);
            Assert.Equal("fr", html.Attributes[0].Value);
        }
示例#25
0
        public void ReplaceWith_works_if_parent_is_unlinked()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.CreateElement("html");

            html.Attribute("lang", "en");

            var alt = doc.CreateAttribute("dir", "rtl");
            var old = html.Attributes[0];

            old.ReplaceWith(alt);

            Assert.Equal(1, html.Attributes.Count);
            Assert.Equal("dir", html.Attributes[0].LocalName);
            Assert.Equal("rtl", html.Attributes[0].Value);
            Assert.True(old.IsUnlinked);
        }
示例#26
0
        public void ReplaceWith_when_name_already_exists_preserves_uniqueness(string attributes)
        {
            var doc  = new DomDocument();
            var attr = doc.CreateAttribute("exists", "expected value");
            var e    = doc.AppendElement("e");

            foreach (var attrName in attributes.Split())
            {
                e.Attribute(attrName, 2);
            }

            // Replacing the second attribute collides with the first by name,
            // so the first by name is removed
            e.Attributes["other1"].ReplaceWith(attr);
            Assert.HasCount(1, e.Attributes);
            Assert.Equal("expected value", e.Attributes[0].Value);
        }
示例#27
0
        public void CreateAttribute_requires_name_argument_nonempty()
        {
            DomDocument doc = new DomDocument();

            Assert.Throws <ArgumentException>(() => doc.CreateAttribute(""));
        }
示例#28
0
        public void test_create_attribute_is_unlinked()
        {
            DomDocument doc = new DomDocument();
            var attr = doc.CreateAttribute("lang", "en");

            Assert.That(attr.OwnerDocument, Is.SameAs(doc));
        }
示例#29
0
        public void test_attribute_replace_with_attribute()
        {
            DomDocument doc = new DomDocument();
            var html = doc.AppendElement("html");
            var attr = html.AppendAttribute("lang", "en");
            var attr2 = doc.CreateAttribute("dir", "ltr");

            Assert.That(attr.ReplaceWith(attr2), Is.SameAs(attr2));
            Assert.That(html.Attributes.Count, Is.EqualTo(1));
            Assert.That(html.Attributes[0], Is.SameAs(attr2));
            Assert.True(doc.UnlinkedNodes.Contains(attr));
            Assert.False(doc.UnlinkedNodes.Contains(attr2));
        }
示例#30
0
        public void test_attribute_duplicate_name_error()
        {
            DomDocument doc = new DomDocument();
            var html = doc.AppendElement("html");
            var attr = html.AppendAttribute("lang", "en");

            Assert.That(() => {
                            html.AppendAttribute("lang", "fr");
                        }, Throws.ArgumentException);

            Assert.That(() => {
                            html.Append(doc.CreateAttribute("lang", "fr"));
                        }, Throws.ArgumentException);

            Assert.That(() => {
                            html.Attributes.Add(doc.CreateAttribute("lang", "fr"));
                        }, Throws.ArgumentException);
        }