// MS.NET doesn't treat as an error.
Fail ("any prefix which name starts from \"xml\" must not be allowed.");
}
- catch (ArgumentException e) {}
+ catch (ArgumentException) {}
xtw.WriteAttributeString ("", "xmlns", null, "http://abc.def");
}
xtw.WriteCData ("foo");
Fail ("WriteCData after Close Should have thrown an InvalidOperationException.");
}
- catch (InvalidOperationException e) {
+ catch (InvalidOperationException) {
// Don't rely on English message assertion.
// It is enough to check an exception occurs.
// AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
xtw.WriteComment ("foo");
Fail ("WriteComment after Close Should have thrown an InvalidOperationException.");
}
- catch (InvalidOperationException e) {
+ catch (InvalidOperationException) {
// AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
}
xtw.WriteProcessingInstruction ("foo", "bar");
Fail ("WriteProcessingInstruction after Close Should have thrown an InvalidOperationException.");
}
- catch (InvalidOperationException e) {
+ catch (InvalidOperationException) {
// AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
}
xtw.WriteStartElement ("foo", "bar", "baz");
Fail ("WriteStartElement after Close Should have thrown an InvalidOperationException.");
}
- catch (InvalidOperationException e) {
+ catch (InvalidOperationException) {
// AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
}
xtw.WriteAttributeString ("foo", "bar");
Fail ("WriteAttributeString after Close Should have thrown an InvalidOperationException.");
}
- catch (InvalidOperationException e)
+ catch (InvalidOperationException)
{
// AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
}
xtw.WriteString ("foo");
Fail ("WriteString after Close Should have thrown an InvalidOperationException.");
}
- catch (InvalidOperationException e) {
+ catch (InvalidOperationException) {
// AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
}
}
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void CommentInvalid ()
{
- xtw.WriteComment("foo-");
- xtw.WriteComment("foo-->bar");
+ try {
+ xtw.WriteComment("foo-");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+
+ try {
+ xtw.WriteComment("foo-->bar");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
}
[Test]
}
[Test]
- [ExpectedException (typeof (InvalidOperationException))]
public void DocumentStart ()
{
xtw.WriteStartDocument ();
AssertEquals ("XmlDeclaration is incorrect.", "<?xml version='1.0' encoding='utf-16'?>", StringWriterText);
- xtw.WriteStartDocument ();
+ try
+ {
+ xtw.WriteStartDocument ();
+ Fail("Should have thrown an InvalidOperationException.");
+ }
+ catch (InvalidOperationException) {
+ // Don't rely on English message assertion.
+ // It is enough to check an exception occurs.
+// AssertEquals ("Exception message is incorrect.",
+// "WriteStartDocument should be the first call.", e.Message);
+ }
+
xtw = new XmlTextWriter (sw = new StringWriter ());
xtw.QuoteChar = '\'';
xtw.WriteStartDocument (true);
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void NamespacesElementsPassingInNamespaces ()
{
xtw.Namespaces = false;
// These should throw ArgumentException because they pass in a
// namespace when Namespaces = false.
- xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
- xtw.WriteStartElement ("foo", "http://netsack.com/");
- xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
- xtw.WriteStartElement ("foo", "bar", null);
- xtw.WriteStartElement ("foo", "bar", "");
- xtw.WriteStartElement ("foo", "", "");
+ try {
+ xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
+
+ try {
+ xtw.WriteStartElement ("foo", "http://netsack.com/");
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
+
+ try {
+ xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
+
+ try {
+ xtw.WriteStartElement ("foo", "bar", null);
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
+
+ try {
+ xtw.WriteStartElement ("foo", "bar", "");
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
+
+ try {
+ xtw.WriteStartElement ("foo", "", "");
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
}
[Test]
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void NamespacesPrefixWithEmptyAndNullNamespace ()
{
- xtw.WriteStartElement ("foo", "bar", "");
- xtw.WriteStartElement ("foo", "bar", null);
+ try {
+ xtw.WriteStartElement ("foo", "bar", "");
+ Fail ("Should have thrown an ArgumentException.");
+ } catch (ArgumentException) {}
+
+ try
+ {
+ xtw.WriteStartElement ("foo", "bar", null);
+ Fail ("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) {}
}
[Test]
- [ExpectedException (typeof (InvalidOperationException))]
public void NamespacesSettingWhenWriteStateNotStart ()
{
xtw.WriteStartElement ("foo");
- xtw.Namespaces = false;
+ try
+ {
+ xtw.Namespaces = false;
+ Fail ("Expected an InvalidOperationException.");
+ }
+ catch (InvalidOperationException) {}
AssertEquals (true, xtw.Namespaces);
}
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void ProcessingInstructionInvalid ()
{
- xtw.WriteProcessingInstruction("fo?>o", "bar");
- xtw.WriteProcessingInstruction("foo", "ba?>r");
- xtw.WriteProcessingInstruction("", "bar");
- xtw.WriteProcessingInstruction(null, "bar");
+ try
+ {
+ xtw.WriteProcessingInstruction("fo?>o", "bar");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+
+ try
+ {
+ xtw.WriteProcessingInstruction("foo", "ba?>r");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+
+ try
+ {
+ xtw.WriteProcessingInstruction("", "bar");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+
+ try
+ {
+ xtw.WriteProcessingInstruction(null, "bar");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
}
[Test]
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void WriteCharEntity ()
{
xtw.WriteCharEntity ('a');
xtw.WriteCharEntity ('K');
AssertEquals ("aA1K", StringWriterText);
- xtw.WriteCharEntity ((char)0xd800);
+ try {
+ xtw.WriteCharEntity ((char)0xd800);
+ } catch (ArgumentException) {}
}
[Test]
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void WriteEndDocument ()
{
- xtw.WriteEndDocument ();
+ try {
+ xtw.WriteEndDocument ();
+ Fail ("Expected an ArgumentException.");
+ } catch (ArgumentException) {}
+
xtw.WriteStartDocument ();
- xtw.WriteEndDocument ();
+
+ try
+ {
+ xtw.WriteEndDocument ();
+ Fail ("Expected an ArgumentException.");
+ }
+ catch (ArgumentException) {}
xtw.WriteStartElement ("foo");
xtw.WriteStartAttribute ("bar", null);
}
[Test]
- [ExpectedException (typeof (InvalidOperationException))]
public void WriteEndElement ()
{
- xtw.WriteEndElement ();
- // Don't rely on English message assertion.
- // It is enough to check an exception occurs.
- // AssertEquals ("Exception message is incorrect.", "There was no XML start tag open.", e.Message);
+ try {
+ xtw.WriteEndElement ();
+ Fail ("Should have thrown an InvalidOperationException.");
+ } catch (InvalidOperationException) {
+ // Don't rely on English message assertion.
+ // It is enough to check an exception occurs.
+// AssertEquals ("Exception message is incorrect.", "There was no XML start tag open.", e.Message);
+ }
xtw.WriteStartElement ("foo");
xtw.WriteEndElement ();
}
[Test]
- [ExpectedException (typeof (InvalidOperationException))]
public void WriteString ()
{
xtw.WriteStartDocument ();
- xtw.WriteString("foo");
+ try {
+ xtw.WriteString("foo");
+ } catch (InvalidOperationException) {}
// Testing attribute values
xtw.WriteWhitespace (" ");
AssertEquals ("<foo bar='baz'> ", StringWriterText);
}
+
+ [Test]
+ public void DontOutputMultipleXmlns ()
+ {
+ XmlDocument doc = new XmlDocument();\r
+ doc.LoadXml("<a xmlns:dt=\"b\" dt:dt=\"c\"/>");\r
+ XmlDocument doc2 = new XmlDocument();\r
+ doc2.LoadXml(doc.InnerXml);
+ AssertEquals ("<a xmlns:dt=\"b\" dt:dt=\"c\" />",
+ doc2.OuterXml);
+ }
}
}