svn path=/trunk/mcs/; revision=104772
[mono.git] / mcs / class / System.XML / Test / System.Xml.XPath / XPathEditableNavigatorTests.cs
index 9538938fba4fc2aec8bc6a1f82032e5ed4484c93..6b0d0c230ef532aa5a78480f04029e88602eba6c 100644 (file)
@@ -702,6 +702,75 @@ namespace MonoTests.System.Xml.XPath
                                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);
+               }
+
+               [Test]
+               public void CanEdit ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       Assert.IsTrue (doc.CreateNavigator ().CanEdit);
+                       Assert.IsTrue (GetInstance ("<root/>").CanEdit);
+               }
+
+               [Test]
+               public void DeleteSelfAttribute ()
+               {
+                       // bug #376210.
+                       XmlDocument document = new XmlDocument ();
+                       document.LoadXml ("<test><node date='2000-12-23'>z</node></test>");
+                       XPathNavigator navigator = document.CreateNavigator ();
+                       XPathNavigator nodeElement = navigator.SelectSingleNode ("//node");
+                       nodeElement.MoveToAttribute ("date", String.Empty);
+                       nodeElement.DeleteSelf ();
+                       Assert.AreEqual ("<test><node>z</node></test>", document.OuterXml);
+               }
        }
 }