Added XPathScanner and Tests.
[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 Ximian.Mono.Tests
13 {
14         public class XmlAttributeTests : TestCase
15         {
16                 public XmlAttributeTests() : base("Ximian.Mono.Tests.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 TestAttributeWithNoValue ()
35                 {
36                         XmlAttribute attribute = doc.CreateAttribute ("name");
37                         AssertEquals (String.Empty, attribute.Value);
38                         Assert (!attribute.HasChildNodes);
39                         AssertNull (attribute.FirstChild);
40                         AssertNull (attribute.LastChild);
41                         AssertEquals (0, attribute.ChildNodes.Count);
42                 }
43
44                 public void TestAttributeWithValue ()
45                 {
46                         XmlAttribute attribute = doc.CreateAttribute ("name");
47                         attribute.Value = "value";
48                         AssertEquals ("value", attribute.Value);
49                         Assert (attribute.HasChildNodes);
50                         AssertNotNull (attribute.FirstChild);
51                         AssertNotNull (attribute.LastChild);
52                         AssertEquals (1, attribute.ChildNodes.Count);
53                         AssertEquals (XmlNodeType.Text, attribute.ChildNodes [0].NodeType);
54                         AssertEquals ("value", attribute.ChildNodes [0].Value);
55                 }
56
57                 public void TestHasChildNodes()
58                 {
59                         Assert(attr.HasChildNodes);
60                 }
61
62                 public void TestName()
63                 {
64                         AssertEquals("attr1", attr.Name);
65                 }
66
67                 public void TestNodeType()
68                 {
69                         AssertEquals(XmlNodeType.Attribute, attr.NodeType);
70                 }
71
72                 public void TestOwnerDocument()
73                 {
74                         AssertSame(doc, attr.OwnerDocument);
75                 }
76
77                 public void TestParentNode()
78                 {
79                         AssertNull("Attr parents not allowed", attr.ParentNode);
80                 }
81
82                 public void TestValue()
83                 {
84                         AssertEquals("val1", attr.Value);
85                 }
86         }
87 }