New tests.
[mono.git] / mcs / class / System.Xml.Linq / Test / System.Xml.Linq / XNodeNavigatorTest.cs
1 //
2 // Authors:
3 //   Atsushi Enomoto
4 //
5 // Copyright 2007 Novell (http://www.novell.com)
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26
27 using System;
28 using System.IO;
29 using System.Xml;
30 using System.Xml.Linq;
31 using System.Xml.XPath;
32
33 using NUnit.Framework;
34
35 namespace MonoTests.System.Xml.Linq
36 {
37         [TestFixture]
38         public class XNodeNavigatorTest
39         {
40                 [Test]
41                 public void MoveToNext ()
42                 {
43                         XElement a = new XElement ("root",
44                         new XElement ("a"),
45                         new XElement ("B"));
46                         XPathNavigator nav = a.CreateNavigator ();
47                         Assert.IsTrue (nav.MoveToFirstChild (), "#1");
48                         Assert.IsTrue (nav.MoveToNext (), "#2");
49                 }
50
51                 [Test]
52                 [ExpectedException (typeof (NotSupportedException))]
53                 public void MoveToId () // ID is not supported here.
54                 {
55                         string xml = @"
56 <!DOCTYPE root [
57 <!ELEMENT foo EMPTY>
58 <!ELEMENT bar EMPTY>
59 <!ATTLIST foo id ID #IMPLIED>
60 <!ATTLIST bar id ID #IMPLIED>
61 ]>
62 <root><foo id='foo' /><bar id='bar' /></root>";
63                         XDocument doc = XDocument.Parse (xml, LoadOptions.SetLineInfo);
64                         XPathNavigator nav = doc.CreateNavigator ();
65                         nav.MoveToId ("foo");
66                 }
67
68                 [Test]
69                 public void Bug594877 ()
70                 {
71                         string data = "<rt> <objsur t=\"o\" guid=\"06974d9a-ff86-4e1c-a3e5-7ce8c961dcb9\" /> </rt>";
72                         XElement xeOldOwner = XElement.Parse(data);
73                         string xpathOld = String.Format(".//objsur[@t='o']");
74                         XElement xeOldRef = xeOldOwner.XPathSelectElement(xpathOld);
75                         Assert.AreEqual ("<objsur t='o' guid='06974d9a-ff86-4e1c-a3e5-7ce8c961dcb9' />".Replace ('\'', '"'), xeOldRef.ToString (), "#1");
76                 }
77         }
78 }