implementing tests: XmlElementTests.TestSetAttributeNode
[mono.git] / mcs / class / System.XML / Test / XmlAttributeCollectionTests.cs
1 // XmlAttributeCollectionTests.cs : Tests for the XmlAttributeCollection class
2 //
3 // Author: Matt Hunter <xrkune@tconl.com>
4 //
5 // <c> 2002 Matt Hunter
6
7 using System;
8 using System.Xml;
9 using System.Text;
10 using System.IO;
11
12 using NUnit.Framework;
13
14 namespace MonoTests.System.Xml
15 {
16         public class XmlAttributeCollectionTests : TestCase
17         {
18                 public XmlAttributeCollectionTests() : base("MonoTests.System.Xml.XmlAttributeCollectionTests testsuite") { }
19                 public XmlAttributeCollectionTests(string name) : base(name) { }
20
21                 private XmlDocument document;
22
23                 protected override void SetUp()
24                 {
25                         document = new XmlDocument ();
26                 }
27                 public void TestRemoveAll ()
28                 {
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>");
33
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"));
43                 }
44
45                 public void TestAppend () 
46                 {
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
56                 }
57
58         }
59 }