| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- //
- // XPathEditableNavigatorTests.cs
- //
- // Author:
- // Atsushi Enomoto <[email protected]>
- //
- // Copyright (C) 2005 Novell, Inc. http://www.novell.com
- //
- #if NET_2_0
- using System;
- using System.Xml;
- using System.Xml.XPath;
- using NUnit.Framework;
- namespace MonoTests.System.Xml.XPath
- {
- [TestFixture]
- public class XPathEditableNavigatorTests
- {
- private XPathNavigator GetInstance (string xml)
- {
- XmlDocument doc = new XmlDocument ();
- doc.LoadXml (xml);
- return doc.CreateNavigator ();
- }
- private static void AssertNavigator (string label, XPathNavigator nav, XPathNodeType type, string prefix, string localName, string ns, string name, string value, bool hasAttributes, bool hasChildren, bool isEmptyElement)
- {
- label += nav.GetType ();
- Assert.AreEqual (type, nav.NodeType, label + "NodeType");
- Assert.AreEqual (prefix, nav.Prefix, label + "Prefix");
- Assert.AreEqual (localName, nav.LocalName, label + "LocalName");
- Assert.AreEqual (ns, nav.NamespaceURI, label + "Namespace");
- Assert.AreEqual (name, nav.Name, label + "Name");
- Assert.AreEqual (value, nav.Value, label + "Value");
- Assert.AreEqual (hasAttributes, nav.HasAttributes, label + "HasAttributes");
- Assert.AreEqual (hasChildren, nav.HasChildren, label + "HasChildren");
- Assert.AreEqual (isEmptyElement, nav.IsEmptyElement, label + "IsEmptyElement");
- }
- [Test]
- [ExpectedException (typeof (XmlException))]
- public void AppendChildStartDocumentInvalid ()
- {
- XPathNavigator nav = GetInstance (String.Empty);
- XmlWriter w = nav.AppendChild ();
- w.WriteStartDocument ();
- w.Close ();
- }
- [Test]
- [ExpectedException (typeof (XmlException))]
- public void AppendChildStartAttributeInvalid ()
- {
- XPathNavigator nav = GetInstance (String.Empty);
- XmlWriter w = nav.AppendChild ();
- // Seems like it is just ignored.
- w.WriteStartAttribute ("test");
- w.WriteEndAttribute ();
- w.Close ();
- Assert.AreEqual (XPathNodeType.Root, nav.NodeType, "#1");
- Assert.IsFalse (nav.MoveToFirstChild (), "#2");
- }
- [Test]
- [ExpectedException (typeof (XmlException))]
- public void AppendChildElementIncomplete ()
- {
- XPathNavigator nav = GetInstance (String.Empty);
- XmlWriter w = nav.AppendChild ();
- w.WriteStartElement ("foo");
- w.Close ();
- }
- [Test]
- // empty content is allowed.
- public void AppendChildEmptyString ()
- {
- XPathNavigator nav = GetInstance ("<root/>");
- nav.MoveToFirstChild (); // root
- nav.AppendChild (String.Empty);
- }
- [Test]
- public void AppendChildElement ()
- {
- XPathNavigator nav = GetInstance ("<root/>");
- nav.MoveToFirstChild ();
- XmlWriter w = nav.AppendChild ();
- w.WriteStartElement ("foo");
- w.WriteEndElement ();
- w.Close ();
- Assert.IsTrue (nav.MoveToFirstChild ());
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "foo", // LocalName
- String.Empty, // NamespaceURI
- "foo", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- }
- [Test]
- public void AppendChildStringFragment ()
- {
- // check that the input string inherits
- // namespace context.
- XPathNavigator nav = GetInstance ("<root xmlns='urn:foo'/>");
- nav.MoveToFirstChild ();
- nav.AppendChild ("<child/>fragment<child></child>");
- Assert.IsTrue (nav.MoveToFirstChild (), "#1-1");
- AssertNavigator ("#1-2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "child", // LocalName
- "urn:foo", // NamespaceURI
- "child", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- Assert.IsFalse (nav.MoveToFirstChild (), "#2-1");
- Assert.IsTrue (nav.MoveToNext (), "#2-2");
- AssertNavigator ("#2-3", nav,
- XPathNodeType.Text,
- String.Empty, // Prefix
- String.Empty, // LocalName
- String.Empty, // NamespaceURI
- String.Empty, // Name
- "fragment", // Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#3-1");
- AssertNavigator ("#3-2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "child", // LocalName
- "urn:foo", // NamespaceURI
- "child", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- public void AppendChildStringInvalidFragment ()
- {
- XPathNavigator nav = GetInstance ("<root xmlns='urn:foo'/>");
- nav.MoveToFirstChild ();
- nav.AppendChild ("<?xml version='1.0'?><root/>");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void AppendChildToTextNode ()
- {
- XPathNavigator nav = GetInstance ("<root>text</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild ();
- XmlWriter w = nav.AppendChild ();
- }
- [Test]
- public void InsertAfter ()
- {
- XPathNavigator nav = GetInstance ("<root>test</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild ();
- nav.InsertAfter ("<blah/><doh>sample</doh>");
- AssertNavigator ("#1", nav,
- XPathNodeType.Text,
- String.Empty, // Prefix
- String.Empty, // LocalName
- String.Empty, // NamespaceURI
- String.Empty, // Name
- "test", // Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#2");
- AssertNavigator ("#2-2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "blah", // LocalName
- String.Empty, // NamespaceURI
- "blah", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#3");
- AssertNavigator ("#3-2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "doh", // LocalName
- String.Empty, // NamespaceURI
- "doh", // Name
- "sample", // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InsertAfterRoot ()
- {
- XPathNavigator nav = GetInstance ("<root/>");
- nav.InsertAfter ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InsertAfterAttribute ()
- {
- XPathNavigator nav = GetInstance ("<root a='b'/>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstAttribute ();
- nav.InsertAfter ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InsertAfterNamespace ()
- {
- XPathNavigator nav = GetInstance ("<root xmlns='urn:foo'/>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstNamespace ();
- nav.InsertAfter ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // xmlns:xml='...', which is likely to have XmlElement or XmlDocument as its node.
- public void InsertAfterNamespace2 ()
- {
- XPathNavigator nav = GetInstance ("<root />");
- nav.MoveToFirstChild ();
- nav.MoveToFirstNamespace ();
- nav.InsertAfter ();
- }
- [Test]
- // empty content is allowed.
- public void InsertAfterEmptyString ()
- {
- XPathNavigator nav = GetInstance ("<root/>");
- nav.MoveToFirstChild (); // root
- nav.InsertAfter (String.Empty);
- }
- [Test]
- public void InsertBefore ()
- {
- XPathNavigator nav = GetInstance ("<root>test</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild ();
- nav.InsertBefore ("<blah/><doh>sample</doh>");
- AssertNavigator ("#1", nav,
- XPathNodeType.Text,
- String.Empty, // Prefix
- String.Empty, // LocalName
- String.Empty, // NamespaceURI
- String.Empty, // Name
- "test", // Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToFirst (), "#2-1");
- AssertNavigator ("#2-2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "blah", // LocalName
- String.Empty, // NamespaceURI
- "blah", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#3");
- AssertNavigator ("#3-2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "doh", // LocalName
- String.Empty, // NamespaceURI
- "doh", // Name
- "sample", // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InsertBeforeRoot ()
- {
- XPathNavigator nav = GetInstance ("<root/>");
- nav.InsertBefore ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InsertBeforeAttribute ()
- {
- XPathNavigator nav = GetInstance ("<root a='b'/>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstAttribute ();
- nav.InsertBefore ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InsertBeforeNamespace ()
- {
- XPathNavigator nav = GetInstance ("<root xmlns='urn:foo'/>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstNamespace ();
- nav.InsertBefore ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // xmlns:xml='...', which is likely to have XmlElement or XmlDocument as its node.
- public void InsertBeforeNamespace2 ()
- {
- XPathNavigator nav = GetInstance ("<root />");
- nav.MoveToFirstChild ();
- nav.MoveToFirstNamespace ();
- nav.InsertBefore ();
- }
- [Test]
- // empty content is allowed.
- public void InsertBeforeEmptyString ()
- {
- XPathNavigator nav = GetInstance ("<root/>");
- nav.MoveToFirstChild (); // root
- nav.InsertBefore (String.Empty);
- }
- [Test]
- public void DeleteRange ()
- {
- XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // <foo>
- XPathNavigator end = nav.Clone ();
- end.MoveToNext (); // <next>
- end.MoveToNext (); // final
- nav.DeleteRange (end);
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "root", // LocalName
- String.Empty, // NamespaceURI
- "root", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DeleteRangeNullArg ()
- {
- XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // <foo>
- nav.DeleteRange (null);
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void DeleteRangeInvalidArg ()
- {
- XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // <foo>
- XPathNavigator end = nav.Clone ();
- end.MoveToNext (); // <next>
- end.MoveToFirstChild (); // child
- nav.DeleteRange (end);
- }
- [Test]
- public void ReplaceRange ()
- {
- XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // <foo>
- XPathNavigator end = nav.Clone ();
- end.MoveToNext (); // <next>
- XmlWriter w = nav.ReplaceRange (end);
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "foo", // LocalName
- String.Empty, // NamespaceURI
- "foo", // Name
- String.Empty, // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToParent (), "#1-2");
- w.WriteStartElement ("whoa");
- w.WriteEndElement ();
- w.Close ();
- AssertNavigator ("#2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "whoa", // LocalName
- String.Empty, // NamespaceURI
- "whoa", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#2-1");
- AssertNavigator ("#3", nav,
- XPathNodeType.Text,
- String.Empty, // Prefix
- String.Empty, // LocalName
- String.Empty, // NamespaceURI
- String.Empty, // Name
- "final", // Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void ReplaceRangeNullArg ()
- {
- XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // <foo>
- nav.ReplaceRange (null);
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void ReplaceRangeInvalidArg ()
- {
- XPathNavigator nav = GetInstance ("<root><foo><bar/><baz/></foo><next>child<tmp/></next>final</root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // <foo>
- XPathNavigator end = nav.Clone ();
- end.MoveToNext (); // <next>
- end.MoveToFirstChild (); // child
- nav.ReplaceRange (end);
- }
- [Test]
- public void PrependChildXmlReader ()
- {
- XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- XmlReader reader = new XmlTextReader (
- "<child>text</child><next_sibling/>",
- XmlNodeType.Element,
- null);
- nav.PrependChild (reader);
- XmlAssert.AssertNode ("#0",
- reader,
- XmlNodeType.None,
- 0, // Depth
- false, // IsEmptyElement
- String.Empty, // Name
- String.Empty, // Prefix
- String.Empty, // LocalName
- String.Empty, // NamespaceURI
- String.Empty, // Value
- false, // HasValue
- 0, // AttributeCount
- false); // HasAttributes
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "foo", // LocalName
- String.Empty, // NamespaceURI
- "foo", // Name
- "textexisting_child", // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToFirstChild (), "#1-2");
- AssertNavigator ("#2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "child", // LocalName
- String.Empty, // NamespaceURI
- "child", // Name
- "text", // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#2-2");
- AssertNavigator ("#3", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "next_sibling", // LocalName
- String.Empty, // NamespaceURI
- "next_sibling", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#3-2");
- AssertNavigator ("#4", nav,
- XPathNodeType.Text,
- String.Empty, // Prefix
- String.Empty, // LocalName
- String.Empty, // NamespaceURI
- String.Empty, // Name
- "existing_child",// Value
- false, // HasAttributes
- false, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void PrependChildInvalid ()
- {
- XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- XmlWriter w = nav.PrependChild ();
- w.WriteStartAttribute ("whoa");
- w.WriteEndAttribute ();
- w.Close ();
- }
- [Test]
- // empty content is allowed.
- public void PrependChildEmptyString ()
- {
- XPathNavigator nav = GetInstance ("<root><foo/><bar/><baz/></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- nav.MoveToNext (); // bar
- nav.PrependChild (String.Empty);
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "bar", // LocalName
- String.Empty, // NamespaceURI
- "bar", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- Assert.IsTrue (nav.MoveToFirst (), "#1-2");
- AssertNavigator ("#2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "foo", // LocalName
- String.Empty, // NamespaceURI
- "foo", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- }
- [Test]
- public void ReplaceSelf ()
- {
- XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- nav.ReplaceSelf ("<hijacker>hah, hah</hijacker><next/>");
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "hijacker", // LocalName
- String.Empty, // NamespaceURI
- "hijacker", // Name
- "hah, hah", // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- Assert.IsTrue (nav.MoveToNext (), "#1-2");
- AssertNavigator ("#2", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "next", // LocalName
- String.Empty, // NamespaceURI
- "next", // Name
- String.Empty, // Value
- false, // HasAttributes
- false, // HasChildren
- true); // IsEmptyElement
- }
- [Test]
- // possible internal behavior difference e.g. due to ReadNode()
- public void ReplaceSelfXmlReaderInteractive ()
- {
- XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- XmlReader xr = new XmlTextReader (
- "<hijacker>hah, hah</hijacker><next/>",
- XmlNodeType.Element,
- null);
- xr.MoveToContent ();
- nav.ReplaceSelf (xr);
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "hijacker", // LocalName
- String.Empty, // NamespaceURI
- "hijacker", // Name
- "hah, hah", // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- Assert.IsFalse (nav.MoveToNext (), "#1-2");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // empty content is not allowed
- public void ReplaceSelfEmptyString ()
- {
- XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- nav.ReplaceSelf (String.Empty);
- }
- [Test]
- public void SetValueEmptyString ()
- {
- XPathNavigator nav = GetInstance ("<root><foo>existing_child</foo></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstChild (); // foo
- nav.SetValue (String.Empty);
- AssertNavigator ("#1", nav,
- XPathNodeType.Element,
- String.Empty, // Prefix
- "foo", // LocalName
- String.Empty, // NamespaceURI
- "foo", // Name
- String.Empty, // Value
- false, // HasAttributes
- true, // HasChildren
- false); // IsEmptyElement
- }
- [Test]
- public void MoveToFollowing ()
- {
- XPathNavigator end;
- XPathNavigator nav = GetInstance ("<root><bar><foo attr='v1'><baz><foo attr='v2'/></baz></foo></bar><dummy/><foo attr='v3'></foo></root>");
- Assert.IsTrue (nav.MoveToFollowing ("foo", String.Empty), "#1");
- Assert.AreEqual ("v1", nav.GetAttribute ("attr", String.Empty), "#2");
- Assert.IsTrue (nav.MoveToFollowing ("foo", String.Empty), "#3");
- Assert.AreEqual ("v2", nav.GetAttribute ("attr", String.Empty), "#4");
- Assert.IsTrue (nav.MoveToFollowing ("foo", String.Empty), "#5");
- Assert.AreEqual ("v3", nav.GetAttribute ("attr", String.Empty), "#6");
- // round 2
- end = nav.Clone ();
- nav.MoveToRoot ();
- Assert.IsTrue (nav.MoveToFollowing ("foo", String.Empty, end), "#7");
- Assert.AreEqual ("v1", nav.GetAttribute ("attr", String.Empty), "#8");
- Assert.IsTrue (nav.MoveToFollowing ("foo", String.Empty, end), "#9");
- Assert.AreEqual ("v2", nav.GetAttribute ("attr", String.Empty), "#10");
- // end is exclusive
- Assert.IsFalse (nav.MoveToFollowing ("foo", String.Empty, end), "#11");
- // in this case it never moves to somewhere else.
- Assert.AreEqual ("v2", nav.GetAttribute ("attr", String.Empty), "#12");
- }
- [Test]
- public void MoveToFollowingFromAttribute ()
- {
- XPathNavigator nav = GetInstance ("<root a='b'><foo/></root>");
- nav.MoveToFirstChild ();
- nav.MoveToFirstAttribute ();
- // should first move to owner element and go on.
- Assert.IsTrue (nav.MoveToFollowing ("foo", String.Empty));
- }
- [Test]
- public void AppendChildInDocumentFragment ()
- {
- XmlDocumentFragment f = new XmlDocument ().CreateDocumentFragment ();
- XmlWriter w = f.CreateNavigator ().AppendChild ();
- w.WriteStartElement ("foo");
- w.WriteEndElement ();
- w.Close ();
- Assert.IsNotNull (f.FirstChild as XmlElement);
- }
- }
- }
- #endif
|