Jelajahi Sumber

2003-04-12 Atsushi Enomoto <[email protected]>

	* added this file as a new entry.
	  See ../ChangeLog to find ChangeLog entries before than this day.

svn path=/trunk/mcs/; revision=13549
Atsushi Eno 23 tahun lalu
induk
melakukan
bef07b2478
25 mengubah file dengan 6905 tambahan dan 0 penghapusan
  1. 4 0
      mcs/class/System.XML/Test/System.Xml/ChangeLog
  2. 95 0
      mcs/class/System.XML/Test/System.Xml/NameTableTests.cs
  3. 157 0
      mcs/class/System.XML/Test/System.Xml/XmlAttributeCollectionTests.cs
  4. 136 0
      mcs/class/System.XML/Test/System.Xml/XmlAttributeTests.cs
  5. 99 0
      mcs/class/System.XML/Test/System.Xml/XmlCDataSectionTests.cs
  6. 179 0
      mcs/class/System.XML/Test/System.Xml/XmlCharacterDataTests.cs
  7. 112 0
      mcs/class/System.XML/Test/System.Xml/XmlCommentTests.cs
  8. 159 0
      mcs/class/System.XML/Test/System.Xml/XmlDeclarationTests.cs
  9. 92 0
      mcs/class/System.XML/Test/System.Xml/XmlDocumentFragmentTests.cs
  10. 925 0
      mcs/class/System.XML/Test/System.Xml/XmlDocumentTests.cs
  11. 106 0
      mcs/class/System.XML/Test/System.Xml/XmlDocumentTypeTests.cs
  12. 357 0
      mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs
  13. 32 0
      mcs/class/System.XML/Test/System.Xml/XmlEntityReferenceTests.cs
  14. 157 0
      mcs/class/System.XML/Test/System.Xml/XmlNamespaceManagerTests.cs
  15. 245 0
      mcs/class/System.XML/Test/System.Xml/XmlNodeListTests.cs
  16. 79 0
      mcs/class/System.XML/Test/System.Xml/XmlNodeReaderTests.cs
  17. 225 0
      mcs/class/System.XML/Test/System.Xml/XmlNodeTests.cs
  18. 38 0
      mcs/class/System.XML/Test/System.Xml/XmlProcessingInstructionTests.cs
  19. 889 0
      mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs
  20. 136 0
      mcs/class/System.XML/Test/System.Xml/XmlSignificantWhitespaceTests.cs
  21. 1249 0
      mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs
  22. 91 0
      mcs/class/System.XML/Test/System.Xml/XmlTextTests.cs
  23. 1016 0
      mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs
  24. 126 0
      mcs/class/System.XML/Test/System.Xml/XmlWhiteSpaceTests.cs
  25. 201 0
      mcs/class/System.XML/Test/System.Xml/XmlWriterTests.cs

+ 4 - 0
mcs/class/System.XML/Test/System.Xml/ChangeLog

@@ -0,0 +1,4 @@
+2003-04-12  Atsushi Enomoto <[email protected]>
+
+	* added this file as a new entry.
+	  See ../ChangeLog to find ChangeLog entries before than this day.

+ 95 - 0
mcs/class/System.XML/Test/System.Xml/NameTableTests.cs

@@ -0,0 +1,95 @@
+//
+// System.Xml.NameTableTests.cs
+//
+// Author: Duncan Mak ([email protected])
+// Author: Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class NameTableTests
+	{
+		NameTable table;
+		
+		[SetUp]
+		public void GetReady ()
+		{
+			table = new NameTable ();
+		}
+
+		//
+		// Tests System.Xml.NameTable.Add (string)
+		//		
+		[Test]
+		public void Add1 ()
+		{
+			string add = "add1";
+			string testAdd = table.Add (add);
+			Assertion.AssertEquals (add, testAdd);
+			Assertion.AssertSame (add, testAdd);
+		}
+
+		//
+		// Tests System.Xml.NameTable.Add (char[], int, int)
+		//		
+		[Test]
+		public void Add2 ()
+		{
+			char[] test = new char [4] { 'a', 'd', 'd', '2' };
+			int index = 0;
+			int length = 3; // "add"			
+
+			Assertion.AssertEquals ("add", table.Add (test, index, length));
+		}
+
+		//
+		// Tests System.Xml.NameTable.Get (string)
+		//
+		[Test]
+		public void Get1 ()
+		{
+			string get1 = "get1";
+			string testGet = table.Add (get1);			
+
+			Assertion.AssertEquals (table.Get (get1), testGet);
+			Assertion.AssertSame (get1, testGet );
+		}
+
+		//
+		// Tests System.Xml.NameTable.Get (char[], int, int)
+		//
+		[Test]
+		public void Get2 ()
+		{						
+			char[] test = new char [4] { 'g', 'e', 't', '2' };
+			int index = 0; 
+			int length = 3; // "get"
+			
+			string testGet = table.Add (test, index, length);			
+
+			Assertion.AssertEquals (table.Get (test, index, length), testGet);
+		}
+
+		//
+		// Tests System.Xml.NameTable.Get (char[], int, 0)
+		//
+		[Test]
+		public void Get3 ()
+		{
+			char[] test = new char [4] { 't', 'e', 's', 't' };
+			int index = 0;
+			int length = 0;
+
+			Assertion.AssertEquals (table.Get (test, index, length), String.Empty);
+		}
+	}
+}

+ 157 - 0
mcs/class/System.XML/Test/System.Xml/XmlAttributeCollectionTests.cs

@@ -0,0 +1,157 @@
+// XmlAttributeCollectionTests.cs : Tests for the XmlAttributeCollection class
+//
+// Author: Matt Hunter <[email protected]>
+// Author: Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Matt Hunter
+// (C) 2003 Martin Willemoes Hansen
+
+using System;
+using System.Xml;
+using System.Text;
+using System.IO;
+using System.Collections;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlAttributeCollectionTests
+	{
+		private XmlDocument document;
+
+		[SetUp]
+		public void GetReady()
+		{
+			document = new XmlDocument ();
+		}
+
+		[Test]
+		public void RemoveAll ()
+		{
+			StringBuilder xml = new StringBuilder ();
+			xml.Append ("<?xml version=\"1.0\" ?><library><book type=\"non-fiction\" price=\"34.95\"> ");
+			xml.Append ("<title type=\"intro\">XML Fun</title> " );
+			xml.Append ("<author>John Doe</author></book></library>");
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			XmlNodeList bookList = document.GetElementsByTagName ("book");
+			XmlNode xmlNode = bookList.Item (0);
+			XmlElement xmlElement = xmlNode as XmlElement;
+			XmlAttributeCollection attributes = xmlElement.Attributes;
+			attributes.RemoveAll ();
+			Assertion.AssertEquals ("not all attributes removed.", false, xmlElement.HasAttribute ("type"));
+		}
+
+		[Test]
+		public void Append () 
+		{
+			XmlDocument xmlDoc = new XmlDocument ();
+			XmlElement xmlEl = xmlDoc.CreateElement ("TestElement");
+			XmlAttribute xmlAttribute = xmlEl.SetAttributeNode ("attr1", "namespace1");
+			XmlNode xmlNode = xmlDoc.CreateNode (XmlNodeType.Attribute, "attr3", "namespace1");
+			XmlAttribute xmlAttribute3 = xmlNode as XmlAttribute;
+			XmlAttributeCollection attributeCol = xmlEl.Attributes;
+			xmlAttribute3 = attributeCol.Append (xmlAttribute3);
+			Assertion.AssertEquals ("attribute name not properly created.", true, xmlAttribute3.Name.Equals ("attr3"));
+			Assertion.AssertEquals ("attribute namespace not properly created.", true, xmlAttribute3.NamespaceURI.Equals ("namespace1"));
+		}
+
+		[Test]
+		public void CopyTo () 
+		{
+			XmlDocument xmlDoc = new XmlDocument ();
+			xmlDoc.LoadXml("<root a1='garnet' a2='amethyst' a3='Bloodstone' a4='diamond' a5='emerald' a6='pearl' a7='ruby' a8='sapphire' a9='moonstone' a10='opal' a11='topaz' a12='turquoize' />");
+			XmlAttributeCollection col = xmlDoc.DocumentElement.Attributes;
+			XmlAttribute[] array = new XmlAttribute[24];
+			col.CopyTo(array, 0);
+			Assertion.AssertEquals("garnet", array[0].Value);
+			Assertion.AssertEquals("moonstone", array[8].Value);
+			Assertion.AssertEquals("turquoize", array[11].Value);
+			col.CopyTo(array, 12);
+			Assertion.AssertEquals("garnet", array[12].Value);
+			Assertion.AssertEquals("moonstone", array[20].Value);
+			Assertion.AssertEquals("turquoize", array[23].Value);
+		}
+
+		[Test]
+		public void SetNamedItem ()
+		{
+			XmlDocument xmlDoc = new XmlDocument ();
+			xmlDoc.LoadXml("<root />");
+			XmlElement el = xmlDoc.DocumentElement;
+			XmlAttributeCollection col = xmlDoc.DocumentElement.Attributes;
+
+			XmlAttribute attr = xmlDoc.CreateAttribute("b3");
+			attr.Value = "bloodstone";
+			col.SetNamedItem(attr);
+			Assertion.AssertEquals("SetNamedItem.Normal", "bloodstone", el.GetAttribute("b3"));
+
+			attr = xmlDoc.CreateAttribute("b3");
+			attr.Value = "aquamaline";
+			col.SetNamedItem(attr);
+			Assertion.AssertEquals("SetNamedItem.Override", "aquamaline", el.GetAttribute("b3"));
+			Assertion.AssertEquals("SetNamedItem.Override.Count.1", 1, el.Attributes.Count);
+			Assertion.AssertEquals("SetNamedItem.Override.Count.2", 1, col.Count);
+		}
+
+		[Test]
+		public void InsertBeforeAfterPrepend () 
+		{
+			XmlDocument xmlDoc = new XmlDocument ();
+			xmlDoc.LoadXml("<root b2='amethyst' />");
+			XmlElement el = xmlDoc.DocumentElement;
+			XmlAttributeCollection col = xmlDoc.DocumentElement.Attributes;
+			XmlAttribute attr = xmlDoc.CreateAttribute("b1");
+			attr.Value = "garnet";
+			col.InsertAfter(attr, null);
+			Assertion.AssertEquals("InsertAfterNull", "garnet", el.GetAttributeNode("b1").Value);
+			Assertion.AssertEquals("InsertAfterNull.Pos", el.GetAttribute("b1"), col[0].Value);
+
+			attr = xmlDoc.CreateAttribute("b3");
+			attr.Value = "bloodstone";
+			col.InsertAfter(attr, el.GetAttributeNode("b2"));
+			Assertion.AssertEquals("InsertAfterAttr", "bloodstone", el.GetAttributeNode("b3").Value);
+			Assertion.AssertEquals("InsertAfterAttr.Pos", el.GetAttribute("b3"), col[2].Value);
+
+			attr = xmlDoc.CreateAttribute("b4");
+			attr.Value = "diamond";
+			col.InsertBefore(attr, null);
+			Assertion.AssertEquals("InsertBeforeNull", "diamond", el.GetAttributeNode("b4").Value);
+			Assertion.AssertEquals("InsertBeforeNull.Pos", el.GetAttribute("b4"), col[3].Value);
+
+			attr = xmlDoc.CreateAttribute("warning");
+			attr.Value = "mixed modern and traditional;-)";
+			col.InsertBefore(attr, el.GetAttributeNode("b1"));
+			Assertion.AssertEquals("InsertBeforeAttr", "mixed modern and traditional;-)", el.GetAttributeNode("warning").Value);
+			Assertion.AssertEquals("InsertBeforeAttr.Pos", el.GetAttributeNode("warning").Value, col[0].Value);
+
+			attr = xmlDoc.CreateAttribute("about");
+			attr.Value = "lists of birthstone.";
+			col.Prepend(attr);
+			Assertion.AssertEquals("Prepend", "lists of birthstone.", col[0].Value);
+		}
+
+		[Test]
+		public void Remove ()
+		{
+			XmlDocument xmlDoc = new XmlDocument ();
+			xmlDoc.LoadXml("<root a1='garnet' a2='amethyst' a3='bloodstone' a4='diamond' a5='emerald' a6='pearl' a7='ruby' a8='sapphire' a9='moonstone' a10='opal' a11='topaz' a12='turquoize' />");
+			XmlElement el = xmlDoc.DocumentElement;
+			XmlAttributeCollection col = el.Attributes;
+
+			// Remove
+			XmlAttribute attr = col.Remove(el.GetAttributeNode("a12"));
+			Assertion.AssertEquals("Remove", 11, col.Count);
+			Assertion.AssertEquals("Remove.Removed", "a12", attr.Name);
+
+			// RemoveAt
+			attr = col.RemoveAt(5);
+			Assertion.AssertEquals("RemoveAt", null, el.GetAttributeNode("a6"));
+			Assertion.AssertEquals("Remove.Removed", "pearl", attr.Value);
+		}
+	}
+}

+ 136 - 0
mcs/class/System.XML/Test/System.Xml/XmlAttributeTests.cs

@@ -0,0 +1,136 @@
+// XmlAttributeTests.cs : Tests for the XmlAttribute class
+//
+// Author: Mike Kestner <[email protected]>
+// Author: Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Mike Kestner
+// (C) 2003 Martin Willemoes Hansen
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlAttributeTests
+	{
+		XmlDocument doc;
+		XmlAttribute attr;
+
+		[SetUp]
+		public void GetReady()
+		{
+			doc = new XmlDocument ();
+			attr = doc.CreateAttribute ("attr1");
+			attr.Value = "val1";
+		}
+
+		[Test]
+		public void Attributes ()
+		{
+			Assertion.AssertNull (attr.Attributes);
+		}
+
+		[Test]
+		public void AttributeInnerAndOuterXml ()
+		{
+			attr = doc.CreateAttribute ("foo", "bar", "http://abc.def");
+			attr.Value = "baz";
+			Assertion.AssertEquals ("baz", attr.InnerXml);
+			Assertion.AssertEquals ("foo:bar=\"baz\"", attr.OuterXml);
+		}
+
+		[Test]
+		public void AttributeWithNoValue ()
+		{
+			XmlAttribute attribute = doc.CreateAttribute ("name");
+			Assertion.AssertEquals (String.Empty, attribute.Value);
+			Assertion.Assert (!attribute.HasChildNodes);
+			Assertion.AssertNull (attribute.FirstChild);
+			Assertion.AssertNull (attribute.LastChild);
+			Assertion.AssertEquals (0, attribute.ChildNodes.Count);
+		}
+
+		[Test]
+		public void AttributeWithValue ()
+		{
+			XmlAttribute attribute = doc.CreateAttribute ("name");
+			attribute.Value = "value";
+			Assertion.AssertEquals ("value", attribute.Value);
+			Assertion.Assert (attribute.HasChildNodes);
+			Assertion.AssertNotNull (attribute.FirstChild);
+			Assertion.AssertNotNull (attribute.LastChild);
+			Assertion.AssertEquals (1, attribute.ChildNodes.Count);
+			Assertion.AssertEquals (XmlNodeType.Text, attribute.ChildNodes [0].NodeType);
+			Assertion.AssertEquals ("value", attribute.ChildNodes [0].Value);
+		}
+
+		[Test]
+		public void HasChildNodes ()
+		{
+			Assertion.Assert (attr.HasChildNodes);
+		}
+
+		[Test]
+		public void Name ()
+		{
+			Assertion.AssertEquals ("attr1", attr.Name);
+		}
+
+		[Test]
+		public void NodeType ()
+		{
+			Assertion.AssertEquals (XmlNodeType.Attribute, attr.NodeType);
+		}
+
+		[Test]
+		public void OwnerDocument ()
+		{
+			Assertion.AssertSame (doc, attr.OwnerDocument);
+		}
+
+		[Test]
+		public void ParentNode ()
+		{
+			Assertion.AssertNull ("Attr parents not allowed", attr.ParentNode);
+		}
+
+		[Test]
+		public void Value ()
+		{
+			Assertion.AssertEquals ("val1", attr.Value);
+		}
+
+		[Test]
+		public void SetInnerTextAndXml ()
+		{
+			string original = doc.OuterXml;
+			doc.LoadXml ("<root name='value' />");
+			XmlNodeChangedEventHandler eh = new XmlNodeChangedEventHandler (OnSetInnerText);
+			try {
+				doc.DocumentElement.Attributes ["name"].InnerText = "a&b";
+				Assertion.AssertEquals ("setInnerText", "a&b", doc.DocumentElement.Attributes ["name"].Value);
+				doc.DocumentElement.Attributes ["name"].InnerXml = "a&amp;b";
+				Assertion.AssertEquals ("setInnerXml", "a&b", doc.DocumentElement.Attributes ["name"].Value);
+
+				doc.NodeChanged += eh;
+				doc.DocumentElement.Attributes ["name"].InnerText = "fire";
+				// If you failed to pass it, then the reason may be loop of event.
+				Assertion.AssertEquals ("setInnerText.Event", "event was fired", doc.DocumentElement.GetAttribute ("appended"));
+			} catch(Exception ex) {
+				Assertion.Fail(ex.Message);
+			} finally {
+				doc.LoadXml (original);
+				doc.NodeChanged -= eh;
+			}
+		}
+
+		public void OnSetInnerText (object o, XmlNodeChangedEventArgs e)
+		{
+			if(e.NewParent.Value == "fire")
+				doc.DocumentElement.SetAttribute ("appended", "event was fired");
+		}
+	}
+}

+ 99 - 0
mcs/class/System.XML/Test/System.Xml/XmlCDataSectionTests.cs

@@ -0,0 +1,99 @@
+//
+// System.Xml.XmlCDataSectionTests.cs
+//
+// Authors:
+//	Duncan Mak  ([email protected])
+//      Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlCDataSectionTests
+	{
+		XmlDocument document;
+		XmlCDataSection section;
+		XmlNode original;
+		XmlNode deep;
+		XmlNode shallow;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.LoadXml ("<root><foo></foo></root>");
+			section = document.CreateCDataSection ("CDataSection");
+		}
+
+		internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+		{
+			// Assertion.AssertEquals (original.nodetype + " was incorrectly cloned.",
+			// 		 original.baseuri, cloned.baseuri);			
+			Assertion.AssertNull (cloned.ParentNode);
+                        Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
+		}
+	       
+		[Test]
+		public void XmlCDataSectionInnerAndOuterXml ()
+		{
+			section = document.CreateCDataSection ("foo");
+			Assertion.AssertEquals (String.Empty, section.InnerXml);
+			Assertion.AssertEquals ("<![CDATA[foo]]>", section.OuterXml);
+		}
+
+		[Test]
+		public void XmlCDataSectionName ()
+		{
+			Assertion.AssertEquals (section.NodeType + " Name property broken",
+				      section.Name, "#cdata-section");
+		}
+
+		[Test]
+		public void XmlCDataSectionLocalName ()
+		{
+			Assertion.AssertEquals (section.NodeType + " LocalName property broken",
+				      section.LocalName, "#cdata-section");
+		}
+
+		[Test]
+		public void XmlCDataSectionNodeType ()
+		{
+			Assertion.AssertEquals ("XmlCDataSection NodeType property broken",
+				      section.NodeType.ToString (), "CDATA");
+		}
+
+		[Test]
+		public void XmlCDataSectionIsReadOnly ()
+		{
+			Assertion.AssertEquals ("XmlCDataSection IsReadOnly property broken",
+				      section.IsReadOnly, false);
+		}
+
+		[Test]
+		public void XmlCDataSectionCloneNode ()
+		{
+			original = section;
+
+			shallow = section.CloneNode (false); // shallow
+			XmlNodeBaseProperties (original, shallow);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				      original.Value, shallow.Value);
+			
+			deep = section.CloneNode (true); // deep
+			XmlNodeBaseProperties (original, deep);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				       original.Value, deep.Value);
+
+                        Assertion.AssertEquals ("deep cloning differs from shallow cloning",
+				      deep.OuterXml, shallow.OuterXml);
+		}
+	}
+}

+ 179 - 0
mcs/class/System.XML/Test/System.Xml/XmlCharacterDataTests.cs

@@ -0,0 +1,179 @@
+//
+// System.Xml.XmlTextWriterTests
+//
+// Author: Kral Ferch <[email protected]>
+// Author: Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlCharacterDataTests
+	{
+		XmlDocument document;
+		XmlComment comment;
+		bool changed;
+		bool changing;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
+			document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChanging);
+			comment = document.CreateComment ("foo");
+		}
+
+		private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
+		{
+			changed = true;
+		}
+
+		private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
+		{
+			changing = true;
+		}
+
+		[Test]
+		public void AppendData ()
+		{
+			changed = false;
+			changing = false;
+			comment.AppendData ("bar");
+			Assertion.Assert (changed);
+			Assertion.Assert (changing);
+			Assertion.AssertEquals ("foobar", comment.Data);
+
+			comment.Value = "foo";
+			comment.AppendData (null);
+			Assertion.AssertEquals ("foo", comment.Data);
+		}
+
+		[Test]
+		public void DeleteData ()
+		{
+			comment.Value = "bar";
+			changed = false;
+			changing = false;
+			comment.DeleteData (1, 1);
+			Assertion.Assert (changed);
+			Assertion.Assert (changing);
+			Assertion.AssertEquals ("br", comment.Data);
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.DeleteData(-1, 1);
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} 
+			catch (ArgumentOutOfRangeException) {}
+
+			comment.Value = "foo";
+			comment.DeleteData(1, 5);
+			Assertion.AssertEquals("f", comment.Data);
+
+			comment.Value = "foo";
+			comment.DeleteData(3, 10);
+			Assertion.AssertEquals("foo", comment.Data);
+		}
+
+		[Test]
+		public void InsertData ()
+		{
+			comment.Value = "foobaz";
+			changed = false;
+			changing = false;
+			comment.InsertData (3, "bar");
+			Assertion.Assert (changed);
+			Assertion.Assert (changing);
+			Assertion.AssertEquals ("foobarbaz", comment.Data);
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.InsertData (-1, "bar");
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} 
+			catch (ArgumentOutOfRangeException) {}
+
+			comment.Value = "foo";
+			comment.InsertData (3, "bar");
+			Assertion.AssertEquals ("foobar", comment.Data);
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.InsertData (4, "bar");
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} 
+			catch (ArgumentOutOfRangeException) {}
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.InsertData (1, null);
+				Assertion.Fail ("Expected an ArgumentNullException to be thrown.");
+			} 
+			catch (ArgumentNullException) {}
+		}
+
+		[Test]
+		public void ReplaceData ()
+		{
+			changed = false;
+			changing = false;
+			comment.ReplaceData (0, 3, "bar");
+			Assertion.Assert (changed);
+			Assertion.Assert (changing);
+			Assertion.AssertEquals ("bar", comment.Data);
+
+			comment.Value = "foo";
+			comment.ReplaceData (2, 3, "bar");
+			Assertion.AssertEquals ("fobar", comment.Data);
+
+			comment.Value = "foo";
+			comment.ReplaceData (3, 3, "bar");
+			Assertion.AssertEquals ("foobar", comment.Data);
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.ReplaceData (4, 3, "bar");
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} 
+			catch (ArgumentOutOfRangeException) {}
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.ReplaceData (-1, 3, "bar");
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} 
+			catch (ArgumentOutOfRangeException) {}
+
+			comment.Value = "foo";
+			comment.ReplaceData (0, 2, "bar");
+			Assertion.AssertEquals ("baro", comment.Data);
+
+			comment.Value = "foo";
+			comment.ReplaceData (0, 5, "bar");
+			Assertion.AssertEquals ("bar", comment.Data);
+
+			try 
+			{
+				comment.Value = "foo";
+				comment.ReplaceData (1, 1, null);
+				Assertion.Fail ("Expected an ArgumentNullException to be thrown.");
+			} 
+			catch (ArgumentNullException) {}
+		}
+	}
+}

+ 112 - 0
mcs/class/System.XML/Test/System.Xml/XmlCommentTests.cs

@@ -0,0 +1,112 @@
+//
+// System.Xml.XmlCommentTests.cs
+//
+// Author: Duncan Mak  ([email protected])
+// Author: Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlCommentTests
+	{
+		XmlDocument document;
+		XmlComment comment;
+		XmlNode original;
+		XmlNode deep;
+		XmlNode shallow;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+		}
+
+		[Test]
+		public void XmlCommentCloneNode ()
+		{
+			document.LoadXml ("<root><foo></foo></root>");
+			comment = document.CreateComment ("Comment");
+			original = comment;
+
+			shallow = comment.CloneNode (false); // shallow
+			XmlNodeBaseProperties (original, shallow);
+			
+			deep = comment.CloneNode (true); // deep
+			XmlNodeBaseProperties (original, deep);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				original.Value, deep.Value);
+
+			Assertion.AssertEquals ("deep cloning differs from shallow cloning",
+				deep.OuterXml, shallow.OuterXml);
+		}
+
+		[Test]
+		public void XmlCommentInnerAndOuterXml ()
+		{
+			comment = document.CreateComment ("foo");
+			Assertion.AssertEquals (String.Empty, comment.InnerXml);
+			Assertion.AssertEquals ("<!--foo-->", comment.OuterXml);
+		}
+
+		[Test]
+		public void XmlCommentIsReadOnly ()
+		{
+			document.LoadXml ("<root><foo></foo></root>");
+			comment = document.CreateComment ("Comment");
+			Assertion.AssertEquals ("XmlComment IsReadOnly property broken",
+				comment.IsReadOnly, false);
+		}
+
+		[Test]
+		public void XmlCommentLocalName ()
+		{
+			document.LoadXml ("<root><foo></foo></root>");
+			comment = document.CreateComment ("Comment");
+			Assertion.AssertEquals (comment.NodeType + " LocalName property broken",
+				      comment.LocalName, "#comment");
+		}
+
+		[Test]
+		public void XmlCommentName ()
+		{
+			document.LoadXml ("<root><foo></foo></root>");
+			comment = document.CreateComment ("Comment");
+			Assertion.AssertEquals (comment.NodeType + " Name property broken",
+				comment.Name, "#comment");
+		}
+
+		[Test]
+		public void XmlCommentNodeType ()
+		{
+			document.LoadXml ("<root><foo></foo></root>");
+			comment = document.CreateComment ("Comment");
+			Assertion.AssertEquals ("XmlComment NodeType property broken",
+				      comment.NodeType.ToString (), "Comment");
+		}
+
+		internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+		{
+			document.LoadXml ("<root><foo></foo></root>");
+			comment = document.CreateComment ("Comment");
+
+			//			assertequals (original.nodetype + " was incorrectly cloned.",
+			//				      original.baseuri, cloned.baseuri);			
+
+			Assertion.AssertNull (cloned.ParentNode);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				original.Value, cloned.Value);
+
+			Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
+		}
+       
+	}
+}

+ 159 - 0
mcs/class/System.XML/Test/System.Xml/XmlDeclarationTests.cs

@@ -0,0 +1,159 @@
+//
+// System.Xml.XmlDeclarationTests.cs
+//
+// Author: Duncan Mak  ([email protected])
+// Author: Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlDeclarationTests
+	{
+		XmlDocument document;
+		XmlDeclaration declaration;
+		
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.LoadXml ("<foo><bar></bar></foo>");
+			declaration = document.CreateXmlDeclaration ("1.0", null, null);
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			declaration = document.CreateXmlDeclaration ("1.0", null, null);
+			Assertion.AssertEquals (String.Empty, declaration.InnerXml);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?>", declaration.OuterXml);
+
+			declaration = document.CreateXmlDeclaration ("1.0", "doesn't check", null);
+			Assertion.AssertEquals (String.Empty, declaration.InnerXml);
+			Assertion.AssertEquals ("<?xml version=\"1.0\" encoding=\"doesn't check\"?>", declaration.OuterXml);
+
+			declaration = document.CreateXmlDeclaration ("1.0", null, "yes");
+			Assertion.AssertEquals (String.Empty, declaration.InnerXml);
+			Assertion.AssertEquals ("<?xml version=\"1.0\" standalone=\"yes\"?>", declaration.OuterXml);
+
+			declaration = document.CreateXmlDeclaration ("1.0", "foo", "no");
+			Assertion.AssertEquals (String.Empty, declaration.InnerXml);
+			Assertion.AssertEquals ("<?xml version=\"1.0\" encoding=\"foo\" standalone=\"no\"?>", declaration.OuterXml);
+		}
+
+		internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+		{
+//			assertequals (original.nodetype + " was incorrectly cloned.",
+//				      original.baseuri, cloned.baseuri);			
+			Assertion.AssertNull (cloned.ParentNode);
+
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				      original.Value, cloned.Value);
+			
+                        Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
+		}
+
+		[Test]
+		public void Constructor ()
+		{
+			try {
+				XmlDeclaration broken = document.CreateXmlDeclaration ("2.0", null, null);
+			} catch (ArgumentException) {
+				return;
+
+			} catch (Exception e) {
+				Assertion.Fail("first arg null, wrong exception: " + e.ToString());
+			}
+		}
+
+		[Test]
+		public void NodeType ()
+		{
+			Assertion.AssertEquals ("incorrect NodeType returned", XmlNodeType.XmlDeclaration, declaration.NodeType);
+		}
+
+		[Test]
+		public void Names ()
+		{
+			Assertion.AssertEquals ("Name is incorrect", "xml", declaration.Name);
+			Assertion.AssertEquals ("LocalName is incorrect", "xml", declaration.LocalName);
+		}
+
+		[Test]
+		public void EncodingProperty ()
+		{
+			XmlDeclaration d1 = document.CreateXmlDeclaration ("1.0", "foo", null);
+			Assertion.AssertEquals ("Encoding property", "foo", d1.Encoding);
+
+			XmlDeclaration d2 = document.CreateXmlDeclaration ("1.0", null, null);
+			Assertion.AssertEquals ("null Encoding property", String.Empty, d2.Encoding);
+		}
+
+		[Test]
+		public void StandaloneProperty ()
+		{
+			XmlDeclaration d1 = document.CreateXmlDeclaration ("1.0", null, "yes");
+			Assertion.AssertEquals ("Yes standalone property", "yes", d1.Standalone);
+
+			XmlDeclaration d2 = document.CreateXmlDeclaration ("1.0", null, "no");
+			Assertion.AssertEquals ("No standalone property", "no", d2.Standalone);
+
+			XmlDeclaration d3 = document.CreateXmlDeclaration ("1.0", null, null);
+			Assertion.AssertEquals ("null Standalone property", String.Empty, d3.Standalone);
+		}
+
+		[Test]
+		public void ValueProperty ()
+		{
+			string expected = "version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"" ;
+
+			XmlDeclaration d = document.CreateXmlDeclaration ("1.0", "ISO-8859-1", "yes");
+			Assertion.AssertEquals ("Value property", expected, d.Value);
+
+			d.Value = expected;
+			Assertion.AssertEquals ("Value round-trip", expected, d.Value);
+
+			d.Value = "   " + expected;
+			Assertion.AssertEquals ("Value round-trip (padded)", expected, d.Value);
+
+			d.Value = "version=\"1.0\"     encoding=\"ISO-8859-1\" standalone=\"yes\"" ;
+			Assertion.AssertEquals ("Value round-trip (padded 2)", expected, d.Value);
+
+			d.Value = "version=\"1.0\"\tencoding=\"ISO-8859-1\" standalone=\"yes\"" ;
+			Assertion.AssertEquals ("Value round-trip (\\t)", expected, d.Value);
+
+			d.Value = "version=\"1.0\"\n    encoding=\"ISO-8859-1\" standalone=\"yes\"" ;
+			Assertion.AssertEquals ("Value round-trip (\\n)", expected, d.Value);
+
+			d.Value = "version=\"1.0\"    encoding	=   \"ISO-8859-1\" standalone = \"yes\"" ;
+			Assertion.AssertEquals ("Value round-trip (spaces)", expected, d.Value);
+
+			d.Value = "version='1.0' encoding='ISO-8859-1' standalone='yes'" ;
+			Assertion.AssertEquals ("Value round-trip ('s)", expected, d.Value);
+
+		}
+
+		[Test]
+		public void XmlCommentCloneNode ()
+		{
+			XmlNode original = declaration;
+
+			XmlNode shallow = declaration.CloneNode (false); // shallow
+			XmlNodeBaseProperties (original, shallow);
+			
+			XmlNode deep = declaration.CloneNode (true); // deep
+			XmlNodeBaseProperties (original, deep);
+
+                        Assertion.AssertEquals ("deep cloning differs from shallow cloning",
+				      deep.OuterXml, shallow.OuterXml);
+		}
+	}
+}

+ 92 - 0
mcs/class/System.XML/Test/System.Xml/XmlDocumentFragmentTests.cs

@@ -0,0 +1,92 @@
+//
+// System.Xml.XmlDocumentFragment.cs
+//
+// Author: Atsushi Enomoto ([email protected])
+// Author: Martin Willemoes Hansen ([email protected])
+//
+// (C) 2002 Atsushi Enomoto
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlDocumentFragmentTests
+	{
+		XmlDocument document;
+		XmlDocumentFragment fragment;
+
+		[Test]
+		public void Constructor ()
+		{
+			XmlDocument d = new XmlDocument ();
+			XmlDocumentFragment df = d.CreateDocumentFragment ();
+			Assertion.AssertEquals ("#Constructor.NodeName", "#document-fragment", df.Name);
+			Assertion.AssertEquals ("#Constructor.NodeType", XmlNodeType.DocumentFragment, df.NodeType);
+		}
+
+		[Test]
+		public void AppendChildToFragment ()
+		{
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			document.LoadXml ("<html><head></head><body></body></html>");
+			XmlElement el = document.CreateElement ("p");
+			el.InnerXml = "Test Paragraph";
+
+			// appending element to fragment
+			fragment.AppendChild (el);
+			Assertion.AssertNotNull ("#AppendChildToFragment.Element", fragment.FirstChild);
+			Assertion.AssertNotNull ("#AppendChildToFragment.Element.Children", fragment.FirstChild.FirstChild);
+			Assertion.AssertEquals ("#AppendChildToFragment.Element.Child.Text", "Test Paragraph", fragment.FirstChild.FirstChild.Value);
+		}
+
+		[Test]
+		public void AppendFragmentToElement ()
+		{
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			document.LoadXml ("<html><head></head><body></body></html>");
+			XmlElement body = document.DocumentElement.LastChild as XmlElement;
+			fragment.AppendChild (document.CreateElement ("p"));
+			fragment.AppendChild (document.CreateElement ("div"));
+
+			// appending fragment to element
+			body.AppendChild (fragment);
+			Assertion.AssertNotNull ("#AppendFragmentToElement.Exist", body.FirstChild);
+			Assertion.AssertEquals ("#AppendFragmentToElement.ChildIsElement", XmlNodeType.Element, body.FirstChild.NodeType);
+			Assertion.AssertEquals ("#AppendFragmentToElement.FirstChild", "p", body.FirstChild.Name);
+			Assertion.AssertEquals ("#AppendFragmentToElement.LastChild", "div", body.LastChild.Name);
+		}
+
+		[Test]
+		public void GetInnerXml ()
+		{
+			// this will be also tests of TestWriteTo()/TestWriteContentTo()
+
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			fragment.AppendChild (document.CreateElement ("foo"));
+			fragment.AppendChild (document.CreateElement ("bar"));
+			fragment.AppendChild (document.CreateElement ("baz"));
+			Assertion.AssertEquals ("#Simple", "<foo /><bar /><baz />", fragment.InnerXml);
+		}
+
+		[Test]
+		public void SetInnerXml ()
+		{
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			fragment.InnerXml = "<foo /><bar><child /></bar><baz />";
+			Assertion.AssertEquals ("foo", fragment.FirstChild.Name);
+			Assertion.AssertEquals ("bar", fragment.FirstChild.NextSibling.Name);
+			Assertion.AssertEquals ("child", fragment.FirstChild.NextSibling.FirstChild.Name);
+			Assertion.AssertEquals ("baz", fragment.LastChild.Name);
+		}
+	}
+}

+ 925 - 0
mcs/class/System.XML/Test/System.Xml/XmlDocumentTests.cs

@@ -0,0 +1,925 @@
+
+// System.Xml.XmlDocumentTests
+//
+// Authors:
+//   Jason Diamond <[email protected]>
+//   Kral Ferch <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Jason Diamond, Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Collections;
+using System.Xml;
+using System.IO;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlDocumentTests
+	{
+		private XmlDocument document;
+		private ArrayList eventStrings = new ArrayList();
+
+		// These Event* methods support the TestEventNode* Tests in this file.
+		// Most of them are event handlers for the XmlNodeChangedEventHandler
+		// delegate.
+		private void EventStringAdd(string eventName, XmlNodeChangedEventArgs e)
+		{
+			string oldParent = (e.OldParent != null) ? e.OldParent.Name : "<none>";
+			string newParent = (e.NewParent != null) ? e.NewParent.Name : "<none>";
+			eventStrings.Add (String.Format ("{0}, {1}, {2}, {3}, {4}", eventName, e.Action.ToString (), e.Node.OuterXml, oldParent, newParent));
+		}
+
+		private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
+		{
+			EventStringAdd ("NodeChanged", e);
+		}
+
+		private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
+		{
+			EventStringAdd ("NodeChanging", e);
+		}
+
+		private void EventNodeChangingException (Object sender, XmlNodeChangedEventArgs e)
+		{
+			throw new Exception ("don't change the value.");
+		}
+
+		private void EventNodeInserted(Object sender, XmlNodeChangedEventArgs e)
+		{
+			EventStringAdd ("NodeInserted", e);
+		}
+
+		private void EventNodeInserting(Object sender, XmlNodeChangedEventArgs e)
+		{
+			EventStringAdd ("NodeInserting", e);
+		}
+
+		private void EventNodeInsertingException(Object sender, XmlNodeChangedEventArgs e)
+		{
+			throw new Exception ("don't insert the element.");
+		}
+
+		private void EventNodeRemoved(Object sender, XmlNodeChangedEventArgs e)
+		{
+			EventStringAdd ("NodeRemoved", e);
+		}
+
+		private void EventNodeRemoving(Object sender, XmlNodeChangedEventArgs e)
+		{
+			EventStringAdd ("NodeRemoving", e);
+		}
+
+		private void EventNodeRemovingException(Object sender, XmlNodeChangedEventArgs e)
+		{
+			throw new Exception ("don't remove the element.");
+		}
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.PreserveWhitespace = true;
+		}
+
+		[Test]
+		public void CreateNodeNodeTypeNameEmptyParams ()
+		{
+			XmlNode node;
+
+			try {
+				node = document.CreateNode (null, null, null);
+				Assertion.Fail ("Expected an ArgumentException to be thrown.");
+			} catch (ArgumentException) {}
+
+			try {
+				node = document.CreateNode ("attribute", null, null);
+				Assertion.Fail ("Expected a NullReferenceException to be thrown.");
+			} catch (NullReferenceException) {}
+
+			try {
+				node = document.CreateNode ("attribute", "", null);
+				Assertion.Fail ("Expected an ArgumentException to be thrown.");
+			} catch (ArgumentException) {}
+
+			try {
+				node = document.CreateNode ("element", null, null);
+				Assertion.Fail ("Expected a NullReferenceException to be thrown.");
+			} catch (NullReferenceException) {}
+
+			try {
+				node = document.CreateNode ("element", "", null);
+				Assertion.Fail ("Expected an ArgumentException to be thrown.");
+			} catch (ArgumentException) {}
+
+			try {
+				node = document.CreateNode ("entityreference", null, null);
+				Assertion.Fail ("Expected a NullReferenceException to be thrown.");
+			} catch (NullReferenceException) {}
+		}
+
+		[Test]
+		public void CreateNodeInvalidXmlNodeType ()
+		{
+			XmlNode node;
+
+			try {
+				node = document.CreateNode (XmlNodeType.EndElement, null, null);
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			try {
+				node = document.CreateNode (XmlNodeType.EndEntity, null, null);
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			try {
+				node = document.CreateNode (XmlNodeType.Entity, null, null);
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			try {
+				node = document.CreateNode (XmlNodeType.None, null, null);
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			try {
+				node = document.CreateNode (XmlNodeType.Notation, null, null);
+				Assertion.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			// TODO:  undocumented allowable type.
+			node = document.CreateNode (XmlNodeType.XmlDeclaration, null, null);
+			Assertion.AssertEquals (XmlNodeType.XmlDeclaration, node.NodeType);
+		}
+
+		[Test]
+		public void CreateNodeWhichParamIsUsed ()
+		{
+			XmlNode node;
+
+			// No constructor params for Document, DocumentFragment.
+
+			node = document.CreateNode (XmlNodeType.CDATA, "a", "b", "c");
+			Assertion.AssertEquals (String.Empty, ((XmlCDataSection)node).Value);
+
+			node = document.CreateNode (XmlNodeType.Comment, "a", "b", "c");
+			Assertion.AssertEquals (String.Empty, ((XmlComment)node).Value);
+
+			node = document.CreateNode (XmlNodeType.DocumentType, "a", "b", "c");
+			Assertion.AssertNull (((XmlDocumentType)node).Value);
+
+// TODO: add this back in to test when it's implemented.
+//			node = document.CreateNode (XmlNodeType.EntityReference, "a", "b", "c");
+//			Assertion.AssertNull (((XmlEntityReference)node).Value);
+
+			node = document.CreateNode (XmlNodeType.ProcessingInstruction, "a", "b", "c");
+			Assertion.AssertEquals (String.Empty, ((XmlProcessingInstruction)node).Value);
+
+			node = document.CreateNode (XmlNodeType.SignificantWhitespace, "a", "b", "c");
+			Assertion.AssertEquals (String.Empty, ((XmlSignificantWhitespace)node).Value);
+
+			node = document.CreateNode (XmlNodeType.Text, "a", "b", "c");
+			Assertion.AssertEquals (String.Empty, ((XmlText)node).Value);
+
+			node = document.CreateNode (XmlNodeType.Whitespace, "a", "b", "c");
+			Assertion.AssertEquals (String.Empty, ((XmlWhitespace)node).Value);
+
+			node = document.CreateNode (XmlNodeType.XmlDeclaration, "a", "b", "c");
+			Assertion.AssertEquals ("version=\"1.0\"", ((XmlDeclaration)node).Value);
+		}
+
+		[Test]
+		public void CreateNodeNodeTypeName ()
+		{
+			XmlNode node;
+
+			try {
+				node = document.CreateNode ("foo", null, null);
+				Assertion.Fail ("Expected an ArgumentException to be thrown.");
+			} catch (ArgumentException) {}
+
+			node = document.CreateNode("attribute", "foo", null);
+			Assertion.AssertEquals (XmlNodeType.Attribute, node.NodeType);
+
+			node = document.CreateNode("cdatasection", null, null);
+			Assertion.AssertEquals (XmlNodeType.CDATA, node.NodeType);
+
+			node = document.CreateNode("comment", null, null);
+			Assertion.AssertEquals (XmlNodeType.Comment, node.NodeType);
+
+			node = document.CreateNode("document", null, null);
+			Assertion.AssertEquals (XmlNodeType.Document, node.NodeType);
+			// TODO: test which constructor this ended up calling,
+			// i.e. reuse underlying NameTable or not?
+
+// TODO: add this back in to test when it's implemented.
+//			node = document.CreateNode("documentfragment", null, null);
+//			Assertion.AssertEquals (XmlNodeType.DocumentFragment, node.NodeType);
+
+			node = document.CreateNode("documenttype", null, null);
+			Assertion.AssertEquals (XmlNodeType.DocumentType, node.NodeType);
+
+			node = document.CreateNode("element", "foo", null);
+			Assertion.AssertEquals (XmlNodeType.Element, node.NodeType);
+
+// TODO: add this back in to test when it's implemented.
+//			node = document.CreateNode("entityreference", "foo", null);
+//			Assertion.AssertEquals (XmlNodeType.EntityReference, node.NodeType);
+
+			node = document.CreateNode("processinginstruction", null, null);
+			Assertion.AssertEquals (XmlNodeType.ProcessingInstruction, node.NodeType);
+
+			node = document.CreateNode("significantwhitespace", null, null);
+			Assertion.AssertEquals (XmlNodeType.SignificantWhitespace, node.NodeType);
+
+			node = document.CreateNode("text", null, null);
+			Assertion.AssertEquals (XmlNodeType.Text, node.NodeType);
+
+			node = document.CreateNode("whitespace", null, null);
+			Assertion.AssertEquals (XmlNodeType.Whitespace, node.NodeType);
+		}
+
+		[Test]
+		public void DocumentElement ()
+		{
+			Assertion.AssertNull (document.DocumentElement);
+			XmlElement element = document.CreateElement ("foo", "bar", "http://foo/");
+			Assertion.AssertNotNull (element);
+
+			Assertion.AssertEquals ("foo", element.Prefix);
+			Assertion.AssertEquals ("bar", element.LocalName);
+			Assertion.AssertEquals ("http://foo/", element.NamespaceURI);
+
+			Assertion.AssertEquals ("foo:bar", element.Name);
+
+			Assertion.AssertSame (element, document.AppendChild (element));
+
+			Assertion.AssertSame (element, document.DocumentElement);
+		}
+
+		[Test]
+		public void DocumentEmpty()
+		{
+			Assertion.AssertEquals ("Incorrect output for empty document.", "", document.OuterXml);
+		}
+
+		[Test]
+		public void EventNodeChanged()
+		{
+			XmlElement element;
+			XmlComment comment;
+
+			document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
+
+			// Node that is part of the document.
+			document.AppendChild (document.CreateElement ("foo"));
+			comment = document.CreateComment ("bar");
+			document.DocumentElement.AppendChild (comment);
+			Assertion.AssertEquals ("<!--bar-->", document.DocumentElement.InnerXml);
+			comment.Value = "baz";
+			Assertion.Assert (eventStrings.Contains ("NodeChanged, Change, <!--baz-->, foo, foo"));
+			Assertion.AssertEquals ("<!--baz-->", document.DocumentElement.InnerXml);
+
+			// Node that isn't part of the document but created by the document.
+			element = document.CreateElement ("foo");
+			comment = document.CreateComment ("bar");
+			element.AppendChild (comment);
+			Assertion.AssertEquals ("<!--bar-->", element.InnerXml);
+			comment.Value = "baz";
+			Assertion.Assert (eventStrings.Contains ("NodeChanged, Change, <!--baz-->, foo, foo"));
+			Assertion.AssertEquals ("<!--baz-->", element.InnerXml);
+
+/*
+ TODO:  Insert this when XmlNode.InnerText() and XmlNode.InnerXml() have been implemented.
+ 
+			// Node that is part of the document.
+			element = document.CreateElement ("foo");
+			element.InnerText = "bar";
+			document.AppendChild(element);
+			element.InnerText = "baz";
+			Assertion.Assert(eventStrings.Contains("NodeChanged, Change, baz, foo, foo"));
+			
+			// Node that isn't part of the document but created by the document.
+			element = document.CreateElement("qux");
+			element.InnerText = "quux";
+			element.InnerText = "quuux";
+			Assertion.Assert(eventStrings.Contains("NodeChanged, Change, quuux, qux, qux"));
+*/
+		}
+
+		[Test]
+		public void EventNodeChanging()
+		{
+			XmlElement element;
+			XmlComment comment;
+
+			document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChanging);
+
+			// Node that is part of the document.
+			document.AppendChild (document.CreateElement ("foo"));
+			comment = document.CreateComment ("bar");
+			document.DocumentElement.AppendChild (comment);
+			Assertion.AssertEquals ("<!--bar-->", document.DocumentElement.InnerXml);
+			comment.Value = "baz";
+			Assertion.Assert (eventStrings.Contains ("NodeChanging, Change, <!--bar-->, foo, foo"));
+			Assertion.AssertEquals ("<!--baz-->", document.DocumentElement.InnerXml);
+
+			// Node that isn't part of the document but created by the document.
+			element = document.CreateElement ("foo");
+			comment = document.CreateComment ("bar");
+			element.AppendChild (comment);
+			Assertion.AssertEquals ("<!--bar-->", element.InnerXml);
+			comment.Value = "baz";
+			Assertion.Assert (eventStrings.Contains ("NodeChanging, Change, <!--bar-->, foo, foo"));
+			Assertion.AssertEquals ("<!--baz-->", element.InnerXml);
+
+			// If an exception is thrown the Document returns to original state.
+			document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChangingException);
+			element = document.CreateElement("foo");
+			comment = document.CreateComment ("bar");
+			element.AppendChild (comment);
+			Assertion.AssertEquals ("<!--bar-->", element.InnerXml);
+			try 
+			{
+				comment.Value = "baz";
+				Assertion.Fail("Expected an exception to be thrown by the NodeChanging event handler method EventNodeChangingException().");
+			} catch (Exception) {}
+			Assertion.AssertEquals ("<!--bar-->", element.InnerXml);
+
+			// Yes it's a bit anal but this tests whether the node changing event exception fires before the
+			// ArgumentOutOfRangeException.  Turns out it does so that means our implementation needs to raise
+			// the node changing event before doing any work.
+			try 
+			{
+				comment.ReplaceData(-1, 0, "qux");
+				Assertion.Fail("Expected an ArgumentOutOfRangeException to be thrown.");
+			} 
+			catch (Exception) {}
+
+			/*
+ TODO:  Insert this when XmlNode.InnerText() and XmlNode.InnerXml() have been implemented.
+ 
+			// Node that is part of the document.
+			element = document.CreateElement ("foo");
+			element.InnerText = "bar";
+			document.AppendChild(element);
+			element.InnerText = "baz";
+			Assertion.Assert(eventStrings.Contains("NodeChanging, Change, bar, foo, foo"));
+
+			// Node that isn't part of the document but created by the document.
+			element = document.CreateElement("foo");
+			element.InnerText = "bar";
+			element.InnerText = "baz";
+			Assertion.Assert(eventStrings.Contains("NodeChanging, Change, bar, foo, foo"));
+
+			// If an exception is thrown the Document returns to original state.
+			document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChangingException);
+			element = document.CreateElement("foo");
+			element.InnerText = "bar";
+			try {
+				element.InnerText = "baz";
+				Assertion.Fail("Expected an exception to be thrown by the NodeChanging event handler method EventNodeChangingException().");
+			} catch (Exception) {}
+			Assertion.AssertEquals("bar", element.InnerText);
+*/
+		}
+
+		[Test]
+		public void EventNodeInserted()
+		{
+			XmlElement element;
+
+			document.NodeInserted += new XmlNodeChangedEventHandler (this.EventNodeInserted);
+
+			// Inserted 'foo' element to the document.
+			element = document.CreateElement ("foo");
+			document.AppendChild (element);
+			Assertion.Assert (eventStrings.Contains ("NodeInserted, Insert, <foo />, <none>, #document"));
+
+			// Append child on node in document
+			element = document.CreateElement ("foo");
+			document.DocumentElement.AppendChild (element);
+			Assertion.Assert (eventStrings.Contains ("NodeInserted, Insert, <foo />, <none>, foo"));
+
+			// Append child on node not in document but created by document
+			element = document.CreateElement ("bar");
+			element.AppendChild(document.CreateElement ("bar"));
+			Assertion.Assert(eventStrings.Contains("NodeInserted, Insert, <bar />, <none>, bar"));
+		}
+
+		[Test]
+		public void EventNodeInserting()
+		{
+			XmlElement element;
+
+			document.NodeInserting += new XmlNodeChangedEventHandler (this.EventNodeInserting);
+
+			// Inserting 'foo' element to the document.
+			element = document.CreateElement ("foo");
+			document.AppendChild (element);
+			Assertion.Assert (eventStrings.Contains ("NodeInserting, Insert, <foo />, <none>, #document"));
+
+			// Append child on node in document
+			element = document.CreateElement ("foo");
+			document.DocumentElement.AppendChild (element);
+			Assertion.Assert(eventStrings.Contains ("NodeInserting, Insert, <foo />, <none>, foo"));
+
+			// Append child on node not in document but created by document
+			element = document.CreateElement ("bar");
+			Assertion.AssertEquals (0, element.ChildNodes.Count);
+			element.AppendChild (document.CreateElement ("bar"));
+			Assertion.Assert (eventStrings.Contains ("NodeInserting, Insert, <bar />, <none>, bar"));
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+
+			// If an exception is thrown the Document returns to original state.
+			document.NodeInserting += new XmlNodeChangedEventHandler (this.EventNodeInsertingException);
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+			try 
+			{
+				element.AppendChild (document.CreateElement("baz"));
+				Assertion.Fail ("Expected an exception to be thrown by the NodeInserting event handler method EventNodeInsertingException().");
+			} 
+			catch (Exception) {}
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+		}
+
+		[Test]
+		public void EventNodeRemoved()
+		{
+			XmlElement element;
+			XmlElement element2;
+
+			document.NodeRemoved += new XmlNodeChangedEventHandler (this.EventNodeRemoved);
+
+			// Removed 'bar' element from 'foo' outside document.
+			element = document.CreateElement ("foo");
+			element2 = document.CreateElement ("bar");
+			element.AppendChild (element2);
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+			element.RemoveChild (element2);
+			Assertion.Assert (eventStrings.Contains ("NodeRemoved, Remove, <bar />, foo, <none>"));
+			Assertion.AssertEquals (0, element.ChildNodes.Count);
+
+/*
+ * TODO:  put this test back in when AttributeCollection.RemoveAll() is implemented.
+
+			// RemoveAll.
+			element = document.CreateElement ("foo");
+			element2 = document.CreateElement ("bar");
+			element.AppendChild(element2);
+			Assertion.AssertEquals(1, element.ChildNodes.Count);
+			element.RemoveAll();
+			Assertion.Assert (eventStrings.Contains ("NodeRemoved, Remove, <bar />, foo, <none>"));
+			Assertion.AssertEquals(0, element.ChildNodes.Count);
+*/
+
+			// Removed 'bar' element from 'foo' inside document.
+			element = document.CreateElement ("foo");
+			document.AppendChild (element);
+			element = document.CreateElement ("bar");
+			document.DocumentElement.AppendChild (element);
+			Assertion.AssertEquals (1, document.DocumentElement.ChildNodes.Count);
+			document.DocumentElement.RemoveChild (element);
+			Assertion.Assert (eventStrings.Contains ("NodeRemoved, Remove, <bar />, foo, <none>"));
+			Assertion.AssertEquals (0, document.DocumentElement.ChildNodes.Count);
+		}
+	
+		[Test]
+		public void EventNodeRemoving()
+		{
+			XmlElement element;
+			XmlElement element2;
+
+			document.NodeRemoving += new XmlNodeChangedEventHandler (this.EventNodeRemoving);
+
+			// Removing 'bar' element from 'foo' outside document.
+			element = document.CreateElement ("foo");
+			element2 = document.CreateElement ("bar");
+			element.AppendChild (element2);
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+			element.RemoveChild (element2);
+			Assertion.Assert (eventStrings.Contains ("NodeRemoving, Remove, <bar />, foo, <none>"));
+			Assertion.AssertEquals (0, element.ChildNodes.Count);
+
+/*
+ * TODO:  put this test back in when AttributeCollection.RemoveAll() is implemented.
+
+			// RemoveAll.
+			element = document.CreateElement ("foo");
+			element2 = document.CreateElement ("bar");
+			element.AppendChild(element2);
+			Assertion.AssertEquals(1, element.ChildNodes.Count);
+			element.RemoveAll();
+			Assertion.Assert (eventStrings.Contains ("NodeRemoving, Remove, <bar />, foo, <none>"));
+			Assertion.AssertEquals(0, element.ChildNodes.Count);
+*/
+
+			// Removing 'bar' element from 'foo' inside document.
+			element = document.CreateElement ("foo");
+			document.AppendChild (element);
+			element = document.CreateElement ("bar");
+			document.DocumentElement.AppendChild (element);
+			Assertion.AssertEquals (1, document.DocumentElement.ChildNodes.Count);
+			document.DocumentElement.RemoveChild (element);
+			Assertion.Assert (eventStrings.Contains ("NodeRemoving, Remove, <bar />, foo, <none>"));
+			Assertion.AssertEquals (0, document.DocumentElement.ChildNodes.Count);
+
+			// If an exception is thrown the Document returns to original state.
+			document.NodeRemoving += new XmlNodeChangedEventHandler (this.EventNodeRemovingException);
+			element.AppendChild (element2);
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+			try 
+			{
+				element.RemoveChild(element2);
+				Assertion.Fail ("Expected an exception to be thrown by the NodeRemoving event handler method EventNodeRemovingException().");
+			} 
+			catch (Exception) {}
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+		}
+
+		[Test]
+		public void GetElementsByTagNameNoNameSpace ()
+		{
+			string xml = @"<library><book><title>XML Fun</title><author>John Doe</author>
+				<price>34.95</price></book><book><title>Bear and the Dragon</title>
+				<author>Tom Clancy</author><price>6.95</price></book><book>
+				<title>Bourne Identity</title><author>Robert Ludlum</author>
+				<price>9.95</price></book><Fluffer><Nutter><book>
+				<title>Bourne Ultimatum</title><author>Robert Ludlum</author>
+				<price>9.95</price></book></Nutter></Fluffer></library>";
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			XmlNodeList bookList = document.GetElementsByTagName ("book");
+			Assertion.AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count);
+		}
+
+		[Test]
+		public void GetElementsByTagNameUsingNameSpace ()
+		{
+			StringBuilder xml = new StringBuilder ();
+			xml.Append ("<?xml version=\"1.0\" ?><library xmlns:North=\"http://www.foo.com\" ");
+			xml.Append ("xmlns:South=\"http://www.goo.com\"><North:book type=\"non-fiction\"> ");
+			xml.Append ("<North:title type=\"intro\">XML Fun</North:title> " );
+			xml.Append ("<North:author>John Doe</North:author> " );
+			xml.Append ("<North:price>34.95</North:price></North:book> " );
+			xml.Append ("<South:book type=\"fiction\"> " );
+			xml.Append ("<South:title>Bear and the Dragon</South:title> " );
+			xml.Append ("<South:author>Tom Clancy</South:author> " );
+                        xml.Append ("<South:price>6.95</South:price></South:book> " );
+			xml.Append ("<South:book type=\"fiction\"><South:title>Bourne Identity</South:title> " );
+			xml.Append ("<South:author>Robert Ludlum</South:author> " );
+			xml.Append ("<South:price>9.95</South:price></South:book></library>");
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			XmlNodeList bookList = document.GetElementsByTagName ("book", "http://www.goo.com");
+			Assertion.AssertEquals ("GetElementsByTagName (string, uri) returned incorrect count.", 2, bookList.Count);
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			Assertion.AssertEquals (String.Empty, document.InnerXml);
+			Assertion.AssertEquals (document.InnerXml, document.OuterXml);
+
+			XmlDeclaration declaration = document.CreateXmlDeclaration ("1.0", null, null);
+			document.AppendChild (declaration);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?>", document.InnerXml);
+			Assertion.AssertEquals (document.InnerXml, document.OuterXml);
+
+			XmlElement element = document.CreateElement ("foo");
+			document.AppendChild (element);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?><foo />", document.InnerXml);
+			Assertion.AssertEquals (document.InnerXml, document.OuterXml);
+
+			XmlComment comment = document.CreateComment ("bar");
+			document.DocumentElement.AppendChild (comment);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?><foo><!--bar--></foo>", document.InnerXml);
+			Assertion.AssertEquals (document.InnerXml, document.OuterXml);
+
+			XmlText text = document.CreateTextNode ("baz");
+			document.DocumentElement.AppendChild (text);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?><foo><!--bar-->baz</foo>", document.InnerXml);
+			Assertion.AssertEquals (document.InnerXml, document.OuterXml);
+
+			element = document.CreateElement ("quux");
+			element.SetAttribute ("quuux", "squonk");
+			document.DocumentElement.AppendChild (element);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?><foo><!--bar-->baz<quux quuux=\"squonk\" /></foo>", document.InnerXml);
+			Assertion.AssertEquals (document.InnerXml, document.OuterXml);
+		}
+
+		[Test]
+		public void LoadWithSystemIOStream ()
+		{			
+			string xml = @"<library><book><title>XML Fun</title><author>John Doe</author>
+				<price>34.95</price></book><book><title>Bear and the Dragon</title>
+				<author>Tom Clancy</author><price>6.95</price></book><book>
+				<title>Bourne Identity</title><author>Robert Ludlum</author>
+				<price>9.95</price></book><Fluffer><Nutter><book>
+				<title>Bourne Ultimatum</title><author>Robert Ludlum</author>
+				<price>9.95</price></book></Nutter></Fluffer></library>";
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			Assertion.AssertEquals ("Not Loaded From IOStream", true, document.HasChildNodes);
+		}
+
+		[Test]
+		public void LoadXmlCDATA ()
+		{
+			document.LoadXml ("<foo><![CDATA[bar]]></foo>");
+			Assertion.Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.CDATA);
+			Assertion.AssertEquals ("bar", document.DocumentElement.FirstChild.Value);
+		}
+
+		[Test]
+		public void LoadXMLComment()
+		{
+// XmlTextReader needs to throw this exception
+//			try {
+//				document.LoadXml("<!--foo-->");
+//				Assertion.Fail("XmlException should have been thrown.");
+//			}
+//			catch (XmlException e) {
+//				Assertion.AssertEquals("Exception message doesn't match.", "The root element is missing.", e.Message);
+//			}
+
+			document.LoadXml ("<foo><!--Comment--></foo>");
+			Assertion.Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.Comment);
+			Assertion.AssertEquals ("Comment", document.DocumentElement.FirstChild.Value);
+
+			document.LoadXml (@"<foo><!--bar--></foo>");
+			Assertion.AssertEquals ("Incorrect target.", "bar", ((XmlComment)document.FirstChild.FirstChild).Data);
+		}
+
+		[Test]
+		public void LoadXmlElementSingle ()
+		{
+			Assertion.AssertNull (document.DocumentElement);
+			document.LoadXml ("<foo/>");
+
+			Assertion.AssertNotNull (document.DocumentElement);
+			Assertion.AssertSame (document.FirstChild, document.DocumentElement);
+
+			Assertion.AssertEquals (String.Empty, document.DocumentElement.Prefix);
+			Assertion.AssertEquals ("foo", document.DocumentElement.LocalName);
+			Assertion.AssertEquals (String.Empty, document.DocumentElement.NamespaceURI);
+			Assertion.AssertEquals ("foo", document.DocumentElement.Name);
+		}
+
+		[Test]
+		public void LoadXmlElementWithAttributes ()
+		{
+			Assertion.AssertNull (document.DocumentElement);
+			document.LoadXml ("<foo bar='baz' quux='quuux' hoge='hello &amp; world' />");
+
+			XmlElement documentElement = document.DocumentElement;
+
+			Assertion.AssertEquals ("baz", documentElement.GetAttribute ("bar"));
+			Assertion.AssertEquals ("quuux", documentElement.GetAttribute ("quux"));
+			Assertion.AssertEquals ("hello & world", documentElement.GetAttribute ("hoge"));
+			Assertion.AssertEquals ("hello & world", documentElement.Attributes ["hoge"].Value);
+			Assertion.AssertEquals (1, documentElement.GetAttributeNode ("hoge").ChildNodes.Count);
+		}
+
+		[Test]
+		public void LoadXmlElementWithChildElement ()
+		{
+			document.LoadXml ("<foo><bar/></foo>");
+			Assertion.Assert (document.ChildNodes.Count == 1);
+			Assertion.Assert (document.FirstChild.ChildNodes.Count == 1);
+			Assertion.AssertEquals ("foo", document.DocumentElement.LocalName);
+			Assertion.AssertEquals ("bar", document.DocumentElement.FirstChild.LocalName);
+		}
+
+		[Test]
+		public void LoadXmlElementWithTextNode ()
+		{
+			document.LoadXml ("<foo>bar</foo>");
+			Assertion.Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.Text);
+			Assertion.AssertEquals ("bar", document.DocumentElement.FirstChild.Value);
+		}
+
+		[Test]
+		public void LoadXmlExceptionClearsDocument ()
+		{
+			document.LoadXml ("<foo/>");
+			Assertion.Assert (document.FirstChild != null);
+			
+			try {
+				document.LoadXml ("<123/>");
+				Assertion.Fail ("An XmlException should have been thrown.");
+			} catch (XmlException) {}
+
+			Assertion.Assert (document.FirstChild == null);
+		}
+
+		[Test]
+		public void LoadXmlProcessingInstruction ()
+		{
+			document.LoadXml (@"<?foo bar='baaz' quux='quuux'?><quuuux></quuuux>");
+			Assertion.AssertEquals ("Incorrect target.", "foo", ((XmlProcessingInstruction)document.FirstChild).Target);
+			Assertion.AssertEquals ("Incorrect data.", "bar='baaz' quux='quuux'", ((XmlProcessingInstruction)document.FirstChild).Data);
+		}
+
+		[Test]
+		public void OuterXml ()
+		{
+			string xml;
+			
+			xml = "<root><![CDATA[foo]]></root>";
+			document.LoadXml (xml);
+			Assertion.AssertEquals("XmlDocument with cdata OuterXml is incorrect.", xml, document.OuterXml);
+
+			xml = "<root><!--foo--></root>";
+			document.LoadXml (xml);
+			Assertion.AssertEquals("XmlDocument with comment OuterXml is incorrect.", xml, document.OuterXml);
+
+			xml = "<root><?foo bar?></root>";
+			document.LoadXml (xml);
+			Assertion.AssertEquals("XmlDocument with processing instruction OuterXml is incorrect.", xml, document.OuterXml);
+		}
+
+		[Test]
+		public void ParentNodes ()
+		{
+			document.LoadXml ("<foo><bar><baz/></bar></foo>");
+			XmlNode node = document.FirstChild.FirstChild.FirstChild;
+			Assertion.AssertEquals ("Wrong child found.", "baz", node.LocalName);
+			Assertion.AssertEquals ("Wrong parent.", "bar", node.ParentNode.LocalName);
+			Assertion.AssertEquals ("Wrong parent.", "foo", node.ParentNode.ParentNode.LocalName);
+			Assertion.AssertEquals ("Wrong parent.", "#document", node.ParentNode.ParentNode.ParentNode.LocalName);
+			Assertion.AssertNull ("Expected parent to be null.", node.ParentNode.ParentNode.ParentNode.ParentNode);
+		}
+
+		[Test]
+		public void RemovedElementNextSibling ()
+		{
+			XmlNode node;
+			XmlNode nextSibling;
+
+			document.LoadXml ("<foo><child1/><child2/></foo>");
+			node = document.DocumentElement.FirstChild;
+			document.DocumentElement.RemoveChild (node);
+			nextSibling = node.NextSibling;
+			Assertion.AssertNull ("Expected removed node's next sibling to be null.", nextSibling);
+		}
+
+		// ImportNode
+		[Test]
+		public void ImportNode ()
+		{
+			XmlNode n;
+
+			string xlinkURI = "http://www.w3.org/1999/XLink";
+			string xml1 = "<?xml version='1.0' encoding='utf-8' ?><foo xmlns:xlink='" + xlinkURI + "'><bar a1='v1' xlink:href='#foo'><baz><![CDATA[cdata section.\n\titem 1\n\titem 2\n]]>From here, simple text node.</baz></bar></foo>";
+			document.LoadXml(xml1);
+			XmlDocument newDoc = new XmlDocument();
+			newDoc.LoadXml("<hoge><fuga /></hoge>");
+			XmlElement bar = document.DocumentElement.FirstChild as XmlElement;
+
+			// Attribute
+			n = newDoc.ImportNode(bar.GetAttributeNode("href", xlinkURI), true);
+			Assertion.AssertEquals("#ImportNode.Attr.NS.LocalName", "href", n.LocalName);
+			Assertion.AssertEquals("#ImportNode.Attr.NS.NSURI", xlinkURI, n.NamespaceURI);
+			Assertion.AssertEquals("#ImportNode.Attr.NS.Value", "#foo", n.Value);
+
+			// CDATA
+			n = newDoc.ImportNode(bar.FirstChild.FirstChild, true);
+			Assertion.AssertEquals("#ImportNode.CDATA", "cdata section.\n\titem 1\n\titem 2\n", n.Value);
+
+			// Element
+			XmlElement e = newDoc.ImportNode(bar, true) as XmlElement;
+			Assertion.AssertEquals("#ImportNode.Element.Name", "bar", e.Name);
+			Assertion.AssertEquals("#ImportNode.Element.Attr", "#foo", e.GetAttribute("href", xlinkURI));
+			Assertion.AssertEquals("#ImportNode.Element.deep", "baz", e.FirstChild.Name);
+
+			// Entity Reference:
+			//   [2002/10/14] CreateEntityReference was not implemented.
+//			document.LoadXml("<!DOCTYPE test PUBLIC 'dummy' [<!ENTITY FOOENT 'foo'>]><root>&FOOENT;</root>");
+//			n = newDoc.ImportNode(document.DocumentElement.FirstChild);
+//			Assertion.AssertEquals("#ImportNode.EntityReference", "FOOENT", n.Name);
+//			Assertion.AssertEquals("#ImportNode.EntityReference", "foo_", n.Value);
+
+			// Processing Instruction
+			document.LoadXml("<foo><?xml-stylesheet href='foo.xsl' ?></foo>");
+			XmlProcessingInstruction pi = (XmlProcessingInstruction)newDoc.ImportNode(document.DocumentElement.FirstChild, false);
+			Assertion.AssertEquals("#ImportNode.ProcessingInstruction.Name", "xml-stylesheet", pi.Name);
+			Assertion.AssertEquals("#ImportNode.ProcessingInstruction.Data", "href='foo.xsl'", pi.Data.Trim());
+			
+			// Text
+			document.LoadXml(xml1);
+			n = newDoc.ImportNode((XmlText)bar.FirstChild.ChildNodes[1], true);
+			Assertion.AssertEquals("#ImportNode.Text", "From here, simple text node.", n.Value);
+
+			// XmlDeclaration
+			document.LoadXml(xml1);
+			XmlDeclaration decl = (XmlDeclaration)newDoc.ImportNode(document.FirstChild, false);
+			Assertion.AssertEquals("#ImportNode.XmlDeclaration.Type", XmlNodeType.XmlDeclaration, decl.NodeType);
+			Assertion.AssertEquals("#ImportNode.XmlDeclaration.Encoding", "utf-8", decl.Encoding);
+		}
+
+		[Test]
+		public void NameTable()
+		{
+			XmlDocument doc = new XmlDocument();
+			Assertion.AssertNotNull(doc.NameTable);
+		}
+
+		[Test]
+		public void SingleEmptyRootDocument()
+		{
+			XmlDocument doc = new XmlDocument();
+			doc.LoadXml("<root />");
+			Assertion.AssertNotNull(doc.DocumentElement);
+		}
+
+		[Test]
+		public void DocumentWithDoctypeDecl ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			try {
+				doc.LoadXml ("<!DOCTYPE test><root />");
+			} catch (XmlException) {
+				Assertion.Fail ("#DoctypeDecl.OnlyName");
+			}
+#if NetworkEnabled
+			try 
+			{
+				doc.LoadXml ("<!DOCTYPE test SYSTEM 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><root />");
+			} catch (XmlException) {
+				Assertion.Fail("#DoctypeDecl.System");
+			}
+			try {
+				doc.LoadXml ("<!DOCTYPE test PUBLIC '-//test' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><root />");
+			} catch (XmlException) {
+				Assertion.Fail ("#DoctypeDecl.Public");
+			}
+#endif
+			// Should this be commented out?
+			try {
+				doc.LoadXml ("<!DOCTYPE test [<!ELEMENT foo >]><root />");
+			} catch (XmlException) {
+				Assertion.Fail("#DoctypeDecl.ElementDecl");
+			}
+		}
+
+		[Test]
+		public void CloneNode ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<foo><bar /><baz hoge='fuga'>TEST Text</baz></foo>");
+			XmlDocument doc2 = (XmlDocument)doc.CloneNode (false);
+			Assertion.AssertEquals ("ShallowCopy", 0, doc2.ChildNodes.Count);
+			doc2 = (XmlDocument)doc.CloneNode (true);
+			Assertion.AssertEquals ("DeepCopy", "foo", doc2.DocumentElement.Name);
+		}
+
+		[Test]
+		public void OuterXmlWithDefaultXmlns ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<iq type=\"get\" id=\"ATECLIENT_1\"><query xmlns=\"jabber:iq:auth\"><username></username></query></iq>");
+			Assertion.AssertEquals ("<iq type=\"get\" id=\"ATECLIENT_1\"><query xmlns=\"jabber:iq:auth\"><username /></query></iq>", doc.OuterXml);
+		}
+
+		[Test]
+		public void PreserveWhitespace ()
+		{
+			string input = 
+				"<?xml version=\"1.0\" encoding=\"utf-8\" ?><!-- --> <foo/>";
+
+			XmlDocument dom = new XmlDocument ();
+			XmlTextReader reader = new XmlTextReader (new StringReader (input));
+			dom.Load (reader);
+
+			Assertion.AssertEquals (XmlNodeType.Element, dom.FirstChild.NextSibling.NextSibling.NodeType);
+		}
+
+//		[Test]  Comment out in the meantime.
+		public void LoadExternalUri ()
+		{
+			// set any URL of well-formed XML.
+			document.Load ("http://www.go-mono.com/index.rss");
+		}
+
+		[Test]
+		public void LoadDocumentWithIgnoreSection ()
+		{
+			// set any URL of well-formed XML.
+			document.Load ("xmlfiles/test.xml");
+		}
+	}
+}

+ 106 - 0
mcs/class/System.XML/Test/System.Xml/XmlDocumentTypeTests.cs

@@ -0,0 +1,106 @@
+//
+// System.Xml.XmlDocumentTypeTests.cs
+//
+// Author: Duncan Mak  ([email protected])
+// Author: Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlDocumentTypeTests
+	{
+		XmlDocument document;
+		XmlDocumentType docType;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			docType = document.CreateDocumentType ("book", null, null, "<!ELEMENT book ANY>");
+			document.AppendChild (docType);
+		}
+
+		internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+		{
+//			assertequals (original.nodetype + " was incorrectly cloned.",
+//				      original.baseuri, cloned.baseuri);			
+
+			Assertion.AssertNull (cloned.ParentNode);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				      original.Value, cloned.Value);
+
+                        Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (original, cloned));
+		}
+
+		[Test]
+		public void Name ()
+		{
+			Assertion.AssertEquals ("Getting Name property", "book", docType.Name);
+		}
+
+		[Test]
+		public void LocalName ()
+		{
+			Assertion.AssertEquals ("Getting LocalName property", "book", docType.LocalName);
+		}
+
+		[Test]
+		public void InternalSubset ()
+		{
+			Assertion.AssertEquals ("Getting Internal Subset property",
+				      "<!ELEMENT book ANY>", docType.InternalSubset);
+		}
+
+		[Test]
+		public void AppendChild ()
+		{
+			try {
+				XmlDocumentType type1 = document.CreateDocumentType ("book", null, null, null);
+				document.AppendChild (type1);
+
+			} catch (InvalidOperationException) {
+				return;
+
+			} catch (Exception) {				
+				Assertion.Fail ("Incorrect Exception thrown.");
+			}
+		}
+
+		[Test]
+		public void NodeType ()
+		{
+			Assertion.AssertEquals ("NodeType property broken",
+				      docType.NodeType.ToString (), "DocumentType");
+		}
+		
+		[Test]
+		public void IsReadOnly ()
+		{
+			Assertion.AssertEquals ("IsReadOnly property", "True", docType.IsReadOnly.ToString ());
+		}
+
+		[Test]
+		public void CloneNode ()
+		{
+			XmlNode original = docType;
+
+			XmlNode cloned1 = docType.CloneNode (true);
+			XmlNodeBaseProperties (original, cloned1);
+
+			XmlNode cloned2 = docType.CloneNode (false);
+			XmlNodeBaseProperties (original, cloned2);
+
+			Assertion.AssertEquals ("Deep and shallow cloning", cloned1.Value, cloned2.Value);
+		}
+	       
+	}
+}

+ 357 - 0
mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs

@@ -0,0 +1,357 @@
+//
+// XmlElementTests
+//
+// Authors:
+//   Jason Diamond ([email protected])
+//   Martin Willemoes Hansen ([email protected])
+//
+// (C) 2002 Jason Diamond  http://injektilo.org/
+// (C) 2003 Martin Willemoes Hansen 
+//
+
+using System;
+using System.Xml;
+using System.IO;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlElementTests 
+	{
+		private XmlDocument document;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+		}
+
+		private void AssertElement (XmlElement element, string prefix,
+					    string localName, string namespaceURI,
+					    int attributesCount)
+		{
+			Assertion.AssertEquals (prefix != String.Empty ? prefix + ":" + localName : localName, element.Name);
+			Assertion.AssertEquals (prefix, element.Prefix);
+			Assertion.AssertEquals (localName, element.LocalName);
+			Assertion.AssertEquals (namespaceURI, element.NamespaceURI);
+			//Assertion.AssertEquals (attributesCount, element.Attributes.Count);
+		}
+
+		// for NodeInserted Event
+		private bool Inserted = false;
+		private void OnNodeInserted (object o, XmlNodeChangedEventArgs e)
+		{
+			Inserted = true;
+		}
+
+		// for NodeChanged Event
+		private bool Changed = false;
+		private void OnNodeChanged (object o, XmlNodeChangedEventArgs e)
+		{
+			Changed = true;
+		}
+
+		// for NodeRemoved Event
+		private bool Removed = false;
+		private void OnNodeRemoved (object o, XmlNodeChangedEventArgs e)
+		{
+			Removed = true;
+		}
+
+		[Test]
+		public void CloneNode ()
+		{
+			XmlElement element = document.CreateElement ("foo");
+			XmlElement child = document.CreateElement ("bar");
+			XmlElement grandson = document.CreateElement ("baz");
+
+			element.SetAttribute ("attr1", "val1");
+			element.SetAttribute ("attr2", "val2");
+			element.AppendChild (child);
+			child.SetAttribute ("attr3", "val3");
+			child.AppendChild (grandson);
+                        
+			document.AppendChild (element);
+			XmlNode deep = element.CloneNode (true);
+			// Assertion.AssertEquals ("These should be the same", deep.OuterXml, element.OuterXml); 
+			Assertion.AssertNull ("This is not null", deep.ParentNode);
+			Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (element,deep));
+
+			XmlNode shallow = element.CloneNode (false);
+			Assertion.AssertNull ("This is not null", shallow.ParentNode);
+			Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (element,shallow));
+			Assertion.AssertEquals ("Shallow clones shalt have no children!", false, shallow.HasChildNodes);
+		}
+
+		[Test]
+		public void CreateElement1 ()
+		{
+			XmlElement element = document.CreateElement ("name");
+			AssertElement (element, String.Empty, "name", String.Empty, 0);
+		}
+
+		[Test]
+		public void CreateElement1WithPrefix ()
+		{
+			XmlElement element = document.CreateElement ("prefix:localName");
+			AssertElement (element, "prefix", "localName", String.Empty, 0);
+		}
+
+		[Test]
+		public void CreateElement2 ()
+		{
+			XmlElement element = document.CreateElement ("qualifiedName", "namespaceURI");
+			AssertElement (element, String.Empty, "qualifiedName",
+				       "namespaceURI", 0);
+		}
+
+		[Test]
+		public void CreateElement2WithPrefix ()
+		{
+			XmlElement element = document.CreateElement ("prefix:localName", "namespaceURI");
+			AssertElement (element, "prefix", "localName", "namespaceURI", 0);
+		}
+
+		[Test]
+		public void CreateElement3 ()
+		{
+			XmlElement element = document.CreateElement ("prefix", "localName", "namespaceURI");
+			AssertElement (element, "prefix", "localName", "namespaceURI", 0);
+		}
+
+		[Test]
+		public void CreateElement3WithNullNamespace ()
+		{
+			// bug #26855, NamespaceURI should NEVER be null.
+			XmlElement element = document.CreateElement (null, "localName", null);
+			AssertElement (element, String.Empty, "localName", String.Empty, 0);
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			XmlElement element;
+			XmlText text;
+			XmlComment comment;
+			
+			element = document.CreateElement ("foo");
+			Assertion.AssertEquals (String.Empty, element.InnerXml);
+			Assertion.AssertEquals ("<foo />", element.OuterXml);
+
+			text = document.CreateTextNode ("bar");
+			element.AppendChild (text);
+			Assertion.AssertEquals ("bar", element.InnerXml);
+			Assertion.AssertEquals ("<foo>bar</foo>", element.OuterXml);
+
+			element.SetAttribute ("baz", "quux");
+			Assertion.AssertEquals ("bar", element.InnerXml);
+			Assertion.AssertEquals ("<foo baz=\"quux\">bar</foo>", element.OuterXml);
+
+			comment = document.CreateComment ("squonk");
+			element.AppendChild (comment);
+			Assertion.AssertEquals ("bar<!--squonk-->", element.InnerXml);
+			Assertion.AssertEquals ("<foo baz=\"quux\">bar<!--squonk--></foo>", element.OuterXml);
+
+			element.RemoveAll();
+			element.AppendChild(document.CreateElement("hoge"));
+			Assertion.AssertEquals ("<hoge />", element.InnerXml);
+		}
+
+		[Test]
+		public void SetGetAttribute ()
+		{
+			XmlElement element = document.CreateElement ("foo");
+			element.SetAttribute ("attr1", "val1");
+			element.SetAttribute ("attr2", "val2");
+			Assertion.AssertEquals ("val1", element.GetAttribute ("attr1"));
+			Assertion.AssertEquals ("val2", element.GetAttribute ("attr2"));
+		}
+
+		[Test]
+		public void GetElementsByTagNameNoNameSpace ()
+		{
+			string xml = @"<library><book><title>XML Fun</title><author>John Doe</author>
+				<price>34.95</price></book><book><title>Bear and the Dragon</title>
+				<author>Tom Clancy</author><price>6.95</price></book><book>
+				<title>Bourne Identity</title><author>Robert Ludlum</author>
+				<price>9.95</price></book><Fluffer><Nutter><book>
+				<title>Bourne Ultimatum</title><author>Robert Ludlum</author>
+				<price>9.95</price></book></Nutter></Fluffer></library>";
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			XmlNodeList libraryList = document.GetElementsByTagName ("library");
+			XmlNode xmlNode = libraryList.Item (0);
+			XmlElement xmlElement = xmlNode as XmlElement;
+			XmlNodeList bookList = xmlElement.GetElementsByTagName ("book");
+			Assertion.AssertEquals ("GetElementsByTagName (string) returned incorrect count.", 4, bookList.Count);
+		}
+
+		[Test]
+		public void GetElementsByTagNameUsingNameSpace ()
+		{
+			StringBuilder xml = new StringBuilder ();
+			xml.Append ("<?xml version=\"1.0\" ?><library xmlns:North=\"http://www.foo.com\" ");
+			xml.Append ("xmlns:South=\"http://www.goo.com\"><North:book type=\"non-fiction\"> ");
+			xml.Append ("<North:title type=\"intro\">XML Fun</North:title> " );
+			xml.Append ("<North:author>John Doe</North:author> " );
+			xml.Append ("<North:price>34.95</North:price></North:book> " );
+			xml.Append ("<South:book type=\"fiction\"> " );
+			xml.Append ("<South:title>Bear and the Dragon</South:title> " );
+			xml.Append ("<South:author>Tom Clancy</South:author> " );
+			xml.Append ("<South:price>6.95</South:price></South:book> " );
+			xml.Append ("<South:book type=\"fiction\"><South:title>Bourne Identity</South:title> " );
+			xml.Append ("<South:author>Robert Ludlum</South:author> " );
+			xml.Append ("<South:price>9.95</South:price></South:book></library>");
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			XmlNodeList libraryList = document.GetElementsByTagName ("library");
+			XmlNode xmlNode = libraryList.Item (0);
+			XmlElement xmlElement = xmlNode as XmlElement;
+			XmlNodeList bookList = xmlElement.GetElementsByTagName ("book", "http://www.foo.com");
+			Assertion.AssertEquals ("GetElementsByTagName (string, uri) returned incorrect count.", 1, bookList.Count);
+		}
+
+		[Test]
+		public void OuterXmlWithNamespace ()
+		{
+			XmlElement element = document.CreateElement ("foo", "bar", "#foo");
+			Assertion.AssertEquals ("<foo:bar xmlns:foo=\"#foo\" />", element.OuterXml);
+		}		
+
+		[Test]
+		public void RemoveAllAttributes ()
+		{
+			StringBuilder xml = new StringBuilder ();
+			xml.Append ("<?xml version=\"1.0\" ?><library><book type=\"non-fiction\" price=\"34.95\"> ");
+			xml.Append ("<title type=\"intro\">XML Fun</title> " );
+			xml.Append ("<author>John Doe</author></book></library>");
+
+			MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
+			document = new XmlDocument ();
+			document.Load (memoryStream);
+			XmlNodeList bookList = document.GetElementsByTagName ("book");
+			XmlNode xmlNode = bookList.Item (0);
+			XmlElement xmlElement = xmlNode as XmlElement;
+			xmlElement.RemoveAllAttributes ();
+			Assertion.AssertEquals ("attributes not properly removed.", false, xmlElement.HasAttribute ("type"));
+		}
+
+		[Test]
+		public void SetAttributeNode ()
+		{
+			XmlDocument xmlDoc = new XmlDocument ();
+			XmlElement xmlEl = xmlDoc.CreateElement ("TestElement");
+			XmlAttribute xmlAttribute = xmlEl.SetAttributeNode ("attr1", "namespace1");
+			XmlAttribute xmlAttribute2 = xmlEl.SetAttributeNode ("attr2", "namespace2");
+			Assertion.AssertEquals ("attribute name not properly created.", true, xmlAttribute.Name.Equals ("attr1"));
+			Assertion.AssertEquals ("attribute namespace not properly created.", true, xmlAttribute.NamespaceURI.Equals ("namespace1"));
+		}
+
+		[Test]
+		public void InnerXmlSetter ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<root/>");
+			XmlElement el =  doc.DocumentElement;
+			Assertion.AssertNull ("#Simple", el.FirstChild);
+			el.InnerXml = "<foo><bar att='baz'/></foo>";
+			XmlElement child = el.FirstChild as XmlElement;
+			Assertion.AssertNotNull ("#Simple.Child", child);
+			Assertion.AssertEquals ("#Simple.Child.Name", "foo", child.LocalName);
+
+			XmlElement grandchild = child.FirstChild as XmlElement;
+			Assertion.AssertNotNull ("#Simple.GrandChild", grandchild);
+			Assertion.AssertEquals ("#Simple.GrandChild.Name", "bar", grandchild.LocalName);
+			Assertion.AssertEquals ("#Simple.GrandChild.Attr", "baz", grandchild.GetAttribute ("att"));
+
+			doc.LoadXml ("<root xmlns='NS0' xmlns:ns1='NS1'><foo/><ns1:bar/><ns2:bar xmlns:ns2='NS2' /></root>");
+			el = doc.DocumentElement.FirstChild.NextSibling as XmlElement;	// ns1:bar
+			Assertion.AssertNull ("#Namespaced.Prepare", el.FirstChild);
+			el.InnerXml = "<ns1:baz />";
+			Assertion.AssertNotNull ("#Namespaced.Child", el.FirstChild);
+			Assertion.AssertEquals ("#Namespaced.Child.Name", "baz", el.FirstChild.LocalName);
+			Assertion.AssertEquals ("#Namespaced.Child.NSURI", "NS1", el.FirstChild.NamespaceURI);	// important!
+
+			el.InnerXml = "<hoge />";
+			Assertion.AssertEquals ("#Namespaced.VerifyPreviousCleared", "hoge", el.FirstChild.Name);
+		}
+
+		[Test]
+		public void RemoveAttribute ()
+		{
+			string xlinkURI = "http://www.w3.org/1999/XLink";
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<root a1='1' a2='2' xlink:href='urn:foo' xmlns:xlink='" + xlinkURI + "' />");
+
+			XmlElement el =  doc.DocumentElement;
+			el.RemoveAttribute ("a1");
+			Assertion.AssertNull ("RemoveAttribute", el.GetAttributeNode ("a1"));
+			el.RemoveAttribute ("xlink:href");
+			Assertion.AssertNull ("RemoveAttribute", el.GetAttributeNode ("href", xlinkURI));
+			el.RemoveAllAttributes ();
+			Assertion.AssertNull ("RemoveAllAttributes", el.GetAttributeNode ("a2"));
+		}
+
+		[Test]
+		public void WriteToWithDefaultNamespace ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<RetrievalElement URI=\"\"xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />");
+			StringWriter sw = new StringWriter ();
+			XmlTextWriter xtw = new XmlTextWriter (sw);
+			doc.DocumentElement.WriteTo (xtw);
+			Assertion.AssertEquals ("<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", sw.ToString());
+		}
+
+		[Test]
+		public void WriteToWithDeletedNamespacePrefix ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<root xmlns:foo='urn:dummy'><foo foo:bar='baz' /></root>");
+			doc.DocumentElement.RemoveAllAttributes ();
+
+			Assertion.Assert (doc.DocumentElement.FirstChild.OuterXml.IndexOf("xmlns:foo") > 0);
+		}
+
+		[Test]
+		public void WriteToWithDifferentNamespaceAttributes ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<root xmlns:foo='urn:dummy' xmlns:html='http://www.w3.org/1999/xhtml' html:style='font-size: 1em'></root>");
+			Assertion.Assert (doc.OuterXml.IndexOf ("xmlns:html=\"http://www.w3.org/1999/xhtml\"") > 0);
+		}
+
+		[Test]
+		public void InnerTextAndEvent ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<root><child>text</child><child2><![CDATA[cdata]]></child2></root>");
+			doc.NodeInserted += new XmlNodeChangedEventHandler (
+				OnNodeInserted);
+			doc.NodeRemoved += new XmlNodeChangedEventHandler (
+				OnNodeRemoved);
+			// If only one child of the element is Text node,
+			// then no events are fired.
+			doc.DocumentElement.FirstChild.InnerText = "no events fired.";
+			Assertion.AssertEquals ("NoInsertEventFired", false, Inserted);
+			Assertion.AssertEquals ("NoRemoveEventFired", false, Removed);
+			Assertion.AssertEquals ("SetInnerTextToSingleText", "no events fired.", doc.DocumentElement.FirstChild.InnerText);
+			Inserted = false;
+			Removed = false;
+
+			// if only one child of the element is CDataSection,
+			// then events are fired.
+			doc.DocumentElement.LastChild.InnerText = "events are fired.";
+			Assertion.AssertEquals ("InsertedEventFired", true, Inserted);
+			Assertion.AssertEquals ("RemovedEventFired", true, Removed);
+			Assertion.AssertEquals ("SetInnerTextToCDataSection", "events are fired.", doc.DocumentElement.LastChild.InnerText);
+		}
+	}
+}

+ 32 - 0
mcs/class/System.XML/Test/System.Xml/XmlEntityReferenceTests.cs

@@ -0,0 +1,32 @@
+//
+// System.Xml.XmlEntityReference.cs
+//
+// Authors:
+//   Atsushi Enomoto <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Atsushi Enomoto
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlEntityReferenceTests
+	{
+		[Test]
+		public void WriteTo ()
+		{
+			XmlDocument doc = new XmlDocument();
+			doc.LoadXml("<root/>");
+			XmlEntityReference er = doc.CreateEntityReference("foo");
+			doc.DocumentElement.AppendChild(er);
+			Assertion.AssertEquals ("Name", "foo", er.Name);
+			Assertion.AssertEquals ("WriteTo", "<root>&foo;</root>", doc.DocumentElement.OuterXml);
+		}
+	}
+}

+ 157 - 0
mcs/class/System.XML/Test/System.Xml/XmlNamespaceManagerTests.cs

@@ -0,0 +1,157 @@
+//
+// XmlNamespaceManagerTests.cs
+//
+// Authors:
+//   Jason Diamond ([email protected])
+//   Martin Willemoes Hansen ([email protected])
+//
+// (C) 2002 Jason Diamond  http://injektilo.org/
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlNamespaceManagerTests
+	{
+		private XmlNameTable nameTable;
+		private XmlNamespaceManager namespaceManager;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			nameTable = new NameTable ();
+			namespaceManager = new XmlNamespaceManager (nameTable);
+		}
+
+		[Test]
+		public void NewNamespaceManager ()
+		{
+			// make sure that you can call PopScope when there aren't any to pop.
+			Assertion.Assert (!namespaceManager.PopScope ());
+
+			// the following strings should have been added to the name table by the
+			// namespace manager.
+			string xmlnsPrefix = nameTable.Get ("xmlns");
+			string xmlPrefix = nameTable.Get ("xml");
+			string stringEmpty = nameTable.Get (String.Empty);
+			string xmlnsNamespace = "http://www.w3.org/2000/xmlns/";
+			string xmlNamespace = "http://www.w3.org/XML/1998/namespace";
+
+			// none of them should be null.
+			Assertion.AssertNotNull (xmlnsPrefix);
+			Assertion.AssertNotNull (xmlPrefix);
+			Assertion.AssertNotNull (stringEmpty);
+			Assertion.AssertNotNull (xmlnsNamespace);
+			Assertion.AssertNotNull (xmlNamespace);
+
+			// Microsoft's XmlNamespaceManager reports that these three
+			// namespaces aren't declared for some reason.
+			Assertion.Assert (!namespaceManager.HasNamespace ("xmlns"));
+			Assertion.Assert (!namespaceManager.HasNamespace ("xml"));
+			Assertion.Assert (!namespaceManager.HasNamespace (String.Empty));
+
+			// these three namespaces are declared by default.
+			Assertion.AssertEquals ("http://www.w3.org/2000/xmlns/", namespaceManager.LookupNamespace ("xmlns"));
+			Assertion.AssertEquals ("http://www.w3.org/XML/1998/namespace", namespaceManager.LookupNamespace ("xml"));
+			Assertion.AssertEquals (String.Empty, namespaceManager.LookupNamespace (String.Empty));
+
+			// the namespaces should be the same references found in the name table.
+			Assertion.AssertSame (xmlnsNamespace, namespaceManager.LookupNamespace ("xmlns"));
+			Assertion.AssertSame (xmlNamespace, namespaceManager.LookupNamespace ("xml"));
+			Assertion.AssertSame (stringEmpty, namespaceManager.LookupNamespace (String.Empty));
+
+			// looking up undeclared namespaces should return null.
+			Assertion.AssertNull (namespaceManager.LookupNamespace ("foo"));
+		}
+
+		[Test]
+		public void AddNamespace ()
+		{
+			// add a new namespace.
+			namespaceManager.AddNamespace ("foo", "http://foo/");
+			// make sure the new namespace is there.
+			Assertion.Assert (namespaceManager.HasNamespace ("foo"));
+			Assertion.AssertEquals ("http://foo/", namespaceManager.LookupNamespace ("foo"));
+		}
+
+		[Test]
+		public void AddNamespaceWithNameTable ()
+		{
+			// add a known reference to the name table.
+			string fooNamespace = "http://foo/";
+			nameTable.Add(fooNamespace);
+
+			// create a new string with the same value but different address.
+			string fooNamespace2 = "http://";
+			fooNamespace2 += "foo/";
+
+			// the references must be different in order for this test to prove anything.
+			Assertion.Assert (!Object.ReferenceEquals (fooNamespace, fooNamespace2));
+
+			// add the namespace with the reference that's not in the name table.
+			namespaceManager.AddNamespace ("foo", fooNamespace2);
+
+			// the returned reference should be the same one that's in the name table.
+			Assertion.AssertSame (fooNamespace, namespaceManager.LookupNamespace ("foo"));
+		}
+
+		[Test]
+		public void PushScope ()
+		{
+			// add a new namespace.
+			namespaceManager.AddNamespace ("foo", "http://foo/");
+			// make sure the new namespace is there.
+			Assertion.Assert (namespaceManager.HasNamespace ("foo"));
+			Assertion.AssertEquals ("http://foo/", namespaceManager.LookupNamespace ("foo"));
+			// push a new scope.
+			namespaceManager.PushScope ();
+			// add a new namespace.
+			namespaceManager.AddNamespace ("bar", "http://bar/");
+			// make sure the old namespace is not in this new scope.
+			Assertion.Assert (!namespaceManager.HasNamespace ("foo"));
+			// but we're still supposed to be able to lookup the old namespace.
+			Assertion.AssertEquals ("http://foo/", namespaceManager.LookupNamespace ("foo"));
+			// make sure the new namespace is there.
+			Assertion.Assert (namespaceManager.HasNamespace ("bar"));
+			Assertion.AssertEquals ("http://bar/", namespaceManager.LookupNamespace ("bar"));
+		}
+
+		[Test]
+		public void PopScope ()
+		{
+			// add some namespaces and a scope.
+			PushScope ();
+			// pop the scope.
+			Assertion.Assert (namespaceManager.PopScope ());
+			// make sure the first namespace is still there.
+			Assertion.Assert (namespaceManager.HasNamespace ("foo"));
+			Assertion.AssertEquals ("http://foo/", namespaceManager.LookupNamespace ("foo"));
+			// make sure the second namespace is no longer there.
+			Assertion.Assert (!namespaceManager.HasNamespace ("bar"));
+			Assertion.AssertNull (namespaceManager.LookupNamespace ("bar"));
+			// make sure there are no more scopes to pop.
+			Assertion.Assert (!namespaceManager.PopScope ());
+			// make sure that popping again doesn't cause an exception.
+			Assertion.Assert (!namespaceManager.PopScope ());
+		}
+
+		[Test]
+		public void LookupPrefix ()
+		{
+			// This test should use an empty nametable.
+			XmlNamespaceManager nsmgr =
+				new XmlNamespaceManager (new NameTable ());
+			nsmgr.NameTable.Add ("urn:hoge");
+			nsmgr.NameTable.Add ("urn:fuga");
+			nsmgr.AddNamespace (string.Empty, "urn:hoge");
+			Assertion.AssertNull (nsmgr.LookupPrefix ("urn:fuga"));
+			Assertion.AssertEquals (String.Empty, nsmgr.LookupPrefix ("urn:hoge"));
+		}
+	}
+}

+ 245 - 0
mcs/class/System.XML/Test/System.Xml/XmlNodeListTests.cs

@@ -0,0 +1,245 @@
+//
+// System.Xml.XmlTextWriterTests
+//
+// Authors:
+//   Kral Ferch <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+using System.Collections;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlNodeListTests
+	{
+		XmlDocument document;
+		XmlElement documentElement;
+		XmlElement element;
+		XmlNode node;
+		Object obj;
+		IEnumerator enumerator;
+		int index;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+		}
+
+		[Test]
+		public void NodeTypesThatCantHaveChildren ()
+		{
+			document.LoadXml ("<foo>bar</foo>");
+			documentElement = document.DocumentElement;
+			node = documentElement.FirstChild;
+			Assertion.AssertEquals ("Expected a text node.", node.NodeType, XmlNodeType.Text);
+			Assertion.AssertEquals ("Shouldn't have children.", node.HasChildNodes, false);
+			Assertion.AssertEquals ("Should be empty node list.", node.ChildNodes.Count, 0);
+			Assertion.AssertEquals ("Should be empty node list.", node.GetEnumerator().MoveNext(), false);
+		}
+
+		[Test]
+		public void ZeroChildren ()
+		{
+			document.LoadXml ("<foo/>");
+			documentElement = document.DocumentElement;
+			Assertion.AssertEquals ("Should be empty node list.", documentElement.GetEnumerator().MoveNext(), false);
+		}
+
+		[Test]
+		public void OneChild ()
+		{
+			document.LoadXml ("<foo><child1/></foo>");
+			documentElement = document.DocumentElement;
+			Assertion.AssertEquals ("Incorrect number of children returned from Count property.", documentElement.ChildNodes.Count, 1);
+			index = 1;
+			foreach (XmlNode childNode in documentElement.ChildNodes) 
+			{
+				Assertion.AssertEquals ("Enumerator didn't return correct node.", "child" + index.ToString(), childNode.LocalName);
+				index++;
+			}
+			Assertion.AssertEquals ("foreach didn't loop over all children correctly.", index, 2);
+		}
+
+		[Test]
+		public void MultipleChildren ()
+		{
+			document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
+			element = document.DocumentElement;
+			Assertion.AssertEquals ("Incorrect number of children returned from Count property.", element.ChildNodes.Count, 3);
+			Assertion.AssertNull ("Index less than zero should have returned null.", element.ChildNodes [-1]);
+			Assertion.AssertNull ("Index greater than or equal to Count should have returned null.", element.ChildNodes [3]);
+			Assertion.AssertEquals ("Didn't return the correct child.", element.FirstChild, element.ChildNodes[0]);
+			Assertion.AssertEquals ("Didn't return the correct child.", "child1", element.ChildNodes[0].LocalName);
+			Assertion.AssertEquals ("Didn't return the correct child.", "child2", element.ChildNodes[1].LocalName);
+			Assertion.AssertEquals ("Didn't return the correct child.", "child3", element.ChildNodes[2].LocalName);
+
+			index = 1;
+			foreach (XmlNode childNode in element.ChildNodes) 
+			{
+				Assertion.AssertEquals ("Enumerator didn't return correct node.", "child" + index.ToString(), childNode.LocalName);
+				index++;
+			}
+			Assertion.AssertEquals ("foreach didn't loop over all children correctly.", index, 4);
+		}
+
+		[Test]
+		public void AppendChildAffectOnEnumeration ()
+		{
+			document.LoadXml ("<foo><child1/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			Assertion.AssertEquals ("MoveNext should have succeeded.", enumerator.MoveNext(), true);
+			Assertion.AssertEquals ("MoveNext should have failed.", enumerator.MoveNext(), false);
+			enumerator.Reset();
+			Assertion.AssertEquals ("MoveNext should have succeeded.", enumerator.MoveNext(), true);
+			element.AppendChild(document.CreateElement("child2"));
+			Assertion.AssertEquals ("MoveNext should have succeeded.", enumerator.MoveNext(), true);
+			Assertion.AssertEquals ("MoveNext should have failed.", enumerator.MoveNext(), false);
+		}
+
+		[Test]
+		public void RemoveChildAffectOnEnumeration ()
+		{
+			document.LoadXml ("<foo><child1/><child2/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			element.RemoveChild(element.FirstChild);
+			enumerator.MoveNext();
+			Assertion.AssertEquals ("Expected child2 element.", ((XmlElement)enumerator.Current).LocalName, "child2");
+		}
+
+		[Test]
+		public void RemoveChildAffectOnEnumerationWhenEnumeratorIsOnRemovedChild ()
+		{
+			document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator ();
+			enumerator.MoveNext ();
+			enumerator.MoveNext ();
+			Assertion.AssertEquals ("Expected child2 element.", "child2", ((XmlElement)enumerator.Current).LocalName);
+			Assertion.AssertEquals ("Expected child2 element.", "child2", element.FirstChild.NextSibling.LocalName);
+			element.RemoveChild (element.FirstChild.NextSibling);
+			enumerator.MoveNext ();
+			
+			try {
+				element = (XmlElement) enumerator.Current;
+				Assertion.Fail ("Expected an InvalidOperationException.");
+			} catch (InvalidOperationException) { }
+		}
+
+		// TODO:  Take the word save off front of this method when XmlNode.ReplaceChild() is implemented.
+
+		public void saveTestReplaceChildAffectOnEnumeration ()
+		{
+			document.LoadXml ("<foo><child1/><child2/></foo>");
+			element = document.DocumentElement;
+			node = document.CreateElement("child3");
+			enumerator = element.GetEnumerator();
+			Assertion.AssertEquals ("MoveNext should have succeeded.", enumerator.MoveNext(), true);
+			element.ReplaceChild(node, element.LastChild);
+			enumerator.MoveNext();
+			Assertion.AssertEquals ("Expected child3 element.", ((XmlElement)enumerator.Current).LocalName, "child3");
+			Assertion.AssertEquals ("MoveNext should have failed.", enumerator.MoveNext(), false);
+		}
+
+		[Test]
+		public void RemoveOnlyChildAffectOnEnumeration ()
+		{
+			document.LoadXml ("<foo><child1/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			element.RemoveChild(element.FirstChild);
+			Assertion.AssertEquals ("MoveNext should have failed.", enumerator.MoveNext(), false);
+		}
+
+		// TODO:  Take the word save off front of this method when XmlNode.RemoveAll() is fully implemented.
+
+		public void saveTestRemoveAllAffectOnEnumeration ()
+		{
+			document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			Assertion.AssertEquals ("Expected 3 children.", element.ChildNodes.Count, 3);
+			Assertion.AssertEquals ("MoveNext should have succeeded.", enumerator.MoveNext(), true);
+			element.RemoveAll();
+			Assertion.AssertEquals ("MoveNext should have failed.", enumerator.MoveNext(), false);
+		}
+
+		[Test]
+		public void CurrentBeforeFirstNode ()
+		{
+			document.LoadXml ("<foo><child1/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			try 
+			{
+				obj = enumerator.Current;
+				Assertion.Fail ("Calling Current property before first node in list should have thrown InvalidOperationException.");
+			} catch (InvalidOperationException) { }
+		}
+
+		[Test]
+		public void CurrentAfterLastNode ()
+		{
+			document.LoadXml ("<foo><child1/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			enumerator.MoveNext();
+			enumerator.MoveNext();
+			try 
+			{
+				obj = enumerator.Current;
+				Assertion.Fail ("Calling Current property after last node in list should have thrown InvalidOperationException.");
+			} 
+			catch (InvalidOperationException) { }
+		}
+
+		[Test]
+		public void CurrentDoesntMove ()
+		{
+			document.LoadXml ("<foo><child1/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			enumerator.MoveNext();
+			Assertion.AssertEquals("Consecutive calls to Current property should yield same reference.", Object.ReferenceEquals(enumerator.Current, enumerator.Current), true);
+		}
+
+		[Test]
+		public void Reset ()
+		{
+			document.LoadXml ("<foo><child1/><child2/></foo>");
+			element = document.DocumentElement;
+			enumerator = element.GetEnumerator();
+			enumerator.MoveNext();
+			enumerator.MoveNext();
+			Assertion.AssertEquals("Expected child2.", ((XmlElement)enumerator.Current).LocalName, "child2");
+			enumerator.Reset();
+			enumerator.MoveNext();
+			Assertion.AssertEquals("Expected child1.", ((XmlElement)enumerator.Current).LocalName, "child1");
+		}
+
+		[Test]
+		public void ReturnNullWhenIndexIsOutOfRange ()
+		{
+			document.LoadXml ("<root><foo/></root>");
+			XmlNodeList nl = document.DocumentElement.GetElementsByTagName ("bar");
+			Assertion.AssertEquals ("empty list. count", 0, nl.Count);
+			try {
+				Assertion.AssertNull ("index 0", nl [0]);
+				Assertion.AssertNull ("index 1", nl [1]);
+				Assertion.AssertNull ("index -1", nl [-1]);
+			} catch (ArgumentOutOfRangeException) {
+				Assertion.Fail ("don't throw index out of range.");
+			}
+		}
+	}
+}

+ 79 - 0
mcs/class/System.XML/Test/System.Xml/XmlNodeReaderTests.cs

@@ -0,0 +1,79 @@
+//
+// System.Xml.XmlNodeReaderTests
+//
+// Authors:
+//   Atsushi Enomoto <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2003 Atsushi Enomoto
+// (C) 2003 Martin Willemoes Hansen
+//
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlNodeReaderTests
+	{
+		[SetUp]
+		public void GetReady ()
+		{
+			document.LoadXml ("<root attr1='value1'><child /></root>");
+		}
+
+		XmlDocument document = new XmlDocument ();
+
+		[Test]
+		public void InvalidConstruction ()
+		{
+			XmlNodeReader nrdr;
+			try {
+				nrdr = new XmlNodeReader (null);
+				Assertion.Fail ("null reference exception is preferable.");
+			} catch (NullReferenceException ex) {
+			}
+			nrdr = new XmlNodeReader (new XmlDocument ());
+			nrdr.Read ();
+			Assertion.AssertEquals ("newDoc.ReadState", ReadState.Error, nrdr.ReadState);
+			Assertion.AssertEquals ("newDoc.EOF", true, nrdr.EOF);
+			Assertion.AssertEquals ("newDoc.NodeType", XmlNodeType.None, nrdr.NodeType);
+			nrdr = new XmlNodeReader (document.CreateDocumentFragment ());
+			nrdr.Read ();
+			Assertion.AssertEquals ("Fragment.ReadState", ReadState.Error, nrdr.ReadState);
+			Assertion.AssertEquals ("Fragment.EOF", true, nrdr.EOF);
+			Assertion.AssertEquals ("Fragment.NodeType", XmlNodeType.None, nrdr.NodeType);
+		}
+
+		[Test]
+		public void ReadFromElement ()
+		{
+			XmlNodeReader nrdr = new XmlNodeReader (document.DocumentElement);
+			nrdr.Read ();
+			Assertion.AssertEquals ("<root>.NodeType", XmlNodeType.Element, nrdr.NodeType);
+			Assertion.AssertEquals ("<root>.Name", "root", nrdr.Name);
+			Assertion.AssertEquals ("<root>.ReadState", ReadState.Interactive, nrdr.ReadState);
+			Assertion.AssertEquals ("<root>.Depth", 0, nrdr.Depth);
+		}
+
+
+		[Test]
+		public void ReadInnerXmlWrongInit ()
+		{
+			document.LoadXml ("<root>test of <b>mixed</b> string.</root>");
+			XmlNodeReader nrdr = new XmlNodeReader (document);
+			nrdr.ReadInnerXml ();
+			Assertion.AssertEquals ("initial.ReadState", ReadState.Error, nrdr.ReadState);
+			Assertion.AssertEquals ("initial.EOF", true, nrdr.EOF);
+			Assertion.AssertEquals ("initial.NodeType", XmlNodeType.None, nrdr.NodeType);
+		}
+
+	}
+
+}

+ 225 - 0
mcs/class/System.XML/Test/System.Xml/XmlNodeTests.cs

@@ -0,0 +1,225 @@
+//
+// System.Xml.XmlNodeTests
+//
+// Authors:
+//   Kral Ferch <[email protected]>
+//   Martin Willemoes Hansen
+//
+// (C) 2002 Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlNodeTests
+	{
+		XmlDocument document;
+		XmlElement element;
+		XmlElement element2;
+		bool inserted;
+		bool inserting;
+		bool changed;
+		bool changing;
+		bool removed;
+		bool removing;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.NodeInserted += new XmlNodeChangedEventHandler (this.EventNodeInserted);
+			document.NodeInserting += new XmlNodeChangedEventHandler (this.EventNodeInserting);
+			document.NodeRemoved += new XmlNodeChangedEventHandler (this.EventNodeRemoved);
+			document.NodeRemoving += new XmlNodeChangedEventHandler (this.EventNodeRemoving);
+			element = document.CreateElement ("foo");
+			element2 = document.CreateElement ("bar");
+		}
+
+		private void EventNodeInserted(Object sender, XmlNodeChangedEventArgs e)
+		{
+			inserted = true;
+		}
+
+		private void EventNodeInserting (Object sender, XmlNodeChangedEventArgs e)
+		{
+			inserting = true;
+		}
+
+		private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
+		{
+			changed = true;
+		}
+
+		private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
+		{
+			changing = true;
+		}
+
+		private void EventNodeRemoved(Object sender, XmlNodeChangedEventArgs e)
+		{
+			removed = true;
+		}
+
+		private void EventNodeRemoving (Object sender, XmlNodeChangedEventArgs e)
+		{
+			removing = true;
+		}
+
+		[Test]
+		public void AppendChild ()
+		{
+			XmlComment comment;
+
+			inserted = false;
+			inserting = false;
+			element.AppendChild (element2);
+			Assertion.Assert (inserted);
+			Assertion.Assert (inserting);
+
+			// Can only append to elements, documents, and attributes
+			try 
+			{
+				comment = document.CreateComment ("baz");
+				comment.AppendChild (element2);
+				Assertion.Fail ("Expected an InvalidOperationException to be thrown.");
+			} 
+			catch (InvalidOperationException) {}
+
+			// Can't append a node from one document into another document.
+			XmlDocument document2 = new XmlDocument();
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+			try 
+			{
+				element2 = document2.CreateElement ("qux");
+				element.AppendChild (element2);
+				Assertion.Fail ("Expected an ArgumentException to be thrown.");
+			} 
+			catch (ArgumentException) {}
+			Assertion.AssertEquals (1, element.ChildNodes.Count);
+
+			// Can't append to a readonly node.
+/* TODO put this in when I figure out how to create a read-only node.
+			try 
+			{
+				XmlElement element3 = (XmlElement)element.CloneNode (false);
+				Assertion.Assert (!element.IsReadOnly);
+				Assertion.Assert (element3.IsReadOnly);
+				element2 = document.CreateElement ("quux");
+				element3.AppendChild (element2);
+				Assertion.Fail ("Expected an ArgumentException to be thrown.");
+			} 
+			catch (ArgumentException) {}
+*/
+		}
+
+		[Test]
+		public void InsertBefore()
+		{
+			document = new XmlDocument();
+			document.LoadXml("<root><sub /></root>");
+			XmlElement docelem = document.DocumentElement;
+			docelem.InsertBefore(document.CreateElement("good_child"), docelem.FirstChild);
+			Assertion.AssertEquals("InsertBefore.Normal", "good_child", docelem.FirstChild.Name);
+			// These are required for .NET 1.0 but not for .NET 1.1.
+//			try {
+//				document.InsertBefore (document.CreateElement ("BAD_MAN"), docelem);
+//				Assertion.Fail ("#InsertBefore.BadPositionButNoError.1");
+//			}
+//			catch (XmlException) {}
+		}
+
+		[Test]
+		public void InsertAfter()
+		{
+			document = new XmlDocument();
+			document.LoadXml("<root><sub1 /><sub2 /></root>");
+			XmlElement docelem = document.DocumentElement;
+			XmlElement newelem = document.CreateElement("good_child");
+			docelem.InsertAfter(newelem, docelem.FirstChild);
+			Assertion.AssertEquals("InsertAfter.Normal", 3, docelem.ChildNodes.Count);
+			Assertion.AssertEquals("InsertAfter.First", "sub1", docelem.FirstChild.Name);
+			Assertion.AssertEquals("InsertAfter.Last", "sub2", docelem.LastChild.Name);
+			Assertion.AssertEquals("InsertAfter.Prev", "good_child", docelem.FirstChild.NextSibling.Name);
+			Assertion.AssertEquals("InsertAfter.Next", "good_child", docelem.LastChild.PreviousSibling.Name);
+			// this doesn't throw an exception
+			document.InsertAfter(document.CreateElement("BAD_MAN"), docelem);
+			Assertion.AssertEquals("InsertAfter with bad location", 
+				"<root><sub1 /><good_child /><sub2 /></root><BAD_MAN />",
+				document.InnerXml);
+}
+
+		[Test]
+		public void PrependChild()
+		{
+			document = new XmlDocument();
+			document.LoadXml("<root><sub1 /><sub2 /></root>");
+			XmlElement docelem = document.DocumentElement;
+			docelem.PrependChild(document.CreateElement("prepender"));
+			Assertion.AssertEquals("PrependChild", "prepender", docelem.FirstChild.Name);
+		}
+
+		public void saveTestRemoveAll ()
+		{
+			// TODO:  put this test back in when AttributeCollection.RemoveAll() is implemented.
+			element.AppendChild(element2);
+			removed = false;
+			removing = false;
+			element.RemoveAll ();
+			Assertion.Assert (removed);
+			Assertion.Assert (removing);
+		}
+
+		[Test]
+		public void RemoveChild ()
+		{
+			element.AppendChild(element2);
+			removed = false;
+			removing = false;
+			element.RemoveChild (element2);
+			Assertion.Assert (removed);
+			Assertion.Assert (removing);
+		}
+		
+		[Test]
+		public void RemoveLastChild ()
+		{
+			element.InnerXml = "<foo/><bar/><baz/>";
+			element.RemoveChild (element.LastChild);
+			Assertion.AssertNotNull (element.FirstChild);
+		}
+		
+		[Test]
+		public void GetPrefixOfNamespace ()
+		{
+			document.LoadXml ("<root><c1 xmlns='urn:foo'><c2 xmlns:foo='urn:foo' xmlns='urn:bar'><c3 xmlns=''/></c2></c1></root>");
+			Assertion.AssertEquals ("root", String.Empty, document.DocumentElement.GetPrefixOfNamespace ("urn:foo"));
+			Assertion.AssertEquals ("c1", String.Empty, document.DocumentElement.GetPrefixOfNamespace ("urn:foo"));
+			Assertion.AssertEquals ("c2", String.Empty, document.DocumentElement.FirstChild.GetPrefixOfNamespace ("urn:foo"));
+			Assertion.AssertEquals ("c3", "foo", document.DocumentElement.FirstChild.FirstChild.GetPrefixOfNamespace ("urn:foo"));
+
+		}
+
+		[Test]
+		public void ReplaceChild ()
+		{
+			document.LoadXml ("<root/>");
+			document.NodeInserted += new XmlNodeChangedEventHandler (this.EventNodeInserted);
+			document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
+			document.NodeRemoved += new XmlNodeChangedEventHandler (this.EventNodeRemoved);
+			inserted = changed = removed = false;
+			XmlElement el = document.CreateElement("root2");
+			document.ReplaceChild (el, document.DocumentElement);
+			Assertion.AssertEquals ("root2", document.DocumentElement.Name);
+			Assertion.AssertEquals (1, document.ChildNodes.Count);
+			Assertion.Assert (inserted && removed && !changed);
+		}
+	}
+}

+ 38 - 0
mcs/class/System.XML/Test/System.Xml/XmlProcessingInstructionTests.cs

@@ -0,0 +1,38 @@
+//
+// System.Xml.XmlTextWriterTests
+//
+// Authors:
+//   Kral Ferch <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlProcessingInstructionTests
+	{
+		XmlDocument document;
+		XmlProcessingInstruction pi;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			pi = document.CreateProcessingInstruction ("foo", "bar");
+			Assertion.AssertEquals (String.Empty, pi.InnerXml);
+			Assertion.AssertEquals ("<?foo bar?>", pi.OuterXml);
+		}
+	}
+}

+ 889 - 0
mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs

@@ -0,0 +1,889 @@
+//
+// System.Xml.XmlReaderCommonTests
+//
+// Authors:
+//   Atsushi Enomoto <[email protected]>
+//
+// (C) 2003 Atsushi Enomoto
+//  Note: Most of testcases are moved from XmlTextReaderTests.cs and
+//  XmlNodeReaderTests.cs.
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlReaderTests
+	{
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.LoadXml (xml1);
+		}
+
+		XmlDocument document;
+		const string xml1 = "<root attr1='value1'><child /></root>";
+		const string xml2 = "<root><foo/><bar>test.</bar></root>";
+		const string xml3 = "<root>  test of <b>mixed</b> string.<![CDATA[ cdata string.]]></root>";
+		const string xml4 = "<root>test of <b>mixed</b> string.</root>";
+		XmlTextReader xtr;
+		XmlNodeReader xnr;
+
+		// copy from XmlTextReaderTests
+		private void AssertStartDocument (XmlReader xmlReader)
+		{
+			Assertion.Assert (xmlReader.ReadState == ReadState.Initial);
+			Assertion.Assert (xmlReader.NodeType == XmlNodeType.None);
+			Assertion.Assert (xmlReader.Depth == 0);
+			Assertion.Assert (!xmlReader.EOF);
+		}
+
+		private void AssertNode (
+			XmlReader xmlReader,
+			XmlNodeType nodeType,
+			int depth,
+			bool isEmptyElement,
+			string name,
+			string prefix,
+			string localName,
+			string namespaceURI,
+			string value,
+			int attributeCount)
+		{
+			Assertion.Assert ("Read() return value", xmlReader.Read ());
+			Assertion.Assert ("ReadState", xmlReader.ReadState == ReadState.Interactive);
+			Assertion.Assert ("!EOF", !xmlReader.EOF);
+			AssertNodeValues (xmlReader, nodeType, depth, isEmptyElement, name, prefix, localName, namespaceURI, value, attributeCount);
+		}
+
+		private void AssertNodeValues (
+			XmlReader xmlReader,
+			XmlNodeType nodeType,
+			int depth,
+			bool isEmptyElement,
+			string name,
+			string prefix,
+			string localName,
+			string namespaceURI,
+			string value,
+			int attributeCount)
+		{
+			Assertion.AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
+			Assertion.AssertEquals ("Depth", depth, xmlReader.Depth);
+			Assertion.AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
+
+			Assertion.AssertEquals ("name", name, xmlReader.Name);
+
+			Assertion.AssertEquals ("prefix", prefix, xmlReader.Prefix);
+
+			Assertion.AssertEquals ("localName", localName, xmlReader.LocalName);
+
+			Assertion.AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
+
+			Assertion.AssertEquals ("hasValue", (value != String.Empty), xmlReader.HasValue);
+
+			Assertion.AssertEquals ("Value", value, xmlReader.Value);
+
+			Assertion.AssertEquals ("hasAttributes", attributeCount > 0, xmlReader.HasAttributes);
+
+			Assertion.AssertEquals ("attributeCount", attributeCount, xmlReader.AttributeCount);
+		}
+
+		private void AssertAttribute (
+			XmlReader xmlReader,
+			string name,
+			string prefix,
+			string localName,
+			string namespaceURI,
+			string value)
+		{
+			Assertion.AssertEquals ("value", value, xmlReader [name]);
+
+			Assertion.Assert (xmlReader.GetAttribute (name) == value);
+
+			if (namespaceURI != String.Empty) {
+				Assertion.Assert (xmlReader[localName, namespaceURI] == value);
+				Assertion.Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
+			}
+		}
+
+		private void AssertEndDocument (XmlReader xmlReader)
+		{
+			Assertion.Assert ("could read", !xmlReader.Read ());
+			Assertion.AssertEquals ("NodeType is not XmlNodeType.None", XmlNodeType.None, xmlReader.NodeType);
+			Assertion.AssertEquals ("Depth is not 0", 0, xmlReader.Depth);
+			Assertion.AssertEquals ("ReadState is not ReadState.EndOfFile",  ReadState.EndOfFile, xmlReader.ReadState);
+			Assertion.Assert ("not EOF", xmlReader.EOF);
+
+			xmlReader.Close ();
+			Assertion.AssertEquals ("ReadState is not ReadState.Cosed", ReadState.Closed, xmlReader.ReadState);
+		}
+
+		private delegate void TestMethod (XmlReader reader);
+
+		private void RunTest (string xml, TestMethod method)
+		{
+			xtr = new XmlTextReader (new StringReader (xml));
+			try {
+				method (xtr);
+			} catch (AssertionException ex) {
+				throw new AssertionException ("XmlTextReader failed:  " + ex.Message, ex);
+			}
+
+			document.LoadXml (xml);
+			xnr = new XmlNodeReader (document);
+			try {
+				method (xnr);
+			} catch (AssertionException ex) {
+				throw new AssertionException ("XmlNodeReader failed:  " + ex.Message, ex);
+			}
+		}
+
+
+
+
+
+		[Test]
+		public void InitialState ()
+		{
+			RunTest (xml1, new TestMethod (InitialState));
+		}
+
+		private void InitialState (XmlReader reader)
+		{
+			Assertion.AssertEquals ("Depth", 0, reader.Depth);
+			Assertion.AssertEquals ("EOF", false, reader.EOF);
+			Assertion.AssertEquals ("HasValue", false, reader.HasValue);
+			Assertion.AssertEquals ("IsEmptyElement", false, reader.IsEmptyElement);
+			Assertion.AssertEquals ("LocalName", String.Empty, reader.LocalName);
+			Assertion.AssertEquals ("NodeType", XmlNodeType.None, reader.NodeType);
+			Assertion.AssertEquals ("ReadState", ReadState.Initial, reader.ReadState);
+		}
+
+		[Test]
+		public void Read ()
+		{
+			RunTest (xml1, new TestMethod (Read));
+		}
+
+		public void Read (XmlReader reader)
+		{
+			reader.Read ();
+			Assertion.AssertEquals ("<root>.NodeType", XmlNodeType.Element, reader.NodeType);
+			Assertion.AssertEquals ("<root>.Name", "root", reader.Name);
+			Assertion.AssertEquals ("<root>.ReadState", ReadState.Interactive, reader.ReadState);
+			Assertion.AssertEquals ("<root>.Depth", 0, reader.Depth);
+
+			// move to 'child'
+			reader.Read ();
+			Assertion.AssertEquals ("<child/>.Depth", 1, reader.Depth);
+			Assertion.AssertEquals ("<child/>.NodeType", XmlNodeType.Element, reader.NodeType);
+			Assertion.AssertEquals ("<child/>.Name", "child", reader.Name);
+
+			reader.Read ();
+			Assertion.AssertEquals ("</root>.Depth", 0, reader.Depth);
+			Assertion.AssertEquals ("</root>.NodeType", XmlNodeType.EndElement, reader.NodeType);
+			Assertion.AssertEquals ("</root>.Name", "root", reader.Name);
+
+			reader.Read ();
+			Assertion.AssertEquals ("end.EOF", true, reader.EOF);
+			Assertion.AssertEquals ("end.NodeType", XmlNodeType.None, reader.NodeType);
+		}
+
+		[Test]
+		public void ReadEmptyElement ()
+		{
+			RunTest (xml2, new TestMethod (ReadEmptyElement));
+		}
+
+		public void ReadEmptyElement (XmlReader reader)
+		{
+			reader.Read ();	// root
+			Assertion.AssertEquals (false, reader.IsEmptyElement);
+			reader.Read ();	// foo
+			Assertion.AssertEquals ("foo", reader.Name);
+			Assertion.AssertEquals (true, reader.IsEmptyElement);
+			reader.Read ();	// bar
+			Assertion.AssertEquals ("bar", reader.Name);
+			Assertion.AssertEquals (false, reader.IsEmptyElement);
+		}
+
+		[Test]
+		public void ReadStringFromElement ()
+		{
+			RunTest (xml3, new TestMethod (ReadStringFromElement));
+		}
+
+		public void ReadStringFromElement (XmlReader reader)
+		{
+			// Note: ReadString() test works only when the reader is
+			// positioned at the container element.
+			// In case the reader is positioned at the first 
+			// character node, XmlTextReader and XmlNodeReader works
+			// different!!
+
+			reader.Read ();
+			string s = reader.ReadString ();
+			Assertion.AssertEquals ("readString.1.ret_val", "  test of ", s);
+			Assertion.AssertEquals ("readString.1.Name", "b", reader.Name);
+			s = reader.ReadString ();
+			Assertion.AssertEquals ("readString.2.ret_val", "mixed", s);
+			Assertion.AssertEquals ("readString.2.NodeType", XmlNodeType.EndElement, reader.NodeType);
+			s = reader.ReadString ();	// never proceeds.
+			Assertion.AssertEquals ("readString.3.ret_val", String.Empty, s);
+			Assertion.AssertEquals ("readString.3.NodeType", XmlNodeType.EndElement, reader.NodeType);
+			reader.Read ();
+			Assertion.AssertEquals ("readString.4.NodeType", XmlNodeType.Text, reader.NodeType);
+			Assertion.AssertEquals ("readString.4.Value", " string.", reader.Value);
+			s = reader.ReadString ();	// reads the same Text node.
+			Assertion.AssertEquals ("readString.5.ret_val", " string. cdata string.", s);
+			Assertion.AssertEquals ("readString.5.NodeType", XmlNodeType.EndElement, reader.NodeType);
+		}
+
+		[Test]
+		public void ReadInnerXml ()
+		{
+			RunTest (xml4, new TestMethod (ReadInnerXml));
+		}
+
+		public void ReadInnerXml (XmlReader reader)
+		{
+			reader.Read ();
+			Assertion.AssertEquals ("initial.ReadState", ReadState.Interactive, reader.ReadState);
+			Assertion.AssertEquals ("initial.EOF", false, reader.EOF);
+			Assertion.AssertEquals ("initial.NodeType", XmlNodeType.Element, reader.NodeType);
+		}
+
+
+		[Test]
+		public void EmptyElement ()
+		{
+			RunTest ("<foo/>", new TestMethod (EmptyElement));
+		}
+		
+		public void EmptyElement (XmlReader xmlReader)
+		{
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, // depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EmptyElementWithStartAndEndTag ()
+		{
+			string xml = "<foo></foo>";
+			RunTest (xml,
+				new TestMethod (EmptyElementWithStartAndEndTag));
+		}
+
+		public void EmptyElementWithStartAndEndTag (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void NestedEmptyTag ()
+		{
+			string xml = "<foo><bar/></foo>";
+			RunTest (xml, new TestMethod (NestedEmptyTag));
+		}
+
+		public void NestedEmptyTag (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				1, //depth
+				true, // isEmptyElement
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void NestedText ()
+		{
+			string xml = "<foo>bar</foo>";
+			RunTest (xml, new TestMethod (NestedText));
+		}
+
+		public void NestedText (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Text, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"bar", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EmptyElementWithAttribute ()
+		{
+			string xml = @"<foo bar=""baz""/>";
+			RunTest (xml, new TestMethod (EmptyElementWithAttribute));
+		}
+
+		public void EmptyElementWithAttribute (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"baz" // value
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void StartAndEndTagWithAttribute ()
+		{
+			string xml = @"<foo bar='baz'></foo>";
+			RunTest (xml, new TestMethod (StartAndEndTagWithAttribute));
+		}
+
+		public void StartAndEndTagWithAttribute (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"baz" // value
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EmptyElementWithTwoAttributes ()
+		{
+			string xml = @"<foo bar=""baz"" quux='quuux'/>";
+			RunTest (xml, new TestMethod (EmptyElementWithTwoAttributes ));
+		}
+
+		public void EmptyElementWithTwoAttributes (XmlReader xmlReader)
+		{
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				2 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"baz" // value
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"quux", // name
+				String.Empty, // prefix
+				"quux", // localName
+				String.Empty, // namespaceURI
+				"quuux" // value
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void ProcessingInstructionBeforeDocumentElement ()
+		{
+			string xml = "<?foo bar?><baz/>";
+			RunTest (xml, new TestMethod (ProcessingInstructionBeforeDocumentElement));
+		}
+
+		public void ProcessingInstructionBeforeDocumentElement (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.ProcessingInstruction, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				"bar", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"baz", // name
+				String.Empty, // prefix
+				"baz", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void CommentBeforeDocumentElement ()
+		{
+			string xml = "<!--foo--><bar/>";
+			RunTest (xml, new TestMethod (CommentBeforeDocumentElement));
+		}
+
+		public void CommentBeforeDocumentElement (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Comment, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"foo", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void PredefinedEntities ()
+		{
+			string xml = "<foo>&lt;&gt;&amp;&apos;&quot;</foo>";
+			RunTest (xml, new TestMethod (PredefinedEntities));
+		}
+
+		public void PredefinedEntities (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Text, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"<>&'\"", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EntityReference ()
+		{
+			string xml = "<foo>&bar;</foo>";
+			RunTest (xml, new TestMethod (EntityReference));
+		}
+
+		public void EntityReference (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EntityReference, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EntityReferenceInsideText ()
+		{
+			string xml = "<foo>bar&baz;quux</foo>";
+			RunTest (xml, new TestMethod (EntityReferenceInsideText));
+		}
+
+		public void EntityReferenceInsideText (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Text, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"bar", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EntityReference, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				"baz", // name
+				String.Empty, // prefix
+				"baz", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Text, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"quux", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void CharacterReferences ()
+		{
+			string xml = "<foo>&#70;&#x4F;&#x4f;</foo>";
+			RunTest (xml, new TestMethod (CharacterReferences));
+		}
+
+		public void CharacterReferences (XmlReader xmlReader)
+		{
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Text, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"FOO", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+	}
+}

+ 136 - 0
mcs/class/System.XML/Test/System.Xml/XmlSignificantWhitespaceTests.cs

@@ -0,0 +1,136 @@
+//
+// System.Xml.XmlWhitespaceTests.cs
+//
+// Authors:
+//	Duncan Mak  ([email protected])
+//      Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlSignificantWhitespaceTests
+	{
+		XmlDocument document;
+		XmlDocument doc2;
+		XmlSignificantWhitespace whitespace;
+		XmlSignificantWhitespace broken;
+		XmlNode original;
+		XmlNode deep;
+		XmlNode shallow;
+		
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.LoadXml ("<root><foo></foo></root>");
+			XmlElement element = document.CreateElement ("foo");
+			whitespace = document.CreateSignificantWhitespace ("\r\n");
+			element.AppendChild (whitespace);
+
+			doc2 = new XmlDocument ();
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			whitespace = doc2.CreateSignificantWhitespace ("\r\n\t ");
+			Assertion.AssertEquals (String.Empty, whitespace.InnerXml);
+			Assertion.AssertEquals ("\r\n\t ", whitespace.OuterXml);
+		}
+
+		[Test]
+		public void DataAndValue ()
+		{
+			string val = "\t\t\r\n ";
+			whitespace = doc2.CreateSignificantWhitespace (val);
+			Assertion.AssertEquals ("#DataValue.1", val, whitespace.Data);
+			Assertion.AssertEquals ("#DataValue.2", val, whitespace.Value);
+			whitespace.Value = val + "\t";
+			Assertion.AssertEquals ("#DataValue.3", val + "\t", whitespace.Data);
+		}
+			
+		internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+		{
+//			assertequals (original.nodetype + " was incorrectly cloned.",
+//				      original.baseuri, cloned.baseuri);			
+			Assertion.AssertNull (cloned.ParentNode);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				       cloned.Value, original.Value);
+			
+                        Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
+		}
+
+		[Test]
+		public void XmlSignificantWhitespaceBadConstructor ()
+		{
+			try {
+				broken = document.CreateSignificantWhitespace ("black");				
+
+			} catch (ArgumentException) {
+				return;
+
+			} catch (Exception) {
+				Assertion.Fail ("Incorrect Exception thrown.");
+			}
+		}
+
+		[Test]
+		public void XmlSignificantWhitespaceConstructor ()
+		{
+			Assertion.AssertEquals ("whitespace char didn't get copied right",
+				      "\r\n", whitespace.Data);
+		}
+		
+	       	[Test]
+		public void XmlSignificantWhitespaceName ()
+		{
+			Assertion.AssertEquals (whitespace.NodeType + " Name property broken",
+				      whitespace.Name, "#significant-whitespace");
+		}
+
+		[Test]
+		public void XmlSignificantWhitespaceLocalName ()
+		{
+			Assertion.AssertEquals (whitespace.NodeType + " LocalName property broken",
+				      whitespace.LocalName, "#significant-whitespace");
+		}
+
+		[Test]
+		public void XmlSignificantWhitespaceNodeType ()
+		{
+			Assertion.AssertEquals ("XmlSignificantWhitespace NodeType property broken",
+				      whitespace.NodeType.ToString (), "SignificantWhitespace");
+		}
+
+		[Test]
+		public void XmlSignificantWhitespaceIsReadOnly ()
+		{
+			Assertion.AssertEquals ("XmlSignificantWhitespace IsReadOnly property broken",
+				      whitespace.IsReadOnly, false);
+		}
+
+		[Test]
+		public void XmlSignificantWhitespaceCloneNode ()
+		{
+			original = whitespace;
+
+			shallow = whitespace.CloneNode (false); // shallow
+			XmlNodeBaseProperties (original, shallow);
+						
+			deep = whitespace.CloneNode (true); // deep
+			XmlNodeBaseProperties (original, deep); 
+
+                        Assertion.AssertEquals ("deep cloning differs from shallow cloning",
+				      deep.OuterXml, shallow.OuterXml);
+		}
+	}
+}

+ 1249 - 0
mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs

@@ -0,0 +1,1249 @@
+//
+// XmlTextReaderTests.cs
+//
+// Authors:
+//   Jason Diamond ([email protected])
+//   Martin Willemoes Hansen ([email protected])
+//
+// (C) 2001, 2002 Jason Diamond  http://injektilo.org/
+//
+
+using System;
+using System.IO;
+using System.Xml;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlTextReaderTests
+	{
+		private void AssertStartDocument (XmlReader xmlReader)
+		{
+			Assertion.Assert (xmlReader.ReadState == ReadState.Initial);
+			Assertion.Assert (xmlReader.NodeType == XmlNodeType.None);
+			Assertion.Assert (xmlReader.Depth == 0);
+			Assertion.Assert (!xmlReader.EOF);
+		}
+
+		private void AssertNode (
+			XmlReader xmlReader,
+			XmlNodeType nodeType,
+			int depth,
+			bool isEmptyElement,
+			string name,
+			string prefix,
+			string localName,
+			string namespaceURI,
+			string value,
+			int attributeCount)
+		{
+			Assertion.Assert (xmlReader.Read ());
+			Assertion.Assert (xmlReader.ReadState == ReadState.Interactive);
+			Assertion.Assert (!xmlReader.EOF);
+			AssertNodeValues (xmlReader, nodeType, depth, isEmptyElement, name, prefix, localName, namespaceURI, value, attributeCount);
+		}
+
+		private void AssertNodeValues (
+			XmlReader xmlReader,
+			XmlNodeType nodeType,
+			int depth,
+			bool isEmptyElement,
+			string name,
+			string prefix,
+			string localName,
+			string namespaceURI,
+			string value,
+			int attributeCount)
+		{
+			Assertion.AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
+			Assertion.AssertEquals ("Depth", depth, xmlReader.Depth);
+			Assertion.AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
+
+			Assertion.AssertEquals ("name", name, xmlReader.Name);
+
+			Assertion.AssertEquals ("prefix", prefix, xmlReader.Prefix);
+
+			Assertion.AssertEquals ("localName", localName, xmlReader.LocalName);
+
+			Assertion.AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
+
+			Assertion.AssertEquals ("hasValue", (value != String.Empty), xmlReader.HasValue);
+
+			Assertion.AssertEquals ("Value", value, xmlReader.Value);
+
+			Assertion.AssertEquals ("hasAttributes", attributeCount > 0, xmlReader.HasAttributes);
+
+			Assertion.AssertEquals ("attributeCount", attributeCount, xmlReader.AttributeCount);
+		}
+
+		private void AssertAttribute (
+			XmlReader xmlReader,
+			string name,
+			string prefix,
+			string localName,
+			string namespaceURI,
+			string value)
+		{
+			Assertion.AssertEquals ("value", value, xmlReader [name]);
+
+			Assertion.Assert (xmlReader.GetAttribute (name) == value);
+
+			if (namespaceURI != String.Empty) {
+				Assertion.Assert (xmlReader[localName, namespaceURI] == value);
+				Assertion.Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
+			}
+		}
+
+		private void AssertEndDocument (XmlReader xmlReader)
+		{
+			Assertion.Assert ("could read", !xmlReader.Read ());
+			Assertion.AssertEquals ("NodeType is not XmlNodeType.None", XmlNodeType.None, xmlReader.NodeType);
+			Assertion.AssertEquals ("Depth is not 0", 0, xmlReader.Depth);
+			Assertion.AssertEquals ("ReadState is not ReadState.EndOfFile",  ReadState.EndOfFile, xmlReader.ReadState);
+			Assertion.Assert ("not EOF", xmlReader.EOF);
+
+			xmlReader.Close ();
+			Assertion.AssertEquals ("ReadState is not ReadState.Cosed", ReadState.Closed, xmlReader.ReadState);
+		}
+
+		// expecting parser error
+		[Test]
+		public void EmptyElementWithBadName ()
+		{
+			string xml = "<1foo/>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			bool caughtXmlException = false;
+
+			try {
+				xmlReader.Read();
+			} catch (XmlException) {
+				caughtXmlException = true;
+			}
+
+			Assertion.Assert(caughtXmlException);
+		}
+
+		// checking parser
+		[Test]
+		public void EmptyElementWithStartAndEndTagWithWhitespace ()
+		{
+			string xml = "<foo ></foo >";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EntityReferenceInAttribute ()
+		{
+			string xml = "<foo bar='&baz;'/>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"&baz;" // value
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void PredefinedEntitiesInAttribute ()
+		{
+			string xml = "<foo bar='&lt;&gt;&amp;&apos;&quot;'/>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"<>&'\"" // value
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void CharacterReferencesInAttribute ()
+		{
+			string xml = "<foo bar='&#70;&#x4F;&#x4f;'/>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"FOO" // value
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void CDATA ()
+		{
+			string xml = "<foo><![CDATA[<>&]]></foo>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.CDATA, // nodeType
+				1, //depth
+				false, // isEmptyElement
+				String.Empty, // name
+				String.Empty, // prefix
+				String.Empty, // localName
+				String.Empty, // namespaceURI
+				"<>&", // value
+				0 // attributeCount
+			);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, //depth
+				false, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EmptyElementInNamespace ()
+		{
+			string xml = @"<foo:bar xmlns:foo='http://foo/' />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, // depth
+				true, // isEmptyElement
+				"foo:bar", // name
+				"foo", // prefix
+				"bar", // localName
+				"http://foo/", // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns:foo", // name
+				"xmlns", // prefix
+				"foo", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://foo/" // value
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void EmptyElementInDefaultNamespace ()
+		{
+			string xml = @"<foo xmlns='http://foo/' />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, // depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				"http://foo/", // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns", // name
+				String.Empty, // prefix
+				"xmlns", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://foo/" // value
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace (String.Empty));
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void ChildElementInNamespace ()
+		{
+			string xml = @"<foo:bar xmlns:foo='http://foo/'><baz:quux xmlns:baz='http://baz/' /></foo:bar>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, // depth
+				false, // isEmptyElement
+				"foo:bar", // name
+				"foo", // prefix
+				"bar", // localName
+				"http://foo/", // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns:foo", // name
+				"xmlns", // prefix
+				"foo", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://foo/" // value
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				1, // depth
+				true, // isEmptyElement
+				"baz:quux", // name
+				"baz", // prefix
+				"quux", // localName
+				"http://baz/", // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns:baz", // name
+				"xmlns", // prefix
+				"baz", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://baz/" // value
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+			Assertion.AssertEquals ("http://baz/", xmlReader.LookupNamespace ("baz"));
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, // depth
+				false, // isEmptyElement
+				"foo:bar", // name
+				"foo", // prefix
+				"bar", // localName
+				"http://foo/", // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+			Assertion.AssertNull (xmlReader.LookupNamespace ("baz"));
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void ChildElementInDefaultNamespace ()
+		{
+			string xml = @"<foo:bar xmlns:foo='http://foo/'><baz xmlns='http://baz/' /></foo:bar>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, // depth
+				false, // isEmptyElement
+				"foo:bar", // name
+				"foo", // prefix
+				"bar", // localName
+				"http://foo/", // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns:foo", // name
+				"xmlns", // prefix
+				"foo", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://foo/" // value
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				1, // depth
+				true, // isEmptyElement
+				"baz", // name
+				String.Empty, // prefix
+				"baz", // localName
+				"http://baz/", // namespaceURI
+				String.Empty, // value
+				1 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns", // name
+				String.Empty, // prefix
+				"xmlns", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://baz/" // value
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+			Assertion.AssertEquals ("http://baz/", xmlReader.LookupNamespace (String.Empty));
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.EndElement, // nodeType
+				0, // depth
+				false, // isEmptyElement
+				"foo:bar", // name
+				"foo", // prefix
+				"bar", // localName
+				"http://foo/", // namespaceURI
+				String.Empty, // value
+				0 // attributeCount
+			);
+
+			Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void AttributeInNamespace ()
+		{
+			string xml = @"<foo bar:baz='quux' xmlns:bar='http://bar/' />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, // depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				2 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar:baz", // name
+				"bar", // prefix
+				"baz", // localName
+				"http://bar/", // namespaceURI
+				"quux" // value
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"xmlns:bar", // name
+				"xmlns", // prefix
+				"bar", // localName
+				"http://www.w3.org/2000/xmlns/", // namespaceURI
+				"http://bar/" // value
+			);
+
+			Assertion.AssertEquals ("http://bar/", xmlReader.LookupNamespace ("bar"));
+
+			AssertEndDocument (xmlReader);
+		}
+
+// The following is #if'ed out because it's specific to the Mono
+// implementation and won't compile when testing Microsoft's code.
+// Feel free to turn it on if you want to test Mono's name tables.
+
+#if false
+
+		[Test]
+		public void IsFirstNameCharTest ()
+		{
+			for (int ch = 0; ch <= 0xFFFF; ++ch) {
+				Assertion.Assert (
+					XmlChar.IsFirstNameChar (ch) ==
+						IsFirstNameChar (ch));
+			}
+		}
+
+		[Test]
+		public void IsNameCharTest ()
+		{
+			for (int ch = 0; ch <= 0xFFFF; ++ch) {
+				Assertion.Assert (
+					XmlChar.IsNameChar (ch) ==
+						IsNameChar (ch));
+			}
+		}
+
+		private static bool IsFirstNameChar (int ch)
+		{
+			return
+				IsLetter (ch) ||
+				(ch == '_') ||
+				(ch == ':');
+		}
+
+		private static bool IsNameChar (int ch)
+		{
+			return
+				IsLetter (ch) ||
+				IsDigit (ch) ||
+				(ch == '.') ||
+				(ch == '-') ||
+				(ch == '_') ||
+				(ch == ':') ||
+				IsCombiningChar (ch) ||
+				IsExtender (ch);
+		}
+
+		private static bool IsLetter (int ch)
+		{
+			return
+				IsBaseChar (ch) ||
+				IsIdeographic (ch);
+		}
+
+		private static bool IsBaseChar (int ch)
+		{
+			return
+				(ch >= 0x0041 && ch <= 0x005A) ||
+				(ch >= 0x0061 && ch <= 0x007A) ||
+				(ch >= 0x00C0 && ch <= 0x00D6) ||
+				(ch >= 0x00D8 && ch <= 0x00F6) ||
+				(ch >= 0x00F8 && ch <= 0x00FF) ||
+				(ch >= 0x0100 && ch <= 0x0131) ||
+				(ch >= 0x0134 && ch <= 0x013E) ||
+				(ch >= 0x0141 && ch <= 0x0148) ||
+				(ch >= 0x014A && ch <= 0x017E) ||
+				(ch >= 0x0180 && ch <= 0x01C3) ||
+				(ch >= 0x01CD && ch <= 0x01F0) ||
+				(ch >= 0x01F4 && ch <= 0x01F5) ||
+				(ch >= 0x01FA && ch <= 0x0217) ||
+				(ch >= 0x0250 && ch <= 0x02A8) ||
+				(ch >= 0x02BB && ch <= 0x02C1) ||
+				(ch == 0x0386) ||
+				(ch >= 0x0388 && ch <= 0x038A) ||
+				(ch == 0x038C) ||
+				(ch >= 0x038E && ch <= 0x03A1) ||
+				(ch >= 0x03A3 && ch <= 0x03CE) ||
+				(ch >= 0x03D0 && ch <= 0x03D6) ||
+				(ch == 0x03DA) ||
+				(ch == 0x03DC) ||
+				(ch == 0x03DE) ||
+				(ch == 0x03E0) ||
+				(ch >= 0x03E2 && ch <= 0x03F3) ||
+				(ch >= 0x0401 && ch <= 0x040C) ||
+				(ch >= 0x040E && ch <= 0x044F) ||
+				(ch >= 0x0451 && ch <= 0x045C) ||
+				(ch >= 0x045E && ch <= 0x0481) ||
+				(ch >= 0x0490 && ch <= 0x04C4) ||
+				(ch >= 0x04C7 && ch <= 0x04C8) ||
+				(ch >= 0x04CB && ch <= 0x04CC) ||
+				(ch >= 0x04D0 && ch <= 0x04EB) ||
+				(ch >= 0x04EE && ch <= 0x04F5) ||
+				(ch >= 0x04F8 && ch <= 0x04F9) ||
+				(ch >= 0x0531 && ch <= 0x0556) ||
+				(ch == 0x0559) ||
+				(ch >= 0x0561 && ch <= 0x0586) ||
+				(ch >= 0x05D0 && ch <= 0x05EA) ||
+				(ch >= 0x05F0 && ch <= 0x05F2) ||
+				(ch >= 0x0621 && ch <= 0x063A) ||
+				(ch >= 0x0641 && ch <= 0x064A) ||
+				(ch >= 0x0671 && ch <= 0x06B7) ||
+				(ch >= 0x06BA && ch <= 0x06BE) ||
+				(ch >= 0x06C0 && ch <= 0x06CE) ||
+				(ch >= 0x06D0 && ch <= 0x06D3) ||
+				(ch == 0x06D5) ||
+				(ch >= 0x06E5 && ch <= 0x06E6) ||
+				(ch >= 0x0905 && ch <= 0x0939) ||
+				(ch == 0x093D) ||
+				(ch >= 0x0958 && ch <= 0x0961) ||
+				(ch >= 0x0985 && ch <= 0x098C) ||
+				(ch >= 0x098F && ch <= 0x0990) ||
+				(ch >= 0x0993 && ch <= 0x09A8) ||
+				(ch >= 0x09AA && ch <= 0x09B0) ||
+				(ch == 0x09B2) ||
+				(ch >= 0x09B6 && ch <= 0x09B9) ||
+				(ch >= 0x09DC && ch <= 0x09DD) ||
+				(ch >= 0x09DF && ch <= 0x09E1) ||
+				(ch >= 0x09F0 && ch <= 0x09F1) ||
+				(ch >= 0x0A05 && ch <= 0x0A0A) ||
+				(ch >= 0x0A0F && ch <= 0x0A10) ||
+				(ch >= 0x0A13 && ch <= 0x0A28) ||
+				(ch >= 0x0A2A && ch <= 0x0A30) ||
+				(ch >= 0x0A32 && ch <= 0x0A33) ||
+				(ch >= 0x0A35 && ch <= 0x0A36) ||
+				(ch >= 0x0A38 && ch <= 0x0A39) ||
+				(ch >= 0x0A59 && ch <= 0x0A5C) ||
+				(ch == 0x0A5E) ||
+				(ch >= 0x0A72 && ch <= 0x0A74) ||
+				(ch >= 0x0A85 && ch <= 0x0A8B) ||
+				(ch == 0x0A8D) ||
+				(ch >= 0x0A8F && ch <= 0x0A91) ||
+				(ch >= 0x0A93 && ch <= 0x0AA8) ||
+				(ch >= 0x0AAA && ch <= 0x0AB0) ||
+				(ch >= 0x0AB2 && ch <= 0x0AB3) ||
+				(ch >= 0x0AB5 && ch <= 0x0AB9) ||
+				(ch == 0x0ABD) ||
+				(ch == 0x0AE0) ||
+				(ch >= 0x0B05 && ch <= 0x0B0C) ||
+				(ch >= 0x0B0F && ch <= 0x0B10) ||
+				(ch >= 0x0B13 && ch <= 0x0B28) ||
+				(ch >= 0x0B2A && ch <= 0x0B30) ||
+				(ch >= 0x0B32 && ch <= 0x0B33) ||
+				(ch >= 0x0B36 && ch <= 0x0B39) ||
+				(ch == 0x0B3D) ||
+				(ch >= 0x0B5C && ch <= 0x0B5D) ||
+				(ch >= 0x0B5F && ch <= 0x0B61) ||
+				(ch >= 0x0B85 && ch <= 0x0B8A) ||
+				(ch >= 0x0B8E && ch <= 0x0B90) ||
+				(ch >= 0x0B92 && ch <= 0x0B95) ||
+				(ch >= 0x0B99 && ch <= 0x0B9A) ||
+				(ch == 0x0B9C) ||
+				(ch >= 0x0B9E && ch <= 0x0B9F) ||
+				(ch >= 0x0BA3 && ch <= 0x0BA4) ||
+				(ch >= 0x0BA8 && ch <= 0x0BAA) ||
+				(ch >= 0x0BAE && ch <= 0x0BB5) ||
+				(ch >= 0x0BB7 && ch <= 0x0BB9) ||
+				(ch >= 0x0C05 && ch <= 0x0C0C) ||
+				(ch >= 0x0C0E && ch <= 0x0C10) ||
+				(ch >= 0x0C12 && ch <= 0x0C28) ||
+				(ch >= 0x0C2A && ch <= 0x0C33) ||
+				(ch >= 0x0C35 && ch <= 0x0C39) ||
+				(ch >= 0x0C60 && ch <= 0x0C61) ||
+				(ch >= 0x0C85 && ch <= 0x0C8C) ||
+				(ch >= 0x0C8E && ch <= 0x0C90) ||
+				(ch >= 0x0C92 && ch <= 0x0CA8) ||
+				(ch >= 0x0CAA && ch <= 0x0CB3) ||
+				(ch >= 0x0CB5 && ch <= 0x0CB9) ||
+				(ch == 0x0CDE) ||
+				(ch >= 0x0CE0 && ch <= 0x0CE1) ||
+				(ch >= 0x0D05 && ch <= 0x0D0C) ||
+				(ch >= 0x0D0E && ch <= 0x0D10) ||
+				(ch >= 0x0D12 && ch <= 0x0D28) ||
+				(ch >= 0x0D2A && ch <= 0x0D39) ||
+				(ch >= 0x0D60 && ch <= 0x0D61) ||
+				(ch >= 0x0E01 && ch <= 0x0E2E) ||
+				(ch == 0x0E30) ||
+				(ch >= 0x0E32 && ch <= 0x0E33) ||
+				(ch >= 0x0E40 && ch <= 0x0E45) ||
+				(ch >= 0x0E81 && ch <= 0x0E82) ||
+				(ch == 0x0E84) ||
+				(ch >= 0x0E87 && ch <= 0x0E88) ||
+				(ch == 0x0E8A) ||
+				(ch == 0x0E8D) ||
+				(ch >= 0x0E94 && ch <= 0x0E97) ||
+				(ch >= 0x0E99 && ch <= 0x0E9F) ||
+				(ch >= 0x0EA1 && ch <= 0x0EA3) ||
+				(ch == 0x0EA5) ||
+				(ch == 0x0EA7) ||
+				(ch >= 0x0EAA && ch <= 0x0EAB) ||
+				(ch >= 0x0EAD && ch <= 0x0EAE) ||
+				(ch == 0x0EB0) ||
+				(ch >= 0x0EB2 && ch <= 0x0EB3) ||
+				(ch == 0x0EBD) ||
+				(ch >= 0x0EC0 && ch <= 0x0EC4) ||
+				(ch >= 0x0F40 && ch <= 0x0F47) ||
+				(ch >= 0x0F49 && ch <= 0x0F69) ||
+				(ch >= 0x10A0 && ch <= 0x10C5) ||
+				(ch >= 0x10D0 && ch <= 0x10F6) ||
+				(ch == 0x1100) ||
+				(ch >= 0x1102 && ch <= 0x1103) ||
+				(ch >= 0x1105 && ch <= 0x1107) ||
+				(ch == 0x1109) ||
+				(ch >= 0x110B && ch <= 0x110C) ||
+				(ch >= 0x110E && ch <= 0x1112) ||
+				(ch == 0x113C) ||
+				(ch == 0x113E) ||
+				(ch == 0x1140) ||
+				(ch == 0x114C) ||
+				(ch == 0x114E) ||
+				(ch == 0x1150) ||
+				(ch >= 0x1154 && ch <= 0x1155) ||
+				(ch == 0x1159) ||
+				(ch >= 0x115F && ch <= 0x1161) ||
+				(ch == 0x1163) ||
+				(ch == 0x1165) ||
+				(ch == 0x1167) ||
+				(ch == 0x1169) ||
+				(ch >= 0x116D && ch <= 0x116E) ||
+				(ch >= 0x1172 && ch <= 0x1173) ||
+				(ch == 0x1175) ||
+				(ch == 0x119E) ||
+				(ch == 0x11A8) ||
+				(ch == 0x11AB) ||
+				(ch >= 0x11AE && ch <= 0x11AF) ||
+				(ch >= 0x11B7 && ch <= 0x11B8) ||
+				(ch == 0x11BA) ||
+				(ch >= 0x11BC && ch <= 0x11C2) ||
+				(ch == 0x11EB) ||
+				(ch == 0x11F0) ||
+				(ch == 0x11F9) ||
+				(ch >= 0x1E00 && ch <= 0x1E9B) ||
+				(ch >= 0x1EA0 && ch <= 0x1EF9) ||
+				(ch >= 0x1F00 && ch <= 0x1F15) ||
+				(ch >= 0x1F18 && ch <= 0x1F1D) ||
+				(ch >= 0x1F20 && ch <= 0x1F45) ||
+				(ch >= 0x1F48 && ch <= 0x1F4D) ||
+				(ch >= 0x1F50 && ch <= 0x1F57) ||
+				(ch == 0x1F59) ||
+				(ch == 0x1F5B) ||
+				(ch == 0x1F5D) ||
+				(ch >= 0x1F5F && ch <= 0x1F7D) ||
+				(ch >= 0x1F80 && ch <= 0x1FB4) ||
+				(ch >= 0x1FB6 && ch <= 0x1FBC) ||
+				(ch == 0x1FBE) ||
+				(ch >= 0x1FC2 && ch <= 0x1FC4) ||
+				(ch >= 0x1FC6 && ch <= 0x1FCC) ||
+				(ch >= 0x1FD0 && ch <= 0x1FD3) ||
+				(ch >= 0x1FD6 && ch <= 0x1FDB) ||
+				(ch >= 0x1FE0 && ch <= 0x1FEC) ||
+				(ch >= 0x1FF2 && ch <= 0x1FF4) ||
+				(ch >= 0x1FF6 && ch <= 0x1FFC) ||
+				(ch == 0x2126) ||
+				(ch >= 0x212A && ch <= 0x212B) ||
+				(ch == 0x212E) ||
+				(ch >= 0x2180 && ch <= 0x2182) ||
+				(ch >= 0x3041 && ch <= 0x3094) ||
+				(ch >= 0x30A1 && ch <= 0x30FA) ||
+				(ch >= 0x3105 && ch <= 0x312C) ||
+				(ch >= 0xAC00 && ch <= 0xD7A3);
+		}
+
+		private static bool IsIdeographic (int ch)
+		{
+			return
+				(ch >= 0x4E00 && ch <= 0x9FA5) ||
+				(ch == 0x3007) ||
+				(ch >= 0x3021 && ch <= 0x3029);
+		}
+
+		private static bool IsDigit (int ch)
+		{
+			return
+				(ch >= 0x0030 && ch <= 0x0039) ||
+				(ch >= 0x0660 && ch <= 0x0669) ||
+				(ch >= 0x06F0 && ch <= 0x06F9) ||
+				(ch >= 0x0966 && ch <= 0x096F) ||
+				(ch >= 0x09E6 && ch <= 0x09EF) ||
+				(ch >= 0x0A66 && ch <= 0x0A6F) ||
+				(ch >= 0x0AE6 && ch <= 0x0AEF) ||
+				(ch >= 0x0B66 && ch <= 0x0B6F) ||
+				(ch >= 0x0BE7 && ch <= 0x0BEF) ||
+				(ch >= 0x0C66 && ch <= 0x0C6F) ||
+				(ch >= 0x0CE6 && ch <= 0x0CEF) ||
+				(ch >= 0x0D66 && ch <= 0x0D6F) ||
+				(ch >= 0x0E50 && ch <= 0x0E59) ||
+				(ch >= 0x0ED0 && ch <= 0x0ED9) ||
+				(ch >= 0x0F20 && ch <= 0x0F29);
+		}
+
+		private static bool IsCombiningChar (int ch)
+		{
+			return
+				(ch >= 0x0300 && ch <= 0x0345) ||
+				(ch >= 0x0360 && ch <= 0x0361) ||
+				(ch >= 0x0483 && ch <= 0x0486) ||
+				(ch >= 0x0591 && ch <= 0x05A1) ||
+				(ch >= 0x05A3 && ch <= 0x05B9) ||
+				(ch >= 0x05BB && ch <= 0x05BD) ||
+				(ch == 0x05BF) ||
+				(ch >= 0x05C1 && ch <= 0x05C2) ||
+				(ch == 0x05C4) ||
+				(ch >= 0x064B && ch <= 0x0652) ||
+				(ch == 0x0670) ||
+				(ch >= 0x06D6 && ch <= 0x06DC) ||
+				(ch >= 0x06DD && ch <= 0x06DF) ||
+				(ch >= 0x06E0 && ch <= 0x06E4) ||
+				(ch >= 0x06E7 && ch <= 0x06E8) ||
+				(ch >= 0x06EA && ch <= 0x06ED) ||
+				(ch >= 0x0901 && ch <= 0x0903) ||
+				(ch == 0x093C) ||
+				(ch >= 0x093E && ch <= 0x094C) ||
+				(ch == 0x094D) ||
+				(ch >= 0x0951 && ch <= 0x0954) ||
+				(ch >= 0x0962 && ch <= 0x0963) ||
+				(ch >= 0x0981 && ch <= 0x0983) ||
+				(ch == 0x09BC) ||
+				(ch == 0x09BE) ||
+				(ch == 0x09BF) ||
+				(ch >= 0x09C0 && ch <= 0x09C4) ||
+				(ch >= 0x09C7 && ch <= 0x09C8) ||
+				(ch >= 0x09CB && ch <= 0x09CD) ||
+				(ch == 0x09D7) ||
+				(ch >= 0x09E2 && ch <= 0x09E3) ||
+				(ch == 0x0A02) ||
+				(ch == 0x0A3C) ||
+				(ch == 0x0A3E) ||
+				(ch == 0x0A3F) ||
+				(ch >= 0x0A40 && ch <= 0x0A42) ||
+				(ch >= 0x0A47 && ch <= 0x0A48) ||
+				(ch >= 0x0A4B && ch <= 0x0A4D) ||
+				(ch >= 0x0A70 && ch <= 0x0A71) ||
+				(ch >= 0x0A81 && ch <= 0x0A83) ||
+				(ch == 0x0ABC) ||
+				(ch >= 0x0ABE && ch <= 0x0AC5) ||
+				(ch >= 0x0AC7 && ch <= 0x0AC9) ||
+				(ch >= 0x0ACB && ch <= 0x0ACD) ||
+				(ch >= 0x0B01 && ch <= 0x0B03) ||
+				(ch == 0x0B3C) ||
+				(ch >= 0x0B3E && ch <= 0x0B43) ||
+				(ch >= 0x0B47 && ch <= 0x0B48) ||
+				(ch >= 0x0B4B && ch <= 0x0B4D) ||
+				(ch >= 0x0B56 && ch <= 0x0B57) ||
+				(ch >= 0x0B82 && ch <= 0x0B83) ||
+				(ch >= 0x0BBE && ch <= 0x0BC2) ||
+				(ch >= 0x0BC6 && ch <= 0x0BC8) ||
+				(ch >= 0x0BCA && ch <= 0x0BCD) ||
+				(ch == 0x0BD7) ||
+				(ch >= 0x0C01 && ch <= 0x0C03) ||
+				(ch >= 0x0C3E && ch <= 0x0C44) ||
+				(ch >= 0x0C46 && ch <= 0x0C48) ||
+				(ch >= 0x0C4A && ch <= 0x0C4D) ||
+				(ch >= 0x0C55 && ch <= 0x0C56) ||
+				(ch >= 0x0C82 && ch <= 0x0C83) ||
+				(ch >= 0x0CBE && ch <= 0x0CC4) ||
+				(ch >= 0x0CC6 && ch <= 0x0CC8) ||
+				(ch >= 0x0CCA && ch <= 0x0CCD) ||
+				(ch >= 0x0CD5 && ch <= 0x0CD6) ||
+				(ch >= 0x0D02 && ch <= 0x0D03) ||
+				(ch >= 0x0D3E && ch <= 0x0D43) ||
+				(ch >= 0x0D46 && ch <= 0x0D48) ||
+				(ch >= 0x0D4A && ch <= 0x0D4D) ||
+				(ch == 0x0D57) ||
+				(ch == 0x0E31) ||
+				(ch >= 0x0E34 && ch <= 0x0E3A) ||
+				(ch >= 0x0E47 && ch <= 0x0E4E) ||
+				(ch == 0x0EB1) ||
+				(ch >= 0x0EB4 && ch <= 0x0EB9) ||
+				(ch >= 0x0EBB && ch <= 0x0EBC) ||
+				(ch >= 0x0EC8 && ch <= 0x0ECD) ||
+				(ch >= 0x0F18 && ch <= 0x0F19) ||
+				(ch == 0x0F35) ||
+				(ch == 0x0F37) ||
+				(ch == 0x0F39) ||
+				(ch == 0x0F3E) ||
+				(ch == 0x0F3F) ||
+				(ch >= 0x0F71 && ch <= 0x0F84) ||
+				(ch >= 0x0F86 && ch <= 0x0F8B) ||
+				(ch >= 0x0F90 && ch <= 0x0F95) ||
+				(ch == 0x0F97) ||
+				(ch >= 0x0F99 && ch <= 0x0FAD) ||
+				(ch >= 0x0FB1 && ch <= 0x0FB7) ||
+				(ch == 0x0FB9) ||
+				(ch >= 0x20D0 && ch <= 0x20DC) ||
+				(ch == 0x20E1) ||
+				(ch >= 0x302A && ch <= 0x302F) ||
+				(ch == 0x3099) ||
+				(ch == 0x309A);
+		}
+
+		private static bool IsExtender (int ch)
+		{
+			return
+				(ch == 0x00B7) ||
+				(ch == 0x02D0) ||
+				(ch == 0x02D1) ||
+				(ch == 0x0387) ||
+				(ch == 0x0640) ||
+				(ch == 0x0E46) ||
+				(ch == 0x0EC6) ||
+				(ch == 0x3005) ||
+				(ch >= 0x3031 && ch <= 0x3035) ||
+				(ch >= 0x309D && ch <= 0x309E) ||
+				(ch >= 0x30FC && ch <= 0x30FE);
+		}
+
+#endif
+		[Test]
+		public void IsName ()
+		{
+			Assertion.Assert (XmlReader.IsName ("foo"));
+			Assertion.Assert (!XmlReader.IsName ("1foo"));
+			Assertion.Assert (!XmlReader.IsName (" foo"));
+		}
+
+		[Test]
+		public void IsNameToken ()
+		{
+			Assertion.Assert (XmlReader.IsNameToken ("foo"));
+			Assertion.Assert (XmlReader.IsNameToken ("1foo"));
+			Assertion.Assert (!XmlReader.IsNameToken (" foo"));
+		}
+
+		[Test]
+		public void MoveToElementFromAttribute ()
+		{
+			string xml = @"<foo bar=""baz"" />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			Assertion.Assert (xmlReader.Read ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+			Assertion.Assert (xmlReader.MoveToFirstAttribute ());
+			Assertion.AssertEquals (XmlNodeType.Attribute, xmlReader.NodeType);
+			Assertion.Assert (xmlReader.MoveToElement ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+		}
+
+		[Test]
+		public void MoveToElementFromElement ()
+		{
+			string xml = @"<foo bar=""baz"" />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			Assertion.Assert (xmlReader.Read ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+			Assertion.Assert (!xmlReader.MoveToElement ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+		}
+
+		[Test]
+		public void MoveToFirstAttributeWithNoAttributes ()
+		{
+			string xml = @"<foo />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			Assertion.Assert (xmlReader.Read ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+			Assertion.Assert (!xmlReader.MoveToFirstAttribute ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+		}
+
+		[Test]
+		public void MoveToNextAttributeWithNoAttributes ()
+		{
+			string xml = @"<foo />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			Assertion.Assert (xmlReader.Read ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+			Assertion.Assert (!xmlReader.MoveToNextAttribute ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+		}
+
+		[Test]
+		public void MoveToNextAttribute()
+		{
+			string xml = @"<foo bar=""baz"" quux='quuux'/>";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			AssertStartDocument (xmlReader);
+
+			AssertNode (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				2 // attributeCount
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"bar", // name
+				String.Empty, // prefix
+				"bar", // localName
+				String.Empty, // namespaceURI
+				"baz" // value
+			);
+
+			AssertAttribute (
+				xmlReader, // xmlReader
+				"quux", // name
+				String.Empty, // prefix
+				"quux", // localName
+				String.Empty, // namespaceURI
+				"quuux" // value
+			);
+
+			Assertion.Assert (xmlReader.MoveToNextAttribute ());
+			Assertion.Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
+			Assertion.Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
+
+			Assertion.Assert (xmlReader.MoveToNextAttribute ());
+			Assertion.Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
+			Assertion.Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
+
+			Assertion.Assert (!xmlReader.MoveToNextAttribute ());
+
+            Assertion.Assert (xmlReader.MoveToElement ());
+
+			AssertNodeValues (
+				xmlReader, // xmlReader
+				XmlNodeType.Element, // nodeType
+				0, //depth
+				true, // isEmptyElement
+				"foo", // name
+				String.Empty, // prefix
+				"foo", // localName
+				String.Empty, // namespaceURI
+				String.Empty, // value
+				2 // attributeCount
+			);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void AttributeOrder ()
+		{
+			string xml = @"<foo _1='1' _2='2' _3='3' />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+
+			Assertion.Assert (xmlReader.Read ());
+			Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
+
+			Assertion.Assert (xmlReader.MoveToFirstAttribute ());
+			Assertion.AssertEquals ("_1", xmlReader.Name);
+			Assertion.Assert (xmlReader.MoveToNextAttribute ());
+			Assertion.AssertEquals ("_2", xmlReader.Name);
+			Assertion.Assert (xmlReader.MoveToNextAttribute ());
+			Assertion.AssertEquals ("_3", xmlReader.Name);
+
+			Assertion.Assert (!xmlReader.MoveToNextAttribute ());
+		}
+
+		[Test]
+		public void FragmentConstructor()
+		{
+			XmlDocument doc = new XmlDocument();
+//			doc.LoadXml("<root/>");
+
+			string xml = @"<foo><bar xmlns=""NSURI"">TEXT NODE</bar></foo>";
+			MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(xml));
+
+			XmlParserContext ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", "", "", "",
+				doc.BaseURI, "", XmlSpace.Default, Encoding.Default);
+
+			XmlTextReader xmlReader = new XmlTextReader(ms, XmlNodeType.Element, ctx);
+			AssertNode(xmlReader, XmlNodeType.Element, 0, false, "foo", "", "foo", "", "", 0);
+
+			AssertNode(xmlReader, XmlNodeType.Element, 1, false, "bar", "", "bar", "NSURI", "", 1);
+
+			AssertNode(xmlReader, XmlNodeType.Text, 2, false, "", "", "", "NSURI", "TEXT NODE", 0);
+
+			AssertNode(xmlReader, XmlNodeType.EndElement, 1, false, "bar", "", "bar", "NSURI", "", 0);
+
+			AssertNode(xmlReader, XmlNodeType.EndElement, 0, false, "foo", "", "foo", "", "", 0);
+
+			AssertEndDocument (xmlReader);
+		}
+
+		[Test]
+		public void AttributeWithCharacterReference ()
+		{
+			string xml = @"<a value='hello &amp; world' />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+			xmlReader.Read ();
+			Assertion.AssertEquals ("hello & world", xmlReader ["value"]);
+		}
+
+		[Test]
+		public void AttributeWithEntityReference ()
+		{
+			string xml = @"<a value='hello &ent; world' />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+			xmlReader.Read ();
+			xmlReader.MoveToFirstAttribute ();
+			xmlReader.ReadAttributeValue ();
+			Assertion.AssertEquals ("hello ", xmlReader.Value);
+			xmlReader.ReadAttributeValue ();
+			Assertion.AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
+			Assertion.AssertEquals ("ent", xmlReader.Name);
+			Assertion.AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
+			xmlReader.ReadAttributeValue ();
+			Assertion.AssertEquals (" world", xmlReader.Value);
+			Assertion.AssertEquals (XmlNodeType.Text, xmlReader.NodeType);
+			xmlReader.ReadAttributeValue ();
+			Assertion.AssertEquals (XmlNodeType.None, xmlReader.NodeType);
+			xmlReader.ReadAttributeValue ();
+			Assertion.AssertEquals (XmlNodeType.None, xmlReader.NodeType);
+		}
+
+		[Test]
+		public void QuoteChar ()
+		{
+			string xml = @"<a value='hello &amp; world' value2="""" />";
+			XmlReader xmlReader =
+				new XmlTextReader (new StringReader (xml));
+			xmlReader.Read ();
+			xmlReader.MoveToFirstAttribute ();
+			Assertion.AssertEquals ("First", '\'', xmlReader.QuoteChar);
+			xmlReader.MoveToNextAttribute ();
+			Assertion.AssertEquals ("Next", '"', xmlReader.QuoteChar);
+			xmlReader.MoveToFirstAttribute ();
+			Assertion.AssertEquals ("First.Again", '\'', xmlReader.QuoteChar);
+		}
+
+		[Test]
+		public void ReadInnerXmlWrongInit ()
+		{
+			// This behavior is different from XmlNodeReader.
+			XmlReader reader = new XmlTextReader (new StringReader ("<root>test of <b>mixed</b> string.</root>"));
+			reader.ReadInnerXml ();
+			Assertion.AssertEquals ("initial.ReadState", ReadState.Initial, reader.ReadState);
+			Assertion.AssertEquals ("initial.EOF", false, reader.EOF);
+			Assertion.AssertEquals ("initial.NodeType", XmlNodeType.None, reader.NodeType);
+		}
+
+		[Test]
+		public void TestExternalDocument ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.Load ("xmlfiles/encoding/utf-7.xml");
+		}
+	}
+}

+ 91 - 0
mcs/class/System.XML/Test/System.Xml/XmlTextTests.cs

@@ -0,0 +1,91 @@
+//
+// System.Xml.XmlTextWriterTests
+//
+// Authors:
+//   Kral Ferch <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlTextTests
+	{
+		XmlDocument document;
+		XmlText text;
+		bool inserted;
+		bool inserting;
+		bool changed;
+		bool changing;
+		bool removed;
+		bool removing;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+		}
+
+		private void EventNodeInserted(Object sender, XmlNodeChangedEventArgs e)
+		{
+			inserted = true;
+		}
+
+		private void EventNodeInserting (Object sender, XmlNodeChangedEventArgs e)
+		{
+			inserting = true;
+		}
+
+		private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
+		{
+			changed = true;
+		}
+
+		private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
+		{
+			changing = true;
+		}
+
+		private void EventNodeRemoved(Object sender, XmlNodeChangedEventArgs e)
+		{
+			removed = true;
+		}
+
+		private void EventNodeRemoving (Object sender, XmlNodeChangedEventArgs e)
+		{
+			removing = true;
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			text = document.CreateTextNode ("&<>\"'");
+			Assertion.AssertEquals (String.Empty, text.InnerXml);
+			Assertion.AssertEquals ("&amp;&lt;&gt;\"'", text.OuterXml);
+		}
+		
+		[Test]
+		public void SplitText ()
+		{
+			document.LoadXml ("<root>test text.</root>");
+			document.NodeInserted += new XmlNodeChangedEventHandler(EventNodeInserted);
+			document.NodeChanged += new XmlNodeChangedEventHandler(EventNodeChanged);
+			document.NodeRemoved += new XmlNodeChangedEventHandler(EventNodeRemoved);
+			XmlText t = document.DocumentElement.FirstChild as XmlText;
+			t.SplitText (5);
+			Assertion.AssertNotNull (t.NextSibling);
+			Assertion.AssertEquals ("test ", t.Value);
+			Assertion.AssertEquals ("text.", t.NextSibling.Value);
+			Assertion.Assert (changed);
+			Assertion.Assert (inserted);
+			Assertion.Assert (!removed);
+		}
+	}
+}

+ 1016 - 0
mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs

@@ -0,0 +1,1016 @@
+//
+// System.Xml.XmlTextWriterTests
+//
+// Authors:
+//   Kral Ferch <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2002 Kral Ferch
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlTextWriterTests
+	{
+		StringWriter sw;
+		XmlTextWriter xtw;
+
+		[SetUp]
+		public void GetReady ()
+		{
+			sw = new StringWriter ();
+			xtw = new XmlTextWriter (sw);
+			xtw.QuoteChar = '\'';
+		}
+
+		private string StringWriterText 
+		{
+			get { return sw.GetStringBuilder ().ToString (); }
+		}
+
+		[Test]
+		public void AttributeNamespacesNonNamespaceAttributeBefore ()
+		{
+			xtw.WriteStartElement ("foo");
+			xtw.WriteAttributeString("bar", "baz");
+			xtw.WriteAttributeString ("xmlns", "abc", null, "http://abc.def");
+			Assertion.AssertEquals ("<foo bar='baz' xmlns:abc='http://abc.def'", StringWriterText);
+		}
+
+		[Test]
+		public void AttributeNamespacesNonNamespaceAttributeAfter ()
+		{
+			xtw.WriteStartElement ("foo");
+
+			xtw.WriteAttributeString ("xmlns", "abc", null, "http://abc.def");
+			xtw.WriteAttributeString("bar", "baz");
+			Assertion.AssertEquals ("<foo xmlns:abc='http://abc.def' bar='baz'", StringWriterText);
+		}
+
+		[Test]
+		public void AttributeNamespacesThreeParamWithNullInNamespaceParam ()
+		{
+			xtw.WriteAttributeString ("xmlns", null, "http://abc.def");
+			Assertion.AssertEquals ("xmlns='http://abc.def'", StringWriterText);
+		}
+
+		[Test]
+		public void AttributeNamespacesThreeParamWithTextInNamespaceParam ()
+		{
+			try 
+			{
+				xtw.WriteAttributeString ("xmlns", "http://somenamespace.com", "http://abc.def");
+			} 
+			catch (ArgumentException) {}
+		}
+
+		[Test]
+		public void AttributeNamespacesWithNullInNamespaceParam ()
+		{
+			xtw.WriteAttributeString ("xmlns", "abc", null, "http://abc.def");
+			Assertion.AssertEquals ("xmlns:abc='http://abc.def'", StringWriterText);
+		}
+
+		[Test]
+		public void AttributeNamespacesWithTextInNamespaceParam ()
+		{
+			try {
+				xtw.WriteAttributeString ("xmlns", "abc", "http://somenamespace.com", "http://abc.def");
+			} catch (ArgumentException) {}
+		}
+
+		[Test]
+		public void AttributeNamespacesXmlnsXmlns ()
+		{
+			xtw.WriteStartElement ("foo");
+			try 
+			{
+				xtw.WriteAttributeString ("xmlns", "xmlns", null, "http://abc.def");
+				Assertion.Fail ("any prefix which name starts from \"xml\" must not be allowed.");
+			} 
+ 			catch (ArgumentException e) {}
+		}
+
+		[Test]
+		public void AttributeWriteAttributeString ()
+		{
+			xtw.WriteStartElement ("foo");
+
+			xtw.WriteAttributeString ("foo", "bar");
+			Assertion.AssertEquals ("<foo foo='bar'", StringWriterText);
+
+			xtw.WriteAttributeString ("bar", "");
+			Assertion.AssertEquals ("<foo foo='bar' bar=''", StringWriterText);
+
+			xtw.WriteAttributeString ("baz", null);
+			Assertion.AssertEquals ("<foo foo='bar' bar='' baz=''", StringWriterText);
+
+			try {
+				// Why does this pass Microsoft?
+				// Anyway, Mono should not allow such code.
+				xtw.WriteAttributeString ("", "quux");
+//				Assertion.AssertEquals ("<foo foo='bar' bar='' baz='' ='quux'", StringWriterText);
+				Assertion.Fail ("empty name not allowed.");
+			} catch (Exception) {
+			}
+
+			try {
+				// Why does this pass Microsoft?
+				// Anyway, Mono should not allow such code.
+				xtw.WriteAttributeString (null, "quuux");
+//				Assertion.AssertEquals ("<foo foo='bar' bar='' baz='' ='quux' ='quuux'", StringWriterText);
+				Assertion.Fail ("null name not allowed.");
+			} catch (Exception) {
+			}
+		}
+
+		[Test]
+		public void AttributeWriteAttributeStringNotInsideOpenStartElement ()
+		{
+			xtw.WriteStartElement ("foo");
+			xtw.WriteString ("bar");
+			
+			try 
+			{
+				xtw.WriteAttributeString ("baz", "quux");
+				Assertion.Fail ("Expected an InvalidOperationException to be thrown.");
+			} 
+			catch (InvalidOperationException) {}
+		}
+
+		[Test]
+		public void AttributeWriteAttributeStringWithoutParentElement ()
+		{
+			xtw.WriteAttributeString ("foo", "bar");
+			Assertion.AssertEquals ("foo='bar'", StringWriterText);
+
+			xtw.WriteAttributeString ("baz", "quux");
+			Assertion.AssertEquals ("foo='bar' baz='quux'", StringWriterText);
+		}
+
+		[Test]
+		public void CDataValid ()
+		{
+			xtw.WriteCData ("foo");
+			Assertion.AssertEquals ("WriteCData had incorrect output.", "<![CDATA[foo]]>", StringWriterText);
+		}
+
+		[Test]
+		public void CDataInvalid ()
+		{
+			try {
+				xtw.WriteCData("foo]]>bar");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+		}
+
+		[Test]
+		public void CloseOpenElements ()
+		{
+			xtw.WriteStartElement("foo");
+			xtw.WriteStartElement("bar");
+			xtw.WriteStartElement("baz");
+			xtw.Close();
+			Assertion.AssertEquals ("Close didn't write out end elements properly.", "<foo><bar><baz /></bar></foo>",	StringWriterText);
+		}
+
+		[Test]
+		public void CloseWriteAfter ()
+		{
+			xtw.WriteElementString ("foo", "bar");
+			xtw.Close ();
+
+			// WriteEndElement and WriteStartDocument aren't tested here because
+			// they will always throw different exceptions besides 'The Writer is closed.'
+			// and there are already tests for those exceptions.
+
+			try {
+				xtw.WriteCData ("foo");
+				Assertion.Fail ("WriteCData after Close Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
+			}
+
+			try {
+				xtw.WriteComment ("foo");
+				Assertion.Fail ("WriteComment after Close Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
+			}
+
+			try {
+				xtw.WriteProcessingInstruction ("foo", "bar");
+				Assertion.Fail ("WriteProcessingInstruction after Close Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
+			}
+
+			try {
+				xtw.WriteStartElement ("foo", "bar", "baz");
+				Assertion.Fail ("WriteStartElement after Close Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
+			}
+
+			try 
+			{
+				xtw.WriteAttributeString ("foo", "bar");
+				Assertion.Fail ("WriteAttributeString after Close Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) 
+			{
+				Assertion.AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
+			}
+
+			try {
+				xtw.WriteString ("foo");
+				Assertion.Fail ("WriteString after Close Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
+			}
+		}
+
+		[Test]
+		public void CommentValid ()
+		{
+			xtw.WriteComment ("foo");
+			Assertion.AssertEquals ("WriteComment had incorrect output.", "<!--foo-->", StringWriterText);
+		}
+
+		[Test]
+		public void CommentInvalid ()
+		{
+			try {
+				xtw.WriteComment("foo-");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+
+			try {
+				xtw.WriteComment("foo-->bar");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+		}
+
+		[Test]
+		public void ConstructorsAndBaseStream ()
+		{
+			Assertion.Assert ("BaseStream property returned wrong value.", Object.ReferenceEquals (null, this.xtw.BaseStream));
+
+			MemoryStream ms;
+			StreamReader sr;
+			XmlTextWriter xtw;
+
+			ms = new MemoryStream ();
+			xtw = new XmlTextWriter (ms, new UnicodeEncoding ());
+			xtw.WriteStartDocument ();
+			xtw.Flush ();
+			ms.Seek (0, SeekOrigin.Begin);
+			sr = new StreamReader (ms, Encoding.Unicode);
+			string expectedXmlDeclaration = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
+			string actualXmlDeclaration = sr.ReadToEnd();
+			Assertion.AssertEquals (expectedXmlDeclaration, actualXmlDeclaration);
+			Assertion.Assert ("BaseStream property returned wrong value.", Object.ReferenceEquals (ms, xtw.BaseStream));
+
+			ms = new MemoryStream ();
+			xtw = new XmlTextWriter (ms, new UnicodeEncoding ());
+			xtw.WriteStartDocument (true);
+			xtw.Flush ();
+			ms.Seek (0, SeekOrigin.Begin);
+			sr = new StreamReader (ms, Encoding.Unicode);
+			Assertion.AssertEquals ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>", sr.ReadToEnd ());
+
+			ms = new MemoryStream ();
+			xtw = new XmlTextWriter (ms, new UTF8Encoding ());
+			xtw.WriteStartDocument ();
+			xtw.Flush ();
+			ms.Seek (0, SeekOrigin.Begin);
+			sr = new StreamReader (ms, Encoding.UTF8);
+			Assertion.AssertEquals ("<?xml version=\"1.0\" encoding=\"utf-8\"?>", sr.ReadToEnd ());
+
+			ms = new MemoryStream ();
+			xtw = new XmlTextWriter (ms, null);
+			xtw.WriteStartDocument ();
+			xtw.Flush ();
+			ms.Seek (0, SeekOrigin.Begin);
+			sr = new StreamReader (ms, Encoding.UTF8);
+			Assertion.AssertEquals ("<?xml version=\"1.0\"?>", sr.ReadToEnd ());
+
+			ms = new MemoryStream ();
+			xtw = new XmlTextWriter (ms, null);
+			xtw.WriteStartDocument (true);
+			xtw.Flush ();
+			ms.Seek (0, SeekOrigin.Begin);
+			sr = new StreamReader (ms, Encoding.UTF8);
+			Assertion.AssertEquals ("<?xml version=\"1.0\" standalone=\"yes\"?>", sr.ReadToEnd ());
+			Assertion.Assert ("BaseStream property returned wrong value.", Object.ReferenceEquals (ms, xtw.BaseStream));
+		}
+
+		[Test]
+		public void DocumentStart ()
+		{
+			xtw.WriteStartDocument ();
+			Assertion.AssertEquals ("XmlDeclaration is incorrect.", "<?xml version='1.0' encoding='utf-16'?>", StringWriterText);
+
+			try 
+			{
+				xtw.WriteStartDocument ();
+				Assertion.Fail("Should have thrown an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.",
+					"WriteStartDocument should be the first call.", e.Message);
+			}
+
+			xtw = new XmlTextWriter (sw = new StringWriter ());
+			xtw.QuoteChar = '\'';
+			xtw.WriteStartDocument (true);
+			Assertion.AssertEquals ("<?xml version='1.0' encoding='utf-16' standalone='yes'?>", StringWriterText);
+
+			xtw = new XmlTextWriter (sw = new StringWriter ());
+			xtw.QuoteChar = '\'';
+			xtw.WriteStartDocument (false);
+			Assertion.AssertEquals ("<?xml version='1.0' encoding='utf-16' standalone='no'?>", StringWriterText);
+		}
+
+		[Test]
+		public void ElementEmpty ()
+		{
+			xtw.WriteStartElement ("foo");
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals ("Incorrect output.", "<foo />", StringWriterText);
+		}
+
+		[Test]
+		public void ElementWriteElementString ()
+		{
+			xtw.WriteElementString ("foo", "bar");
+			Assertion.AssertEquals ("WriteElementString has incorrect output.", "<foo>bar</foo>", StringWriterText);
+
+			xtw.WriteElementString ("baz", "");
+			Assertion.AssertEquals ("<foo>bar</foo><baz />", StringWriterText);
+
+			xtw.WriteElementString ("quux", null);
+			Assertion.AssertEquals ("<foo>bar</foo><baz /><quux />", StringWriterText);
+
+			xtw.WriteElementString ("", "quuux");
+			Assertion.AssertEquals ("<foo>bar</foo><baz /><quux /><>quuux</>", StringWriterText);
+
+			xtw.WriteElementString (null, "quuuux");
+			Assertion.AssertEquals ("<foo>bar</foo><baz /><quux /><>quuux</><>quuuux</>", StringWriterText);
+		}
+
+		[Test]
+		public void FormattingTest ()
+		{
+			xtw.Formatting = Formatting.Indented;
+			xtw.WriteStartDocument ();
+			xtw.WriteStartElement ("foo");
+			xtw.WriteElementString ("bar", "");
+			xtw.Close ();
+ 			Assertion.AssertEquals (String.Format ("<?xml version='1.0' encoding='utf-16'?>{0}<foo>{0}  <bar />{0}</foo>", Environment.NewLine), StringWriterText);
+		}
+
+		[Test]
+		public void FormattingInvalidXmlForFun ()
+		{
+			xtw.Formatting = Formatting.Indented;
+			xtw.IndentChar = 'x';
+			xtw.WriteStartDocument ();
+			xtw.WriteStartElement ("foo");
+			xtw.WriteStartElement ("bar");
+			xtw.WriteElementString ("baz", "");
+			xtw.Close ();
+ 			Assertion.AssertEquals (String.Format ("<?xml version='1.0' encoding='utf-16'?>{0}<foo>{0}xx<bar>{0}xxxx<baz />{0}xx</bar>{0}</foo>", Environment.NewLine), StringWriterText);
+		}
+
+		[Test]
+		public void FormattingFromRemarks ()
+		{
+			// Remarks section of on-line help for XmlTextWriter.Formatting suggests this test.
+			xtw.Formatting = Formatting.Indented; 
+			xtw.WriteStartElement ("ol"); 
+			xtw.WriteStartElement ("li"); 
+			xtw.WriteString ("The big "); // This means "li" now has a mixed content model. 
+			xtw.WriteElementString ("b", "E"); 
+			xtw.WriteElementString ("i", "lephant"); 
+			xtw.WriteString (" walks slowly."); 
+			xtw.WriteEndElement (); 
+			xtw.WriteEndElement ();
+ 			Assertion.AssertEquals (String.Format ("<ol>{0}  <li>The big <b>E</b><i>lephant</i> walks slowly.</li>{0}</ol>", Environment.NewLine), StringWriterText);
+		}
+
+		[Test]
+		public void LookupPrefix ()
+		{
+			xtw.WriteStartElement ("root");
+
+			xtw.WriteStartElement ("one");
+			xtw.WriteAttributeString ("xmlns", "foo", null, "http://abc.def");
+			xtw.WriteAttributeString ("xmlns", "bar", null, "http://ghi.jkl");
+			Assertion.AssertEquals ("foo", xtw.LookupPrefix ("http://abc.def"));
+			Assertion.AssertEquals ("bar", xtw.LookupPrefix ("http://ghi.jkl"));
+			xtw.WriteEndElement ();
+
+			xtw.WriteStartElement ("two");
+			xtw.WriteAttributeString ("xmlns", "baz", null, "http://mno.pqr");
+			xtw.WriteString("quux");
+			Assertion.AssertEquals ("baz", xtw.LookupPrefix ("http://mno.pqr"));
+			Assertion.AssertNull (xtw.LookupPrefix ("http://abc.def"));
+			Assertion.AssertNull (xtw.LookupPrefix ("http://ghi.jkl"));
+
+			Assertion.AssertNull (xtw.LookupPrefix ("http://bogus"));
+		}
+
+		[Test]
+		public void NamespacesAttributesPassingInNamespaces ()
+		{
+			xtw.Namespaces = false;
+			xtw.WriteStartElement ("foo");
+
+			// These shouldn't throw any exceptions since they don't pass in
+			// a namespace.
+			xtw.WriteAttributeString ("bar", "baz");
+			xtw.WriteAttributeString ("", "a", "", "b");
+			xtw.WriteAttributeString (null, "c", "", "d");
+			xtw.WriteAttributeString ("", "e", null, "f");
+			xtw.WriteAttributeString (null, "g", null, "h");
+
+			Assertion.AssertEquals ("<foo bar='baz' a='b' c='d' e='f' g='h'", StringWriterText);
+
+			// These should throw ArgumentException because they pass in a
+			// namespace when Namespaces = false.
+		}
+
+		[Test]
+		public void NamespacesElementsPassingInNamespaces ()
+		{
+			xtw.Namespaces = false;
+
+			// These shouldn't throw any exceptions since they don't pass in
+			// a namespace.
+			xtw.WriteElementString ("foo", "bar");
+			xtw.WriteStartElement ("baz");
+			xtw.WriteStartElement ("quux", "");
+			xtw.WriteStartElement ("quuux", null);
+			xtw.WriteStartElement (null, "a", null);
+			xtw.WriteStartElement (null, "b", "");
+			xtw.WriteStartElement ("", "c", null);
+			xtw.WriteStartElement ("", "d", "");
+
+			Assertion.AssertEquals ("<foo>bar</foo><baz><quux><quuux><a><b><c><d", StringWriterText);
+
+			// These should throw ArgumentException because they pass in a
+			// namespace when Namespaces = false.
+			try {
+				xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteStartElement ("foo", "http://netsack.com/");
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteStartElement ("foo", "bar", null);
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteStartElement ("foo", "bar", "");
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteStartElement ("foo", "", "");
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+		}
+
+		[Test]
+		public void NamespacesNoNamespaceClearsDefaultNamespace ()
+		{
+			xtw.WriteStartElement(String.Empty, "foo", "http://netsack.com/");
+			xtw.WriteStartElement(String.Empty, "bar", String.Empty);
+			xtw.WriteElementString("baz", String.Empty, String.Empty);
+			xtw.WriteEndElement();
+			xtw.WriteEndElement();
+			Assertion.AssertEquals ("XmlTextWriter is incorrectly outputting namespaces.",
+				"<foo xmlns='http://netsack.com/'><bar xmlns=''><baz /></bar></foo>", StringWriterText);
+		}
+
+		[Test]
+		public void NamespacesPrefix ()
+		{
+			xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
+			xtw.WriteStartElement ("foo", "baz", "http://netsack.com/");
+			xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
+			xtw.WriteEndElement ();
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals ("XmlTextWriter is incorrectly outputting prefixes.",
+				"<foo:bar xmlns:foo='http://netsack.com/'><foo:baz><foo:qux /></foo:baz></foo:bar>", StringWriterText);
+		}
+
+		[Test]
+		public void NamespacesPrefixWithEmptyAndNullNamespace ()
+		{
+			try {
+				xtw.WriteStartElement ("foo", "bar", "");
+				Assertion.Fail ("Should have thrown an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			try 
+			{
+				xtw.WriteStartElement ("foo", "bar", null);
+				Assertion.Fail ("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) {}
+		}
+
+		[Test]
+		public void NamespacesSettingWhenWriteStateNotStart ()
+		{
+			xtw.WriteStartElement ("foo");
+			try 
+			{
+				xtw.Namespaces = false;
+				Assertion.Fail ("Expected an InvalidOperationException.");
+			} 
+			catch (InvalidOperationException) {}
+			Assertion.AssertEquals (true, xtw.Namespaces);
+		}
+
+		[Test]
+		public void ProcessingInstructionValid ()
+		{
+			xtw.WriteProcessingInstruction("foo", "bar");
+			Assertion.AssertEquals ("WriteProcessingInstruction had incorrect output.", "<?foo bar?>", StringWriterText);
+		}
+
+		[Test]
+		public void ProcessingInstructionInvalid ()
+		{
+			try 
+			{
+				xtw.WriteProcessingInstruction("fo?>o", "bar");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+
+			try 
+			{
+				xtw.WriteProcessingInstruction("foo", "ba?>r");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+
+			try 
+			{
+				xtw.WriteProcessingInstruction("", "bar");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+
+			try 
+			{
+				xtw.WriteProcessingInstruction(null, "bar");
+				Assertion.Fail("Should have thrown an ArgumentException.");
+			} 
+			catch (ArgumentException) { }
+		}
+
+		[Test]
+		public void QuoteCharDoubleQuote ()
+		{
+			xtw.QuoteChar = '"';
+
+			// version, encoding, standalone
+			xtw.WriteStartDocument (true);
+			
+			// namespace declaration
+			xtw.WriteElementString ("foo", "http://netsack.com", "bar");
+
+			Assertion.AssertEquals ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?><foo xmlns=\"http://netsack.com\">bar</foo>", StringWriterText);
+
+
+		}
+
+		[Test]
+		public void QuoteCharInvalid ()
+		{
+			try {
+				xtw.QuoteChar = 'x';
+				Assertion.Fail ("Should have thrown an ArgumentException.");
+			} catch (ArgumentException) {}
+		}
+
+		[Test]
+		public void WriteBase64 ()
+		{
+			UTF8Encoding encoding = new UTF8Encoding();
+			byte[] fooBar = encoding.GetBytes("foobar");
+			xtw.WriteBase64 (fooBar, 0, 6);
+			Assertion.AssertEquals("Zm9vYmFy", StringWriterText);
+
+			try {
+				xtw.WriteBase64 (fooBar, 3, 6);
+				Assertion.Fail ("Expected an Argument Exception to be thrown.");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteBase64 (fooBar, -1, 6);
+				Assertion.Fail ("Expected an Argument Exception to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			try {
+				xtw.WriteBase64 (fooBar, 3, -1);
+				Assertion.Fail ("Expected an Argument Exception to be thrown.");
+			} catch (ArgumentOutOfRangeException) {}
+
+			try {
+				xtw.WriteBase64 (null, 0, 6);
+				Assertion.Fail ("Expected an Argument Exception to be thrown.");
+			} catch (ArgumentNullException) {}
+		}
+
+		[Test]
+		public void WriteCharEntity ()
+		{
+			xtw.WriteCharEntity ('a');
+			Assertion.AssertEquals ("&#x61;", StringWriterText);
+
+			xtw.WriteCharEntity ('A');
+			Assertion.AssertEquals ("&#x61;&#x41;", StringWriterText);
+
+			xtw.WriteCharEntity ('1');
+			Assertion.AssertEquals ("&#x61;&#x41;&#x31;", StringWriterText);
+
+			xtw.WriteCharEntity ('K');
+			Assertion.AssertEquals ("&#x61;&#x41;&#x31;&#x4B;", StringWriterText);
+
+			try {
+				xtw.WriteCharEntity ((char)0xd800);
+			} catch (ArgumentException) {}
+		}
+
+		[Test]
+		public void WriteEndAttribute ()
+		{
+			try 
+			{
+				xtw.WriteEndAttribute ();
+				Assertion.Fail ("Should have thrown an InvalidOperationException.");
+			}
+			catch (InvalidOperationException) {}
+		}
+
+		[Test]
+		public void WriteEndDocument ()
+		{
+			try {
+				xtw.WriteEndDocument ();
+				Assertion.Fail ("Expected an ArgumentException.");
+			} catch (ArgumentException) {}
+
+			xtw.WriteStartDocument ();
+
+			try 
+			{
+				xtw.WriteEndDocument ();
+				Assertion.Fail ("Expected an ArgumentException.");
+			} 
+			catch (ArgumentException) {}
+
+			xtw.WriteStartElement ("foo");
+			xtw.WriteStartAttribute ("bar", null);
+			Assertion.AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo bar='", StringWriterText);
+
+			xtw.WriteEndDocument ();
+			Assertion.AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo bar='' />", StringWriterText);
+			Assertion.AssertEquals (WriteState.Start, xtw.WriteState);
+		}
+
+		[Test]
+		public void WriteEndElement ()
+		{
+			try {
+				xtw.WriteEndElement ();
+				Assertion.Fail ("Should have thrown an InvalidOperationException.");
+			} catch (InvalidOperationException e) {
+				Assertion.AssertEquals ("Exception message is incorrect.", "There was no XML start tag open.", e.Message);
+			}
+
+			xtw.WriteStartElement ("foo");
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals ("<foo />", StringWriterText);
+
+			xtw.WriteStartElement ("bar");
+			xtw.WriteStartAttribute ("baz", null);
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals ("<foo /><bar baz='' />", StringWriterText);
+		}
+
+		[Test]
+		public void FullEndElement ()
+		{
+			xtw.WriteStartElement ("foo");
+			xtw.WriteFullEndElement ();
+			Assertion.AssertEquals ("<foo></foo>", StringWriterText);
+
+			xtw.WriteStartElement ("bar");
+			xtw.WriteAttributeString ("foo", "bar");
+			xtw.WriteFullEndElement ();
+			Assertion.AssertEquals ("<foo></foo><bar foo='bar'></bar>", StringWriterText);
+
+			xtw.WriteStartElement ("baz");
+			xtw.WriteStartAttribute ("bar", null);
+			xtw.WriteFullEndElement ();
+			Assertion.AssertEquals ("<foo></foo><bar foo='bar'></bar><baz bar=''></baz>", StringWriterText);
+		}
+
+		[Test]
+		public void WriteQualifiedName ()
+		{
+			xtw.WriteStartElement (null, "test", null);
+			xtw.WriteAttributeString ("xmlns", "me", null, "http://localhost/");
+			xtw.WriteQualifiedName ("bob", "http://localhost/");
+			xtw.WriteEndElement ();
+
+			Assertion.AssertEquals ("<test xmlns:me='http://localhost/'>me:bob</test>", StringWriterText);
+		}
+
+		[Test]
+		public void WriteRaw ()
+		{
+			xtw.WriteRaw("&<>\"'");
+			Assertion.AssertEquals ("&<>\"'", StringWriterText);
+
+			xtw.WriteRaw(null);
+			Assertion.AssertEquals ("&<>\"'", StringWriterText);
+
+			xtw.WriteRaw("");
+			Assertion.AssertEquals ("&<>\"'", StringWriterText);
+		}
+
+		[Test]
+		public void WriteRawInvalidInAttribute ()
+		{
+			xtw.WriteStartElement ("foo");
+			xtw.WriteStartAttribute ("bar", null);
+			xtw.WriteRaw ("&<>\"'");
+			xtw.WriteEndAttribute ();
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals ("<foo bar='&<>\"'' />", StringWriterText);
+		}
+
+		[Test]
+		public void WriteStateTest ()
+		{
+			Assertion.AssertEquals (WriteState.Start, xtw.WriteState);
+			xtw.WriteStartDocument ();
+			Assertion.AssertEquals (WriteState.Prolog, xtw.WriteState);
+			xtw.WriteStartElement ("root");
+			Assertion.AssertEquals (WriteState.Element, xtw.WriteState);
+			xtw.WriteElementString ("foo", "bar");
+			Assertion.AssertEquals (WriteState.Content, xtw.WriteState);
+			xtw.Close ();
+			Assertion.AssertEquals (WriteState.Closed, xtw.WriteState);
+		}
+
+		[Test]
+		public void WriteString ()
+		{
+			xtw.WriteStartDocument ();
+			try {
+				xtw.WriteString("foo");
+			} catch (InvalidOperationException) {}
+
+			// Testing attribute values
+
+			xtw.WriteStartElement ("foo");
+			xtw.WriteAttributeString ("bar", "&<>");
+			Assertion.AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo bar='&amp;&lt;&gt;'", StringWriterText);
+		}
+
+		[Test]
+		public void WriteAttributeStringSingleQuoteChar()
+		{
+			// When QuoteChar is single quote then replaces single quotes within attributes
+			// but not double quotes.
+			xtw.WriteStartElement ("foo");
+			xtw.WriteAttributeString ("bar", "\"baz\"");
+			xtw.WriteAttributeString ("quux", "'baz'");
+			Assertion.AssertEquals ("<foo bar='\"baz\"' quux='&apos;baz&apos;'", StringWriterText);
+		}
+
+		[Test]
+		public void WriteAttributeStringDoubleQuoteChar()
+		{
+			// When QuoteChar is double quote then replaces double quotes within attributes
+			// but not single quotes.
+			xtw.QuoteChar = '"';
+			xtw.WriteStartElement ("foo");
+			xtw.WriteAttributeString ("bar", "\"baz\"");
+			xtw.WriteAttributeString ("quux", "'baz'");
+			Assertion.AssertEquals ("<foo bar=\"&quot;baz&quot;\" quux=\"'baz'\"", StringWriterText);
+		}
+
+		[Test]
+		public void WriteStringWithEntities()
+		{
+			// Testing element values
+			xtw.QuoteChar = '\'';
+			xtw.WriteElementString ("foo", "&<>\"'");
+			Assertion.AssertEquals ("<foo>&amp;&lt;&gt;\"'</foo>", StringWriterText);
+		}
+
+		[Test]
+		public void XmlLang ()
+		{
+			Assertion.AssertNull (xtw.XmlLang);
+			
+			xtw.WriteStartElement ("foo");
+			xtw.WriteAttributeString ("xml", "lang", null, "langfoo");
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo'", StringWriterText);
+
+			xtw.WriteAttributeString ("boo", "yah");
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'", StringWriterText);
+			
+			xtw.WriteElementString("bar", "baz");
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>", StringWriterText);
+			
+			xtw.WriteString("baz");
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz", StringWriterText);
+			
+			xtw.WriteStartElement ("quux");
+			xtw.WriteStartAttribute ("xml", "lang", null);
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='", StringWriterText);
+			
+			xtw.WriteString("langbar");
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='", StringWriterText);
+			
+			xtw.WriteEndAttribute ();
+			Assertion.AssertEquals ("langbar", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'", StringWriterText);
+
+			// check if xml:lang repeats output even if same as current scope.
+			xtw.WriteStartElement ("joe");
+			xtw.WriteAttributeString ("xml", "lang", null, "langbar");
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'", StringWriterText);
+
+			
+			xtw.WriteElementString ("quuux", "squonk");
+			Assertion.AssertEquals ("langbar", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'><quuux>squonk</quuux>", StringWriterText);
+
+			xtw.WriteEndElement ();
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals ("langfoo", xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'><quuux>squonk</quuux></joe></quux>", StringWriterText);
+			
+			xtw.WriteEndElement ();
+			Assertion.AssertNull (xtw.XmlLang);
+			Assertion.AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'><quuux>squonk</quuux></joe></quux></foo>", StringWriterText);
+			
+			xtw.Close ();
+			Assertion.AssertNull (xtw.XmlLang);
+		}
+
+		// TODO: test operational aspects
+		[Test]
+		public void XmlSpaceTest ()
+		{
+			xtw.WriteStartElement ("foo");
+			Assertion.AssertEquals (XmlSpace.None, xtw.XmlSpace);
+
+			xtw.WriteStartElement ("bar");
+			xtw.WriteAttributeString ("xml", "space", null, "preserve");
+			Assertion.AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo><bar xml:space='preserve'",	StringWriterText);
+
+			xtw.WriteStartElement ("baz");
+			xtw.WriteAttributeString ("xml", "space", null, "preserve");
+			Assertion.AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'", StringWriterText);
+
+			xtw.WriteStartElement ("quux");
+			xtw.WriteStartAttribute ("xml", "space", null);
+			Assertion.AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText);
+
+			xtw.WriteString ("default");
+			Assertion.AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText);
+			
+			xtw.WriteEndAttribute ();
+			Assertion.AssertEquals (XmlSpace.Default, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='default'", StringWriterText);
+
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
+			xtw.WriteEndElement ();
+			Assertion.AssertEquals (XmlSpace.None, xtw.XmlSpace);
+
+			xtw.WriteStartElement ("quux");
+			try {
+				xtw.WriteAttributeString ("xml", "space", null, "bubba");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteAttributeString ("xml", "space", null, "PRESERVE");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteAttributeString ("xml", "space", null, "Preserve");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteAttributeString ("xml", "space", null, "Default");
+			} catch (ArgumentException) {}
+
+			try {
+				xtw.WriteWhitespace ("x");
+			} catch (ArgumentException) { }
+		}
+
+		[Test]
+		public void XmlSpaceRaw ()
+		{
+			xtw.WriteStartElement ("foo");
+			xtw.WriteStartAttribute ("xml", "space", null);
+			Assertion.AssertEquals (XmlSpace.None, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo xml:space='", StringWriterText);
+
+			xtw.WriteString ("default");
+			Assertion.AssertEquals (XmlSpace.None, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo xml:space='", StringWriterText);
+
+			xtw.WriteEndAttribute ();
+			Assertion.AssertEquals (XmlSpace.Default, xtw.XmlSpace);
+			Assertion.AssertEquals ("<foo xml:space='default'", StringWriterText);
+		}
+
+		[Test]
+		public void WriteAttributes ()
+		{
+			XmlDocument doc = new XmlDocument();
+			StringWriter sw = new StringWriter();
+			XmlWriter wr = new XmlTextWriter(sw);
+			StringBuilder sb = sw.GetStringBuilder();
+			XmlParserContext ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", XmlSpace.Default);
+			XmlTextReader xtr = new XmlTextReader("<?xml version='1.0' encoding='utf-8' standalone='no'?><root a1='A' b2='B' c3='C'><foo><bar /></foo></root>", XmlNodeType.Document, ctx);
+
+			xtr.Read();	// read XMLDecl
+			wr.WriteAttributes(xtr, false);
+			// This method don't always have to take this double-quoted style...
+			Assertion.AssertEquals("#WriteAttributes.XmlDecl.1", "version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"", sw.ToString().Trim());
+
+			sb.Remove(0, sb.Length);	// init
+			ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", XmlSpace.Default);
+			xtr = new XmlTextReader("<?xml version='1.0'		 standalone='no'?><root a1='A' b2='B' c3='C'><foo><bar /></foo></root>", XmlNodeType.Document, ctx);
+			xtr.Read();	// read XMLDecl
+			wr.WriteAttributes(xtr, false);
+			// This method don't always have to take this double-quoted style...
+			Assertion.AssertEquals("#WriteAttributes.XmlDecl.2", "version=\"1.0\" standalone=\"no\"", sw.ToString().Trim());
+
+			sb.Remove(0, sb.Length);	// init
+			xtr.Read();	// read root
+			wr.WriteStartElement(xtr.LocalName, xtr.Value);
+			wr.WriteAttributes(xtr, false);
+			wr.WriteEndElement();
+			wr.Close();
+			// This method don't always have to take this double-quoted style...
+			Assertion.AssertEquals("#WriteAttributes.Element", "<root a1=\"A\" b2=\"B\" c3=\"C\" />", sw.ToString().Trim());
+		}
+	}
+}

+ 126 - 0
mcs/class/System.XML/Test/System.Xml/XmlWhiteSpaceTests.cs

@@ -0,0 +1,126 @@
+//
+// System.Xml.XmlWhitespaceTests.cs
+//
+// Authors:
+//	Duncan Mak  ([email protected])
+//      Martin Willemoes Hansen ([email protected])
+//
+// (C) Ximian, Inc.
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlWhiteSpaceTests
+	{
+		XmlDocument document;
+		XmlDocument doc2;
+		XmlWhitespace whitespace;
+		XmlWhitespace broken;
+		XmlNode original;
+		XmlNode deep;
+		XmlNode shallow;
+		
+		[SetUp]
+		public void GetReady ()
+		{
+			document = new XmlDocument ();
+			document.LoadXml ("<root><foo></foo></root>");
+			XmlElement element = document.CreateElement ("foo");
+			whitespace = document.CreateWhitespace ("\r\n");
+			element.AppendChild (whitespace);
+
+			doc2 = new XmlDocument ();
+			doc2.PreserveWhitespace = true;
+		}
+
+		[Test]
+		public void InnerAndOuterXml ()
+		{
+			whitespace = doc2.CreateWhitespace ("\r\n\t ");
+			Assertion.AssertEquals (String.Empty, whitespace.InnerXml);
+			Assertion.AssertEquals ("\r\n\t ", whitespace.OuterXml);
+		}
+			
+		internal void XmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+		{
+//			assertequals (original.nodetype + " was incorrectly cloned.",
+//				      original.baseuri, cloned.baseuri);			
+			Assertion.AssertNull (cloned.ParentNode);
+			Assertion.AssertEquals ("Value incorrectly cloned",
+				       cloned.Value, original.Value);
+			
+                        Assertion.Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
+		}
+
+		[Test]
+		public void XmlWhitespaceBadConstructor ()
+		{
+			try {
+				broken = document.CreateWhitespace ("black");				
+
+			} catch (ArgumentException) {
+				return;
+
+			} catch (Exception) {
+				Assertion.Fail ("Incorrect Exception thrown.");
+			}
+		}
+
+		[Test]
+		public void XmlWhitespaceConstructor ()
+		{
+			Assertion.AssertEquals ("whitespace char didn't get copied right",
+				      "\r\n", whitespace.Data);
+		}
+			       
+		[Test]
+		public void XmlWhitespaceName ()
+		{
+			Assertion.AssertEquals (whitespace.NodeType + " Name property broken",
+				      whitespace.Name, "#whitespace");
+		}
+
+		[Test]
+		public void XmlWhitespaceLocalName ()
+		{
+			Assertion.AssertEquals (whitespace.NodeType + " LocalName property broken",
+				      whitespace.LocalName, "#whitespace");
+		}
+
+		[Test]
+		public void XmlWhitespaceNodeType ()
+		{
+			Assertion.AssertEquals ("XmlWhitespace NodeType property broken",
+				      whitespace.NodeType.ToString (), "Whitespace");
+		}
+
+		[Test]
+		public void XmlWhitespaceIsReadOnly ()
+		{
+			Assertion.AssertEquals ("XmlWhitespace IsReadOnly property broken",
+				      whitespace.IsReadOnly, false);
+		}
+
+		[Test]
+		public void XmlWhitespaceCloneNode ()
+		{
+			original = whitespace;
+
+			shallow = whitespace.CloneNode (false); // shallow
+			XmlNodeBaseProperties (original, shallow);
+						
+			deep = whitespace.CloneNode (true); // deep
+			XmlNodeBaseProperties (original, deep);			
+
+                        Assertion.AssertEquals ("deep cloning differs from shallow cloning",
+				      deep.OuterXml, shallow.OuterXml);
+		}
+	}
+}

+ 201 - 0
mcs/class/System.XML/Test/System.Xml/XmlWriterTests.cs

@@ -0,0 +1,201 @@
+//
+// System.Xml.XmlTextWriterTests
+//
+// Authors:
+//   Atsushi Enomoto <[email protected]>
+//   Martin Willemoes Hansen <[email protected]>
+//
+// (C) 2003 Atsushi Enomoto
+// (C) 2003 Martin Willemoes Hansen
+//
+//
+//  This class mainly checks inheritance and behaviors of XmlWriter.
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	[TestFixture]
+	public class XmlWriterTests
+	{
+		// MS.NET's not-overriden XmlWriter.WriteStartElement(name)
+		// invokes WriteStartElement(null, name, null). 
+		// WriteStartElement(name, ns) invokes (null, name, ns), too.
+		[Test]
+		public void StartElement ()
+		{
+			StartElementTestWriter xw = new StartElementTestWriter ();
+			xw.WriteStartDocument ();
+			xw.WriteStartElement ("test");
+			Assertion.AssertEquals ("StartElementOverride.NS", null, xw.NS);
+			Assertion.AssertEquals ("StartElementOverride.Prefix", null, xw.Prefix);
+			xw.NS = String.Empty;
+			xw.Prefix = String.Empty;
+			xw.WriteStartElement ("test", "urn:hoge");
+			Assertion.AssertEquals ("StartElementOverride.NS", "urn:hoge", xw.NS);
+			Assertion.AssertEquals ("StartElementOverride.Prefix", null, xw.Prefix);
+		}
+		
+		class StartElementTestWriter : DefaultXmlWriter
+		{
+			public StartElementTestWriter () : base () {}
+			public string NS = String.Empty;
+			public string Prefix = String.Empty;
+
+			public override void WriteStartElement (string prefix, string localName, string ns)
+			{
+				this.NS = ns;
+				this.Prefix = prefix;
+			}
+		}
+	}
+
+	internal class DefaultXmlWriter : XmlWriter
+	{
+		public DefaultXmlWriter () : base ()
+		{
+		}
+
+		public override void Close ()
+		{
+		}
+
+		public override void Flush ()
+		{
+		}
+
+		public override string LookupPrefix (string ns)
+		{
+			return null;
+		}
+
+		public override void WriteBase64 (byte [] buffer, int index, int count)
+		{
+		}
+
+		public override void WriteBinHex (byte [] buffer, int index, int count)
+		{
+		}
+
+		public override void WriteCData (string text)
+		{
+		}
+
+		public override void WriteCharEntity (char ch)
+		{
+		}
+
+		public override void WriteChars (char [] buffer, int index, int count)
+		{
+		}
+
+		public override void WriteComment (string text)
+		{
+		}
+
+		public override void WriteDocType (string name, string pubid, string sysid, string subset)
+		{
+		}
+
+		public override void WriteEndAttribute ()
+		{
+		}
+
+		public override void WriteEndDocument ()
+		{
+		}
+
+		public override void WriteEndElement ()
+		{
+		}
+
+		public override void WriteEntityRef (string name)
+		{
+		}
+
+		public override void WriteFullEndElement ()
+		{
+		}
+
+		public override void WriteName (string name)
+		{
+		}
+
+		public override void WriteNmToken (string name)
+		{
+		}
+
+		public override void WriteNode (XmlReader reader, bool defattr)
+		{
+		}
+
+		public override void WriteProcessingInstruction (string name, string text)
+		{
+		}
+
+		public override void WriteQualifiedName (string localName, string ns)
+		{
+		}
+
+		public override void WriteRaw (string data)
+		{
+		}
+
+		public override void WriteRaw (char [] buffer, int index, int count)
+		{
+		}
+
+		public override void WriteStartAttribute (string prefix, string localName, string ns)
+		{
+		}
+
+		public override void WriteStartDocument (bool standalone)
+		{
+		}
+
+		public override void WriteStartDocument ()
+		{
+		}
+
+		public override void WriteStartElement (string prefix, string localName, string ns)
+		{
+		}
+
+		public override void WriteString (string text)
+		{
+		}
+
+		public override void WriteSurrogateCharEntity (char lowChar, char highChar)
+		{
+		}
+
+		public override void WriteWhitespace (string ws)
+		{
+		}
+
+		public override WriteState WriteState {
+			get {
+				return WriteState.Start;
+			}
+		}
+
+		public override string XmlLang {
+			get {
+				return null;
+			}
+		}
+
+		public override XmlSpace XmlSpace {
+			get {
+				return XmlSpace.None;
+			}
+		}
+
+	}
+}