2002-09-29 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / System.XML / Test / XmlAttributeTests.cs
1 // XmlAttributeTests.cs : Tests for the XmlAttribute class
2 //
3 // Author: Mike Kestner <mkestner@speakeasy.net>
4 //
5 // <c> 2002 Mike Kestner
6
7 using System;
8 using System.Xml;
9
10 using NUnit.Framework;
11
12 namespace MonoTests.System.Xml
13 {
14         public class XmlAttributeTests : TestCase
15         {
16                 public XmlAttributeTests() : base("MonoTests.System.Xml.XmlAttributeTests testsuite") { }
17                 public XmlAttributeTests(string name) : base(name) { }
18
19                 XmlDocument doc;
20                 XmlAttribute attr;
21
22                 protected override void SetUp()
23                 {
24                         doc = new XmlDocument();
25                         attr = doc.CreateAttribute("attr1");
26                         attr.Value = "val1";
27                 }
28
29                 public void TestAttributes()
30                 {
31                         AssertNull(attr.Attributes);
32                 }
33
34                 public void TestAttributeInnerAndOuterXml ()
35                 {
36                         attr = doc.CreateAttribute ("foo", "bar", "http://abc.def");
37                         attr.Value = "baz";
38                         AssertEquals ("baz", attr.InnerXml);
39                         AssertEquals ("foo:bar=\"baz\"", attr.OuterXml);
40                 }
41
42                 public void TestAttributeWithNoValue ()
43                 {
44                         XmlAttribute attribute = doc.CreateAttribute ("name");
45                         AssertEquals (String.Empty, attribute.Value);
46                         Assert (!attribute.HasChildNodes);
47                         AssertNull (attribute.FirstChild);
48                         AssertNull (attribute.LastChild);
49                         AssertEquals (0, attribute.ChildNodes.Count);
50                 }
51
52                 public void TestAttributeWithValue ()
53                 {
54                         XmlAttribute attribute = doc.CreateAttribute ("name");
55                         attribute.Value = "value";
56                         AssertEquals ("value", attribute.Value);
57                         Assert (attribute.HasChildNodes);
58                         AssertNotNull (attribute.FirstChild);
59                         AssertNotNull (attribute.LastChild);
60                         AssertEquals (1, attribute.ChildNodes.Count);
61                         AssertEquals (XmlNodeType.Text, attribute.ChildNodes [0].NodeType);
62                         AssertEquals ("value", attribute.ChildNodes [0].Value);
63                 }
64
65                 public void TestHasChildNodes()
66                 {
67                         Assert(attr.HasChildNodes);
68                 }
69
70                 public void TestName()
71                 {
72                         AssertEquals("attr1", attr.Name);
73                 }
74
75                 public void TestNodeType()
76                 {
77                         AssertEquals(XmlNodeType.Attribute, attr.NodeType);
78                 }
79
80                 public void TestOwnerDocument()
81                 {
82                         AssertSame(doc, attr.OwnerDocument);
83                 }
84
85                 public void TestParentNode()
86                 {
87                         AssertNull("Attr parents not allowed", attr.ParentNode);
88                 }
89
90                 public void TestValue()
91                 {
92                         AssertEquals("val1", attr.Value);
93                 }
94         }
95 }