2 // System.Xml.XmlNodeTests
5 // Kral Ferch <kral_ferch@hotmail.com>
15 using NUnit.Framework;
17 namespace MonoTests.System.Xml
19 public class XmlNodeTests : TestCase
21 public XmlNodeTests () : base ("MonoTests.System.Xml.XmlNodeTests testsuite") {}
22 public XmlNodeTests (string name) : base (name) {}
32 protected override void SetUp ()
34 document = new XmlDocument ();
35 document.NodeInserted += new XmlNodeChangedEventHandler (this.EventNodeInserted);
36 document.NodeInserting += new XmlNodeChangedEventHandler (this.EventNodeInserting);
37 document.NodeRemoved += new XmlNodeChangedEventHandler (this.EventNodeRemoved);
38 document.NodeRemoving += new XmlNodeChangedEventHandler (this.EventNodeRemoving);
39 element = document.CreateElement ("foo");
40 element2 = document.CreateElement ("bar");
43 private void EventNodeInserted(Object sender, XmlNodeChangedEventArgs e)
48 private void EventNodeInserting (Object sender, XmlNodeChangedEventArgs e)
53 private void EventNodeRemoved(Object sender, XmlNodeChangedEventArgs e)
58 private void EventNodeRemoving (Object sender, XmlNodeChangedEventArgs e)
63 public void TestAppendChild ()
69 element.AppendChild (element2);
73 // Can only append to elements, documents, and attributes
76 comment = document.CreateComment ("baz");
77 comment.AppendChild (element2);
78 Fail ("Expected an InvalidOperationException to be thrown.");
80 catch (InvalidOperationException) {}
82 // Can't append a node from one document into another document.
83 XmlDocument document2 = new XmlDocument();
84 AssertEquals (1, element.ChildNodes.Count);
87 element2 = document2.CreateElement ("qux");
88 element.AppendChild (element2);
89 Fail ("Expected an ArgumentException to be thrown.");
91 catch (ArgumentException) {}
92 AssertEquals (1, element.ChildNodes.Count);
94 // Can't append to a readonly node.
95 /* TODO put this in when I figure out how to create a read-only node.
98 XmlElement element3 = (XmlElement)element.CloneNode (false);
99 Assert (!element.IsReadOnly);
100 Assert (element3.IsReadOnly);
101 element2 = document.CreateElement ("quux");
102 element3.AppendChild (element2);
103 Fail ("Expected an ArgumentException to be thrown.");
105 catch (ArgumentException) {}
109 public void saveTestRemoveAll ()
111 // TODO: put this test back in when AttributeCollection.RemoveAll() is implemented.
112 element.AppendChild(element2);
115 element.RemoveAll ();
120 public void TestRemoveChild ()
122 element.AppendChild(element2);
125 element.RemoveChild (element2);