2 // System.Xml.XmlTextWriterTests
5 // Kral Ferch <kral_ferch@hotmail.com>
13 using NUnit.Framework;
15 namespace MonoTests.System.Xml
17 public class XmlCharacterDataTests : TestCase
19 public XmlCharacterDataTests () : base ("MonoTests.System.Xml.XmlCharacterDataTests testsuite") {}
20 public XmlCharacterDataTests (string name) : base (name) {}
27 protected override void SetUp ()
29 document = new XmlDocument ();
30 document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
31 document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChanging);
32 comment = document.CreateComment ("foo");
35 private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
40 private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
45 public void TestAppendData ()
49 comment.AppendData ("bar");
52 AssertEquals ("foobar", comment.Data);
54 comment.Value = "foo";
55 comment.AppendData (null);
56 AssertEquals ("foo", comment.Data);
59 public void TestDeleteData ()
61 comment.Value = "bar";
64 comment.DeleteData (1, 1);
67 AssertEquals ("br", comment.Data);
71 comment.Value = "foo";
72 comment.DeleteData(-1, 1);
73 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
75 catch (ArgumentOutOfRangeException) {}
77 comment.Value = "foo";
78 comment.DeleteData(1, 5);
79 AssertEquals("f", comment.Data);
81 comment.Value = "foo";
82 comment.DeleteData(3, 10);
83 AssertEquals("foo", comment.Data);
86 public void TestInsertData ()
88 comment.Value = "foobaz";
91 comment.InsertData (3, "bar");
94 AssertEquals ("foobarbaz", comment.Data);
98 comment.Value = "foo";
99 comment.InsertData (-1, "bar");
100 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
102 catch (ArgumentOutOfRangeException) {}
104 comment.Value = "foo";
105 comment.InsertData (3, "bar");
106 AssertEquals ("foobar", comment.Data);
110 comment.Value = "foo";
111 comment.InsertData (4, "bar");
112 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
114 catch (ArgumentOutOfRangeException) {}
118 comment.Value = "foo";
119 comment.InsertData (1, null);
120 Fail ("Expected an ArgumentNullException to be thrown.");
122 catch (ArgumentNullException) {}
125 public void TestReplaceData ()
129 comment.ReplaceData (0, 3, "bar");
132 AssertEquals ("bar", comment.Data);
134 comment.Value = "foo";
135 comment.ReplaceData (2, 3, "bar");
136 AssertEquals ("fobar", comment.Data);
138 comment.Value = "foo";
139 comment.ReplaceData (3, 3, "bar");
140 AssertEquals ("foobar", comment.Data);
144 comment.Value = "foo";
145 comment.ReplaceData (4, 3, "bar");
146 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
148 catch (ArgumentOutOfRangeException) {}
152 comment.Value = "foo";
153 comment.ReplaceData (-1, 3, "bar");
154 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
156 catch (ArgumentOutOfRangeException) {}
158 comment.Value = "foo";
159 comment.ReplaceData (0, 2, "bar");
160 AssertEquals ("baro", comment.Data);
162 comment.Value = "foo";
163 comment.ReplaceData (0, 5, "bar");
164 AssertEquals ("bar", comment.Data);
168 comment.Value = "foo";
169 comment.ReplaceData (1, 1, null);
170 Fail ("Expected an ArgumentNullException to be thrown.");
172 catch (ArgumentNullException) {}