1 // XmlAttributeCollectionTests.cs : Tests for the XmlAttributeCollection class
3 // Author: Matt Hunter <xrkune@tconl.com>
5 // <c> 2002 Matt Hunter
12 using NUnit.Framework;
14 namespace MonoTests.System.Xml
16 public class XmlAttributeCollectionTests : TestCase
18 public XmlAttributeCollectionTests() : base("MonoTests.System.Xml.XmlAttributeCollectionTests testsuite") { }
19 public XmlAttributeCollectionTests(string name) : base(name) { }
21 private XmlDocument document;
23 protected override void SetUp()
25 document = new XmlDocument ();
27 public void TestRemoveAll ()
29 StringBuilder xml = new StringBuilder ();
30 xml.Append ("<?xml version=\"1.0\" ?><library><book type=\"non-fiction\" price=\"34.95\"> ");
31 xml.Append ("<title type=\"intro\">XML Fun</title> " );
32 xml.Append ("<author>John Doe</author></book></library>");
34 MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
35 document = new XmlDocument ();
36 document.Load (memoryStream);
37 XmlNodeList bookList = document.GetElementsByTagName ("book");
38 XmlNode xmlNode = bookList.Item (0);
39 XmlElement xmlElement = xmlNode as XmlElement;
40 XmlAttributeCollection attributes = xmlElement.Attributes;
41 attributes.RemoveAll ();
42 AssertEquals ("not all attributes removed.", false, xmlElement.HasAttribute ("type"));
45 public void TestAppend ()
47 XmlDocument xmlDoc = new XmlDocument ();
\r
48 XmlElement xmlEl = xmlDoc.CreateElement ("TestElement");
\r
49 XmlAttribute xmlAttribute = xmlEl.SetAttributeNode ("attr1", "namespace1");
\r
50 XmlNode xmlNode = xmlDoc.CreateNode (XmlNodeType.Attribute, "attr3", "namespace1");
\r
51 XmlAttribute xmlAttribute3 = xmlNode as XmlAttribute;
\r
52 XmlAttributeCollection attributeCol = xmlEl.Attributes;
\r
53 xmlAttribute3 = attributeCol.Append (xmlAttribute3);
\r
54 AssertEquals ("attribute name not properly created.", true, xmlAttribute3.Name.Equals ("attr3"));
\r
55 AssertEquals ("attribute namespace not properly created.", true, xmlAttribute3.NamespaceURI.Equals ("namespace1"));
\r