XmlCharacterDataTests.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // System.Xml.XmlTextWriterTests
  3. //
  4. // Author:
  5. // Kral Ferch <[email protected]>
  6. //
  7. // (C) 2002 Kral Ferch
  8. //
  9. using System;
  10. using System.Xml;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Xml
  13. {
  14. public class XmlCharacterDataTests : TestCase
  15. {
  16. public XmlCharacterDataTests () : base ("MonoTests.System.Xml.XmlCharacterDataTests testsuite") {}
  17. public XmlCharacterDataTests (string name) : base (name) {}
  18. XmlDocument document;
  19. XmlComment comment;
  20. bool changed;
  21. bool changing;
  22. protected override void SetUp ()
  23. {
  24. document = new XmlDocument ();
  25. document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
  26. document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChanging);
  27. comment = document.CreateComment ("foo");
  28. }
  29. private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
  30. {
  31. changed = true;
  32. }
  33. private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
  34. {
  35. changing = true;
  36. }
  37. public void TestAppendData ()
  38. {
  39. changed = false;
  40. changing = false;
  41. comment.AppendData ("bar");
  42. Assert (changed);
  43. Assert (changing);
  44. AssertEquals ("foobar", comment.Data);
  45. comment.Value = "foo";
  46. comment.AppendData (null);
  47. AssertEquals ("foo", comment.Data);
  48. }
  49. public void TestDeleteData ()
  50. {
  51. comment.Value = "bar";
  52. changed = false;
  53. changing = false;
  54. comment.DeleteData (1, 1);
  55. Assert (changed);
  56. Assert (changing);
  57. AssertEquals ("br", comment.Data);
  58. try
  59. {
  60. comment.Value = "foo";
  61. comment.DeleteData(-1, 1);
  62. Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
  63. }
  64. catch (ArgumentOutOfRangeException) {}
  65. comment.Value = "foo";
  66. comment.DeleteData(1, 5);
  67. AssertEquals("f", comment.Data);
  68. comment.Value = "foo";
  69. comment.DeleteData(3, 10);
  70. AssertEquals("foo", comment.Data);
  71. }
  72. public void TestInsertData ()
  73. {
  74. comment.Value = "foobaz";
  75. changed = false;
  76. changing = false;
  77. comment.InsertData (3, "bar");
  78. Assert (changed);
  79. Assert (changing);
  80. AssertEquals ("foobarbaz", comment.Data);
  81. try
  82. {
  83. comment.Value = "foo";
  84. comment.InsertData (-1, "bar");
  85. Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
  86. }
  87. catch (ArgumentOutOfRangeException) {}
  88. comment.Value = "foo";
  89. comment.InsertData (3, "bar");
  90. AssertEquals ("foobar", comment.Data);
  91. try
  92. {
  93. comment.Value = "foo";
  94. comment.InsertData (4, "bar");
  95. Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
  96. }
  97. catch (ArgumentOutOfRangeException) {}
  98. try
  99. {
  100. comment.Value = "foo";
  101. comment.InsertData (1, null);
  102. Fail ("Expected an ArgumentNullException to be thrown.");
  103. }
  104. catch (ArgumentNullException) {}
  105. }
  106. public void TestReplaceData ()
  107. {
  108. changed = false;
  109. changing = false;
  110. comment.ReplaceData (0, 3, "bar");
  111. Assert (changed);
  112. Assert (changing);
  113. AssertEquals ("bar", comment.Data);
  114. comment.Value = "foo";
  115. comment.ReplaceData (2, 3, "bar");
  116. AssertEquals ("fobar", comment.Data);
  117. comment.Value = "foo";
  118. comment.ReplaceData (3, 3, "bar");
  119. AssertEquals ("foobar", comment.Data);
  120. try
  121. {
  122. comment.Value = "foo";
  123. comment.ReplaceData (4, 3, "bar");
  124. Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
  125. }
  126. catch (ArgumentOutOfRangeException) {}
  127. try
  128. {
  129. comment.Value = "foo";
  130. comment.ReplaceData (-1, 3, "bar");
  131. Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
  132. }
  133. catch (ArgumentOutOfRangeException) {}
  134. comment.Value = "foo";
  135. comment.ReplaceData (0, 2, "bar");
  136. AssertEquals ("baro", comment.Data);
  137. comment.Value = "foo";
  138. comment.ReplaceData (0, 5, "bar");
  139. AssertEquals ("bar", comment.Data);
  140. try
  141. {
  142. comment.Value = "foo";
  143. comment.ReplaceData (1, 1, null);
  144. Fail ("Expected an ArgumentNullException to be thrown.");
  145. }
  146. catch (ArgumentNullException) {}
  147. }
  148. }
  149. }