Implementation and tests for XmlAttributeCollection.RemoveAll and XmlElement.RemoveAl...
authorJason Diamond <injektilo@mono-cvs.ximian.com>
Fri, 23 Aug 2002 05:09:53 +0000 (05:09 -0000)
committerJason Diamond <injektilo@mono-cvs.ximian.com>
Fri, 23 Aug 2002 05:09:53 +0000 (05:09 -0000)
svn path=/trunk/mcs/; revision=6926

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlAttributeCollection.cs
mcs/class/System.XML/System.Xml/XmlElement.cs
mcs/class/System.XML/Test/AllTests.cs
mcs/class/System.XML/Test/ChangeLog
mcs/class/System.XML/Test/MonoMicro.Test.csproj
mcs/class/System.XML/Test/System.XML_linux_test.args
mcs/class/System.XML/Test/XmlAttributeCollectionTests.cs [new file with mode: 0644]
mcs/class/System.XML/Test/XmlElementTests.cs

index bb2e2a8ab7dd71b7a0d7bbee20544b5eb2903964..a44fce96d1b19fad6dac4cbd9798943c7dbae557 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-22  Jason Diamond <jason@injektilo.org>
+
+       * XmlAttributeCollection.cs, XmlElement.cs: Implementation of RemoveAll
+       and RemoveAllAttributes courtesy of Matt Hunter <xrkune@tconl.com>.
+
 2002-08-22  Jason Diamond <jason@injektilo.org>
 
        * XmlElement.cs: Correction to previous GetElementsByTagName patch
index 203d8d33f155a323a3128be24c00dc9740a70b67..3c3afbf5385d3ca093e6155a5f847c5921e5bf96 100644 (file)
@@ -96,10 +96,11 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public virtual void RemoveAll () 
                {
-                       throw new NotImplementedException ();
+                       while (this.Count > 0)
+                               base.RemoveNamedItem (this.Item (0).Name);
+                       
                }
 
                [MonoTODO]
index 11802a285acc4a44191b0c91c5f853f35c5cb974..5c3460245967f4f94ca5edd20860df9cb7044caf 100644 (file)
@@ -217,10 +217,9 @@ namespace System.Xml
                        attributes.RemoveAll ();
                }
 
-               [MonoTODO]
                public virtual void RemoveAllAttributes ()
                {
-                       throw new NotImplementedException ();
+                       attributes.RemoveAll ();
                }
 
                [MonoTODO]
index a1b0583c08ac2fc0aa8902db6850199084e036cb..1ebb29520791dfe02f99fa766dcd5575d3a9ca91 100644 (file)
@@ -25,6 +25,7 @@ namespace MonoTests.System.Xml
                                suite.AddTest (new TestSuite (typeof (XmlTextWriterTests)));
                                suite.AddTest (new TestSuite (typeof (XmlNamespaceManagerTests)));
                                suite.AddTest (new TestSuite (typeof (XmlAttributeTests)));
+                               suite.AddTest (new TestSuite (typeof (XmlAttributeCollectionTests)));
                                suite.AddTest (new TestSuite (typeof (XmlDocumentTests)));
                                suite.AddTest (new TestSuite (typeof (NameTableTests)));
                                suite.AddTest (new TestSuite (typeof (XmlElementTests)));
index 86707218b629b5ff32c2fdc9a20d689378361fd6..cb73def2b85cee7c36477bc9e63e23cab3174550 100644 (file)
@@ -1,3 +1,10 @@
+2002-08-22  Jason Diamond <jason@injektilo.org>
+
+       * AllTests.cs, System.XML_linux_test.args, 
+       XmlAttributeCollectionTests.cs,XmlElementTests.cs: Added test for 
+       RemoveAll and RemoveAllAttributes courtesy of Matt Hunter
+       <xrkune@tconl.com>.
+
 2002-08-22  Jason Diamond <jason@injektilo.org>
 
        * XmlElementTests.cs: Correction to previous GetElementsByTagName
index a14116ecdf102e27b783707593aacac5a43ed0cd..a90ea037a175c82810cf0f5d48d772a56b461fcd 100644 (file)
@@ -74,7 +74,7 @@
                 />
                 <Reference
                     Name = "System.XML"
-                    AssemblyName = "System.XML"
+                    AssemblyName = "System.Xml"
                     HintPath = "..\obj\Debug\System.XML.dll"
                 />
             </References>
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <File
+                    RelPath = "XmlAttributeCollectionTests.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
                 <File
                     RelPath = "XmlAttributeTests.cs"
                     SubType = "Code"
index a2ea845739640a388a3689c069c9c6b493219bac..51c948e981281ecdd95fe8be01dbe2fbb0d5f937 100644 (file)
@@ -7,6 +7,7 @@
 AllTests.cs
 NameTableTests.cs
 SelectNodesTests.cs
+XmlAttributeCollectionTests.cs
 XmlAttributeTests.cs
 XmlCDataSectionTests.cs
 XmlCharacterDataTests.cs
diff --git a/mcs/class/System.XML/Test/XmlAttributeCollectionTests.cs b/mcs/class/System.XML/Test/XmlAttributeCollectionTests.cs
new file mode 100644 (file)
index 0000000..218691f
--- /dev/null
@@ -0,0 +1,46 @@
+// XmlAttributeCollectionTests.cs : Tests for the XmlAttributeCollection class
+//
+// Author: Matt Hunter <xrkune@tconl.com>
+//
+// <c> 2002 Matt Hunter
+
+using System;
+using System.Xml;
+using System.Text;
+using System.IO;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+       public class XmlAttributeCollectionTests : TestCase
+       {
+               public XmlAttributeCollectionTests() : base("MonoTests.System.Xml.XmlAttributeCollectionTests testsuite") { }
+               public XmlAttributeCollectionTests(string name) : base(name) { }
+
+               private XmlDocument document;
+
+               protected override void SetUp()
+               {
+                       document = new XmlDocument ();
+               }
+               public void TestRemoveAll ()
+               {
+                       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 ();
+                       AssertEquals ("not all attributes removed.", false, xmlElement.HasAttribute ("type"));
+               }
+
+       }
+}
index a8561f393735485b9b619d94b02862771a8ba0ad..83a45b1e45f7431fd0a7e177444acd52fe9b0430 100644 (file)
@@ -188,5 +188,22 @@ namespace MonoTests.System.Xml
                        XmlElement element = document.CreateElement ("foo", "bar", "#foo");
                        AssertEquals ("<foo:bar xmlns:foo=\"#foo\" />", element.OuterXml);
                }               
+
+               public void TestRemoveAllAttributes ()
+               {
+                       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 ();
+                       AssertEquals ("attributes not properly removed.", false, xmlElement.HasAttribute ("type"));
+               }
        }
 }