implementing XmlElement.SetAttributeNode(localName, namespaceURI) and
[mono.git] / mcs / class / System.XML / Test / XPathNavigatorMatchesTests.cs
1 //
2 // MonoTests.System.Xml.XPathNavigatorMatchesTests
3 //
4 // Author:
5 //   Jason Diamond <jason@injektilo.org>
6 //
7 // (C) 2002 Jason Diamond
8 //
9
10 using System;
11 using System.Xml;
12 using System.Xml.XPath;
13
14 using NUnit.Framework;
15
16 namespace MonoTests.System.Xml
17 {
18         public class XPathNavigatorMatchesTests : TestCase
19         {
20                 public XPathNavigatorMatchesTests () : base ("MonoTests.System.Xml.XPathNavigatorMatchesTests testsuite") {}
21                 public XPathNavigatorMatchesTests (string name) : base (name) {}
22
23                 public void TestMatchRoot ()
24                 {
25                         XmlDocument document = new XmlDocument ();
26                         document.LoadXml ("<foo />");
27                         XPathNavigator navigator = document.CreateNavigator ();
28
29                         Assert (navigator.Matches ("/"));
30                 }
31
32                 public void TestFalseMatchRoot ()
33                 {
34                         XmlDocument document = new XmlDocument ();
35                         document.LoadXml ("<foo />");
36                         XPathNavigator navigator = document.CreateNavigator ();
37
38                         Assert (!navigator.Matches ("foo"));
39                 }
40
41                 public void TestMatchDocumentElement ()
42                 {
43                         XmlDocument document = new XmlDocument ();
44                         document.LoadXml ("<foo />");
45                         XPathNavigator navigator = document.DocumentElement.CreateNavigator ();
46
47                         Assert (navigator.Matches ("foo"));
48                 }
49
50                 public void TestMatchAbsoluteDocumentElement ()
51                 {
52                         XmlDocument document = new XmlDocument ();
53                         document.LoadXml ("<foo />");
54                         XPathNavigator navigator = document.DocumentElement.CreateNavigator ();
55
56                         Assert (navigator.Matches ("/foo"));
57                 }
58
59                 public void TestMatchDocumentElementChild ()
60                 {
61                         XmlDocument document = new XmlDocument ();
62                         document.LoadXml ("<foo><bar /></foo>");
63                         XPathNavigator navigator = document.DocumentElement.FirstChild.CreateNavigator ();
64
65                         Assert (navigator.Matches ("bar"));
66                         Assert (navigator.Matches ("foo/bar"));
67                 }
68
69                 public void TestMatchAttribute ()
70                 {
71                         XmlDocument document = new XmlDocument ();
72                         document.LoadXml ("<foo bar='baz' />");
73                         XPathNavigator navigator = document.DocumentElement.Attributes[0].CreateNavigator ();
74
75                         Assert (navigator.Matches ("@bar"));
76                         Assert (navigator.Matches ("foo/@bar"));
77                 }
78
79                 public void TestSlashSlash ()
80                 {
81                         XmlDocument document = new XmlDocument ();
82                         document.LoadXml ("<foo><bar><baz/></bar></foo>");
83                         XPathNavigator navigator = document.DocumentElement.FirstChild.FirstChild.CreateNavigator ();
84
85                         Assert (navigator.Matches ("foo//baz"));
86                 }
87
88                 public void TestAbsoluteSlashSlash ()
89                 {
90                         XmlDocument document = new XmlDocument ();
91                         document.LoadXml ("<foo><bar><baz/></bar></foo>");
92                         XPathNavigator navigator = document.DocumentElement.FirstChild.FirstChild.CreateNavigator ();
93
94                         Assert (navigator.Matches ("//baz"));
95                 }
96
97                 public void TestMatchDocumentElementWithPredicate ()
98                 {
99                         XmlDocument document = new XmlDocument ();
100                         document.LoadXml ("<foo><bar /></foo>");
101                         XPathNavigator navigator = document.DocumentElement.CreateNavigator ();
102
103                         Assert (navigator.Matches ("foo[bar]"));
104                 }
105
106                 public void TestFalseMatchDocumentElementWithPredicate ()
107                 {
108                         XmlDocument document = new XmlDocument ();
109                         document.LoadXml ("<foo><bar /></foo>");
110                         XPathNavigator navigator = document.DocumentElement.CreateNavigator ();
111
112                         Assert (!navigator.Matches ("foo[baz]"));
113                 }
114         }
115 }
116