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
: Assertion
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");
53 AssertEquals ("foobar", comment
.Data
);
55 comment
.Value
= "foo";
56 comment
.AppendData (null);
57 AssertEquals ("foo", comment
.Data
);
61 public void DeleteData ()
63 comment
.Value
= "bar";
66 comment
.DeleteData (1, 1);
69 AssertEquals ("br", comment
.Data
);
73 comment
.Value
= "foo";
74 comment
.DeleteData(-1, 1);
75 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
77 catch (ArgumentOutOfRangeException
) {}
79 comment
.Value
= "foo";
80 comment
.DeleteData(1, 5);
81 AssertEquals("f", comment
.Data
);
83 comment
.Value
= "foo";
84 comment
.DeleteData(3, 10);
85 AssertEquals("foo", comment
.Data
);
89 public void InsertData ()
91 comment
.Value
= "foobaz";
94 comment
.InsertData (3, "bar");
97 AssertEquals ("foobarbaz", comment
.Data
);
101 comment
.Value
= "foo";
102 comment
.InsertData (-1, "bar");
103 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
105 catch (ArgumentOutOfRangeException
) {}
107 comment
.Value
= "foo";
108 comment
.InsertData (3, "bar");
109 AssertEquals ("foobar", comment
.Data
);
113 comment
.Value
= "foo";
114 comment
.InsertData (4, "bar");
115 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
117 catch (ArgumentOutOfRangeException
) {}
121 comment
.Value
= "foo";
122 comment
.InsertData (1, null);
123 Fail ("Expected an ArgumentNullException to be thrown.");
125 catch (ArgumentNullException
) {}
129 public void ReplaceData ()
133 comment
.ReplaceData (0, 3, "bar");
136 AssertEquals ("bar", comment
.Data
);
138 comment
.Value
= "foo";
139 comment
.ReplaceData (2, 3, "bar");
140 AssertEquals ("fobar", comment
.Data
);
142 comment
.Value
= "foo";
143 comment
.ReplaceData (3, 3, "bar");
144 AssertEquals ("foobar", comment
.Data
);
148 comment
.Value
= "foo";
149 comment
.ReplaceData (4, 3, "bar");
150 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
152 catch (ArgumentOutOfRangeException
) {}
156 comment
.Value
= "foo";
157 comment
.ReplaceData (-1, 3, "bar");
158 Fail ("Expected an ArgumentOutOfRangeException to be thrown.");
160 catch (ArgumentOutOfRangeException
) {}
162 comment
.Value
= "foo";
163 comment
.ReplaceData (0, 2, "bar");
164 AssertEquals ("baro", comment
.Data
);
166 comment
.Value
= "foo";
167 comment
.ReplaceData (0, 5, "bar");
168 AssertEquals ("bar", comment
.Data
);
172 comment
.Value
= "foo";
173 comment
.ReplaceData (1, 1, null);
174 Fail ("Expected an ArgumentNullException to be thrown.");
176 catch (ArgumentNullException
) {}
180 public void Substring ()
182 comment
.Value
= "test string";
183 AssertEquals ("test string", comment
.Substring (0, 50));
187 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
188 public void SubstringStartOutOfRange ()
190 comment
.Value
= "test string";
191 comment
.Substring (-5, 10);
195 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
196 public void SubstringCountOutOfRange ()
198 comment
.Value
= "test string";
199 comment
.Substring (10, -5);