XmlAttributeCollectionTests.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // XmlAttributeCollectionTests.cs : Tests for the XmlAttributeCollection class
  2. //
  3. // Author: Matt Hunter <[email protected]>
  4. //
  5. // <c> 2002 Matt Hunter
  6. using System;
  7. using System.Xml;
  8. using System.Text;
  9. using System.IO;
  10. using NUnit.Framework;
  11. namespace MonoTests.System.Xml
  12. {
  13. public class XmlAttributeCollectionTests : TestCase
  14. {
  15. public XmlAttributeCollectionTests() : base("MonoTests.System.Xml.XmlAttributeCollectionTests testsuite") { }
  16. public XmlAttributeCollectionTests(string name) : base(name) { }
  17. private XmlDocument document;
  18. protected override void SetUp()
  19. {
  20. document = new XmlDocument ();
  21. }
  22. public void TestRemoveAll ()
  23. {
  24. StringBuilder xml = new StringBuilder ();
  25. xml.Append ("<?xml version=\"1.0\" ?><library><book type=\"non-fiction\" price=\"34.95\"> ");
  26. xml.Append ("<title type=\"intro\">XML Fun</title> " );
  27. xml.Append ("<author>John Doe</author></book></library>");
  28. MemoryStream memoryStream = new MemoryStream (Encoding.UTF8.GetBytes (xml.ToString ()));
  29. document = new XmlDocument ();
  30. document.Load (memoryStream);
  31. XmlNodeList bookList = document.GetElementsByTagName ("book");
  32. XmlNode xmlNode = bookList.Item (0);
  33. XmlElement xmlElement = xmlNode as XmlElement;
  34. XmlAttributeCollection attributes = xmlElement.Attributes;
  35. attributes.RemoveAll ();
  36. AssertEquals ("not all attributes removed.", false, xmlElement.HasAttribute ("type"));
  37. }
  38. }
  39. }