XmlAttributeTests.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // XmlAttributeTests.cs : Tests for the XmlAttribute class
  2. //
  3. // Author: Mike Kestner <[email protected]>
  4. //
  5. // <c> 2002 Mike Kestner
  6. using System;
  7. using System.Xml;
  8. using NUnit.Framework;
  9. namespace MonoTests.System.Xml
  10. {
  11. public class XmlAttributeTests : TestCase
  12. {
  13. public XmlAttributeTests() : base("MonoTests.System.Xml.XmlAttributeTests testsuite") { }
  14. public XmlAttributeTests(string name) : base(name) { }
  15. XmlDocument doc;
  16. XmlAttribute attr;
  17. protected override void SetUp()
  18. {
  19. doc = new XmlDocument();
  20. attr = doc.CreateAttribute("attr1");
  21. attr.Value = "val1";
  22. }
  23. public void TestAttributes()
  24. {
  25. AssertNull(attr.Attributes);
  26. }
  27. public void TestAttributeInnerAndOuterXml ()
  28. {
  29. attr = doc.CreateAttribute ("foo", "bar", "http://abc.def");
  30. attr.Value = "baz";
  31. AssertEquals ("baz", attr.InnerXml);
  32. AssertEquals ("foo:bar=\"baz\"", attr.OuterXml);
  33. }
  34. public void TestAttributeWithNoValue ()
  35. {
  36. XmlAttribute attribute = doc.CreateAttribute ("name");
  37. AssertEquals (String.Empty, attribute.Value);
  38. Assert (!attribute.HasChildNodes);
  39. AssertNull (attribute.FirstChild);
  40. AssertNull (attribute.LastChild);
  41. AssertEquals (0, attribute.ChildNodes.Count);
  42. }
  43. public void TestAttributeWithValue ()
  44. {
  45. XmlAttribute attribute = doc.CreateAttribute ("name");
  46. attribute.Value = "value";
  47. AssertEquals ("value", attribute.Value);
  48. Assert (attribute.HasChildNodes);
  49. AssertNotNull (attribute.FirstChild);
  50. AssertNotNull (attribute.LastChild);
  51. AssertEquals (1, attribute.ChildNodes.Count);
  52. AssertEquals (XmlNodeType.Text, attribute.ChildNodes [0].NodeType);
  53. AssertEquals ("value", attribute.ChildNodes [0].Value);
  54. }
  55. public void TestHasChildNodes()
  56. {
  57. Assert(attr.HasChildNodes);
  58. }
  59. public void TestName()
  60. {
  61. AssertEquals("attr1", attr.Name);
  62. }
  63. public void TestNodeType()
  64. {
  65. AssertEquals(XmlNodeType.Attribute, attr.NodeType);
  66. }
  67. public void TestOwnerDocument()
  68. {
  69. AssertSame(doc, attr.OwnerDocument);
  70. }
  71. public void TestParentNode()
  72. {
  73. AssertNull("Attr parents not allowed", attr.ParentNode);
  74. }
  75. public void TestValue()
  76. {
  77. AssertEquals("val1", attr.Value);
  78. }
  79. }
  80. }