2 // System.Xml.XmlTextWriterTests
4 // Author: Kral Ferch <kral_ferch@hotmail.com>
5 // Author: Martin Willemoes Hansen <mwh@sysrq.dk>
8 // (C) 2003 Martin Willemoes Hansen
14 using NUnit.Framework;
16 namespace MonoTests.System.Xml
19 public class XmlCharacterDataTests
27 public void GetReady ()
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)
46 public void AppendData ()
50 comment.AppendData ("bar");
51 Assert.IsTrue (changed);
52 Assert.IsTrue (changing);
53 Assert.AreEqual ("foobar", comment.Data);
55 comment.Value = "foo";
56 comment.AppendData (null);
57 Assert.AreEqual ("foo", comment.Data);
61 public void DeleteData ()
63 comment.Value = "bar";
66 comment.DeleteData (1, 1);
67 Assert.IsTrue (changed);
68 Assert.IsTrue (changing);
69 Assert.AreEqual ("br", comment.Data);
73 comment.Value = "foo";
74 comment.DeleteData(-1, 1);
75 Assert.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
77 catch (ArgumentOutOfRangeException) {}
79 comment.Value = "foo";
80 comment.DeleteData(1, 5);
81 Assert.AreEqual ("f", comment.Data);
83 comment.Value = "foo";
84 comment.DeleteData(3, 10);
85 Assert.AreEqual ("foo", comment.Data);
90 [Category ("NotDotNet")] // enbug in 2.0
92 public void InsertData ()
94 comment.Value = "foobaz";
97 comment.InsertData (3, "bar");
98 Assert.IsTrue (changed);
99 Assert.IsTrue (changing);
100 Assert.AreEqual ("foobarbaz", comment.Data);
104 comment.Value = "foo";
105 comment.InsertData (-1, "bar");
106 Assert.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
108 catch (ArgumentOutOfRangeException) {}
110 comment.Value = "foo";
111 comment.InsertData (3, "bar");
112 Assert.AreEqual ("foobar", comment.Data);
116 comment.Value = "foo";
117 comment.InsertData (4, "bar");
118 Assert.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
120 catch (ArgumentOutOfRangeException) {}
124 comment.Value = "foo";
125 comment.InsertData (1, null);
126 Assert.Fail ("Expected an ArgumentNullException to be thrown.");
128 catch (ArgumentNullException) {}
133 [Category ("NotDotNet")] // enbug in 2.0
135 public void ReplaceData ()
139 comment.ReplaceData (0, 3, "bar");
140 Assert.IsTrue (changed);
141 Assert.IsTrue (changing);
142 Assert.AreEqual ("bar", comment.Data);
144 comment.Value = "foo";
145 comment.ReplaceData (2, 3, "bar");
146 Assert.AreEqual ("fobar", comment.Data);
148 comment.Value = "foo";
149 comment.ReplaceData (3, 3, "bar");
150 Assert.AreEqual ("foobar", comment.Data);
154 comment.Value = "foo";
155 comment.ReplaceData (4, 3, "bar");
156 Assert.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
158 catch (ArgumentOutOfRangeException) {}
162 comment.Value = "foo";
163 comment.ReplaceData (-1, 3, "bar");
164 Assert.Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
166 catch (ArgumentOutOfRangeException) {}
168 comment.Value = "foo";
169 comment.ReplaceData (0, 2, "bar");
170 Assert.AreEqual ("baro", comment.Data);
172 comment.Value = "foo";
173 comment.ReplaceData (0, 5, "bar");
174 Assert.AreEqual ("bar", comment.Data);
178 comment.Value = "foo";
179 comment.ReplaceData (1, 1, null);
180 Assert.Fail ("Expected an ArgumentNullException to be thrown.");
182 catch (ArgumentNullException) {}
186 public void Substring ()
188 comment.Value = "test string";
189 Assert.AreEqual (comment.Substring (0, 50), "test string");
193 [ExpectedException (typeof (ArgumentOutOfRangeException))]
194 public void SubstringStartOutOfRange ()
196 comment.Value = "test string";
197 comment.Substring (-5, 10);
201 [ExpectedException (typeof (ArgumentOutOfRangeException))]
202 public void SubstringCountOutOfRange ()
204 comment.Value = "test string";
205 comment.Substring (10, -5);