diff options
author | Gert Driesen <drieseng@users.sourceforge.net> | 2006-02-09 16:30:02 +0300 |
---|---|---|
committer | Gert Driesen <drieseng@users.sourceforge.net> | 2006-02-09 16:30:02 +0300 |
commit | fe34bc872c62ae173700620692e00cefa36d4a9b (patch) | |
tree | 132337f4177ecc7b335561e69f50377167173e89 /mcs/class | |
parent | f865900374044eb999e1ca8bfa2af559dd3def66 (diff) |
* XmlSerializationWriterTests.cs: Use Assert instead of deprecated
Assertion class. Added tests for FromEnum, WriteXsiType,
WriteTypedPrimitive and WritePotentiallyReferencingElement. Changed
accessibility of Reset and Content on XmlSerializationWriterTester
and added public Execute methods for WritePotentiallyReferencingElement
and WriteTypedPrimitive, to allow this class to be useful for tests
that have effect on the prefix for other tests.
* XmlSerializationReaderTests.cs: Added tests for ToEnum.
* System.Xml_test.dll.Sources: Added XmlSerializationReaderTests.cs.
* XmlSerializationWriter.cs: Implemented 2.0 version of FromEnum, and
CreateInvalidEnumValueException. Set eol-style to native.
* XmlCustomerFormatter.cs: Added FromEnum overload that takes name of
enum for which string value must be created. Set eol-style to native.
Modified FromEnum to behave more like MSFT's implementation:
- treat value as bit field.
- no longer return empty string if the value matches an id for which there's
no corresponding name.
- if one of the ids has value 0 and there's a match for the enum value
(with a zero length XML name) or the enum value is 0, then return the
corresponding XML for the id with value 0.
- in 2.0 profile, throw InvalidOperationException if no match is found
for (part of) the enum value.
Modifies ToEnum to match the MSFT implementation (as described in
.NET 2.0 SDK):
- Expect hashtable containing enum names as key, and corresponding
integral numbers as value.
- Do not report exception for whitespace-only value.
- Support space (MS docs are not clear about this) delimited list
of names.
- typeName is only used to construct exception message.
svn path=/trunk/mcs/; revision=56700
Diffstat (limited to 'mcs/class')
7 files changed, 1416 insertions, 110 deletions
diff --git a/mcs/class/System.XML/ChangeLog b/mcs/class/System.XML/ChangeLog index aa1fa555bdc..21d84375a0e 100644 --- a/mcs/class/System.XML/ChangeLog +++ b/mcs/class/System.XML/ChangeLog @@ -1,3 +1,7 @@ +2006-02-09 Gert Driesen <drieseng@users.sourceforge.net> + + * System.Xml_test.dll.Sources: Added XmlSerializationReaderTests.cs. + 2006-01-27 Atsushi Enomoto <atsushi@ximian.com> * System.Xml.dll.sources : added XmlIteratorNodeList.cs. diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs index dc3818bd360..40b1c70bd41 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs @@ -76,16 +76,49 @@ namespace System.Xml.Serialization { internal static string FromEnum (long value, string[] values, long[] ids) { + return FromEnum (value, values, ids, (string) null); + } + + internal static string FromEnum (long value, string[] values, long[] ids, string typeName) + { + StringBuilder sb = new StringBuilder(); int length = ids.Length; + long valueToProcess = value; + int zeroValue = -1; for (int i = 0; i < length; i ++) { - if (ids[i] == value) - if (i >= values.Length) - return String.Empty; - else - return values[i].ToString (); + if (ids[i] == 0) { + zeroValue = i; + } else { + if (valueToProcess == 0) { + break; + } + + if ((ids[i] & value) == ids[i]) { + if (sb.Length != 0) + sb.Append (' '); + sb.Append (values[i]); + valueToProcess &= ~ids[i]; + } + } } - return String.Empty; + + if (valueToProcess != 0) { +#if NET_2_0 + if (typeName != null) + throw new InvalidOperationException (string.Format (CultureInfo.CurrentCulture, + "'{0}' is not a valid value for {1}.", value, typeName)); + else + throw new InvalidOperationException (string.Format (CultureInfo.CurrentCulture, + "'{0}' is not a valid value.", value)); +#else + return value.ToString (); +#endif + } + if (sb.Length == 0 && zeroValue != -1) { + sb.Append (values[zeroValue]); + } + return sb.ToString (); } internal static string FromXmlName (string name) @@ -141,16 +174,27 @@ namespace System.Xml.Serialization { // Assuming that h contains map from value to Enumerated Name /* You can try : - return ToEnum ("Element", h, "XmlNodeType"); + return ToEnum ("One Two", h, "SomeType"); where: (1) no keys and values for h. - (2) string keys and Enum, Type, long, string value. + (2) string keys and long values. + + according to MSDN docs (for .NET 2.0) the hashtable "consists of the + identifiers as keys and the constants as integral numbers" */ - string memberName = (string) values [value]; - if (memberName == null) - throw new InvalidOperationException (String.Format ("{0} is not a valid member of type {1}", value, typeName)); + long enumValue = 0; + string[] names = value.Split (' '); + + foreach (string name in names) { + object nameValue = values[name]; + if (nameValue != null) { + enumValue |= (long) nameValue; + } else if (validate && name.Length != 0) { + throw new InvalidOperationException (String.Format ("'{0}' is not a valid member of type {1}.", name, typeName)); + } + } - return (long) Enum.Parse (Type.GetType (typeName), memberName); + return enumValue; } internal static string ToXmlName (string value) diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs index 304470a82e0..a54a7a8482c 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs @@ -925,16 +925,15 @@ namespace System.Xml.Serialization throw new NotImplementedException (); } - [MonoTODO] protected Exception CreateInvalidEnumValueException (object value, string typeName) { - throw new NotImplementedException (); + return new InvalidOperationException (string.Format(CultureInfo.CurrentCulture, + "'{0}' is not a valid value for {1}.", value, typeName)); } - [MonoTODO] protected static string FromEnum (long value, string[] values, long[] ids, string typeName) { - throw new NotImplementedException (); + return XmlCustomFormatter.FromEnum (value, values, ids, typeName); } [MonoTODO] @@ -962,7 +961,7 @@ namespace System.Xml.Serialization set { throw new NotImplementedException(); } } #endif - + #endregion class WriteCallbackInfo diff --git a/mcs/class/System.XML/System.Xml_test.dll.sources b/mcs/class/System.XML/System.Xml_test.dll.sources index 6c13ea47063..a4a9de8a3fd 100644 --- a/mcs/class/System.XML/System.Xml_test.dll.sources +++ b/mcs/class/System.XML/System.Xml_test.dll.sources @@ -74,6 +74,7 @@ System.Xml.Serialization/XmlReflectionImporterTests.cs System.Xml.Serialization/XmlRootAttributeTests.cs System.Xml.Serialization/XmlSchemaExporterTests.cs System.Xml.Serialization/XmlSchemaImporterTests.cs +System.Xml.Serialization/XmlSerializationReaderTests.cs System.Xml.Serialization/XmlSerializationWriterTests.cs System.Xml.Serialization/XmlTextAttributeTests.cs System.Xml.Serialization/XmlTypeAttributeTests.cs diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog b/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog index deda77e54f8..aecb9295dcc 100644 --- a/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog @@ -1,3 +1,14 @@ +2006-02-09 Gert Driesen <drieseng@users.sourceforge.net> + + * XmlSerializationWriterTests.cs: Use Assert instead of deprecated + Assertion class. Added tests for FromEnum, WriteXsiType, + WriteTypedPrimitive and WritePotentiallyReferencingElement. Changed + accessibility of Reset and Content on XmlSerializationWriterTester + and added public Execute methods for WritePotentiallyReferencingElement + and WriteTypedPrimitive, to allow this class to be useful for tests + that have effect on the prefix for other tests. + * XmlSerializationReaderTests.cs: Added tests for ToEnum. + 2006-02-08 Gert Driesen <drieseng@users.sourceforge.net> * XmlTypeAttributeTests.cs: Set eol-style to native. diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationReaderTests.cs b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationReaderTests.cs new file mode 100644 index 00000000000..cdd34e14804 --- /dev/null +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationReaderTests.cs @@ -0,0 +1,134 @@ +// +// MonoTests.System.Xml.Serialization.XmlSerializationReaderTests +// +// Author: +// Gert Driesen (drieseng@users.sourceforge.net) +// +// (C) 2006 Novell +// + +using System; +using System.Collections; +using System.Xml.Serialization; + +using NUnit.Framework; + +using MonoTests.System.Xml.TestClasses; + +namespace MonoTests.System.XmlSerialization +{ + [TestFixture] + public class XmlSerializationReaderTests : XmlSerializarionReaderTester + { + [Test] + public void TestToEnum () + { + Hashtable values = new Hashtable (); + values.Add ("One", 1L); + values.Add ("Two", 2L); + values.Add ("Four", 4L); + + Assert.AreEqual (1, ToEnum ("One", values, "Some.Type.Name"), "#A1"); + Assert.AreEqual (2, ToEnum (" Two ", values, "Some.Type.Name"), "#A2"); + Assert.AreEqual (4, ToEnum ("Four", values, "Some.Type.Name"), "#A3"); + Assert.AreEqual (5, ToEnum ("One Four", values, "Some.Type.Name"), "#A4"); + Assert.AreEqual (7, ToEnum ("One Two Four", values, "Some.Type.Name"), "#A5"); + Assert.AreEqual (0, ToEnum ("", values, "Some.Type.Name"), "#A6"); + Assert.AreEqual (0, ToEnum (" ", values, "Some.Type.Name"), "#A7"); + Assert.AreEqual (2, ToEnum ("Two Two", values, "Some.Type.Name"), "#A8"); + + values.Add ("", 24L); + Assert.AreEqual (24, ToEnum ("", values, "Some.Type.Name"), "#B1"); + Assert.AreEqual (24, ToEnum (" ", values, "Some.Type.Name"), "#B2"); + } + + [Test] + public void TestToEnum_InvalidValue () + { + try { + ToEnum ("SomeValue", new Hashtable (), "Some.Type.Name"); + Assert.Fail ("#A1"); + } catch (InvalidOperationException ex) { + Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2"); + Assert.IsNotNull (ex.Message, "#A3"); + Assert.IsTrue (ex.Message.IndexOf ("'SomeValue'") != -1, "#A4"); + Assert.IsTrue (ex.Message.IndexOf ("Some.Type.Name") != -1, "#A5"); + Assert.IsNull (ex.InnerException, "#A6"); + } + + Hashtable values = new Hashtable (); + values.Add ("One", 1L); + values.Add ("Two", 2L); + values.Add ("Four", 4L); + + try { + ToEnum ("one", values, "Some.Type.Name"); + Assert.Fail ("#B1"); + } catch (InvalidOperationException ex) { + Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2"); + Assert.IsNotNull (ex.Message, "#B3"); + Assert.IsTrue (ex.Message.IndexOf ("'one'") != -1, "#B4"); + Assert.IsTrue (ex.Message.IndexOf ("Some.Type.Name") != -1, "#B5"); + Assert.IsNull (ex.InnerException, "#B6"); + } + + values.Clear (); + values.Add ("One", FlagEnum.e1); + + try { + ToEnum ("One", values, "Some.Type.Name"); + Assert.Fail ("#C1"); + } catch (InvalidCastException ex) { + } + + values.Clear (); + values.Add ("One", 1); + + try { + ToEnum ("One", values, "Some.Type.Name"); + Assert.Fail ("#D1"); + } catch (InvalidCastException ex) { + } + + values.Clear (); + values.Add ("One", null); + + try { + ToEnum ("One", values, "Some.Type.Name"); + Assert.Fail ("#E1"); + } catch (InvalidOperationException ex) { + Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2"); + Assert.IsNotNull (ex.Message, "#E3"); + Assert.IsTrue (ex.Message.IndexOf ("'One'") != -1, "#E4"); + Assert.IsTrue (ex.Message.IndexOf ("Some.Type.Name") != -1, "#E5"); + Assert.IsNull (ex.InnerException, "#E6"); + } + } + + [Test] + [ExpectedException (typeof (NullReferenceException))] + public void TestToEnum_Null_Value () + { + ToEnum ((string) null, new Hashtable (), "DoesNotMatter"); + } + + [Test] + [ExpectedException (typeof (NullReferenceException))] + public void TestToEnum_Null_Values () + { + ToEnum ("", (Hashtable) null, "DoesNotMatter"); + } + } + + public class XmlSerializarionReaderTester : XmlSerializationReader + { + // appease the compiler + protected override void InitCallbacks () + { + } + + protected override void InitIDs () + { + } + } +} diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationWriterTests.cs b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationWriterTests.cs index cf3a8534e4c..13679d50658 100644 --- a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationWriterTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializationWriterTests.cs @@ -11,12 +11,15 @@ //
using System;
+using System.Globalization;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;
+using MonoTests.System.Xml.TestClasses;
+
namespace MonoTests.System.XmlSerialization
{
// base, common implementation of XmlSerializationWriter test harness.
@@ -40,7 +43,7 @@ namespace MonoTests.System.XmlSerialization XmlTextWriter writer;
[SetUp]
- protected void Reset()
+ public void Reset()
{
sw = new StringWriter ();
writer = new XmlTextWriter (sw);
@@ -49,15 +52,24 @@ namespace MonoTests.System.XmlSerialization Writer = writer;
}
- protected string Content
+ public string Content
{
get
{
string val = sw.GetStringBuilder().ToString();
-// Console.WriteLine(val);
return val;
}
}
+
+ public void ExecuteWritePotentiallyReferencingElement (string name, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
+ {
+ WritePotentiallyReferencingElement (name, ns, o, ambientType, suppressReference, isNullable);
+ }
+
+ public void ExecuteWriteTypedPrimitive (string name, string ns, object o, bool xsiType)
+ {
+ WriteTypedPrimitive (name, ns, o, xsiType);
+ }
}
// this class tests the methods of the XmlSerializationWriter that
@@ -65,7 +77,12 @@ namespace MonoTests.System.XmlSerialization [TestFixture]
public class XmlSerializationWriterSimpleTests : XmlSerializarionWriterTester
{
+ const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
+ const string XmlSchemaInstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
+ const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
+ const string WsdlTypesNamespace = "http://microsoft.com/wsdl/types/";
const string ANamespace = "some:urn";
+ const string AnotherNamespace = "another:urn";
// These TestFrom* methods indirectly test the functionality of XmlCustomFormatter
@@ -77,7 +94,7 @@ namespace MonoTests.System.XmlSerialization // returns a byte array.
//
//string val = this.FromByteArrayBase64(new byte [] {143, 144, 1, 0});
- //Assertion.AssertEquals(FromByteArrayBase64(null), "");
+ //Assert.AreEqual (FromByteArrayBase64(null), "");
//val = FromByteArrayBase64(null);
//try/catch or AssertEruals?
@@ -87,50 +104,143 @@ namespace MonoTests.System.XmlSerialization public void TestFromByteArrayHex()
{
byte [] vals = {143, 144, 1, 0};
- Assertion.AssertEquals("8F900100", FromByteArrayHex(vals));
- Assertion.AssertEquals(null, FromByteArrayHex(null));
+ Assert.AreEqual ("8F900100", FromByteArrayHex(vals));
+ Assert.IsNull (FromByteArrayHex (null));
}
[Test]
public void TestFromChar()
{
- Assertion.AssertEquals("97", FromChar('a'));
- Assertion.AssertEquals("0", FromChar('\0'));
- Assertion.AssertEquals("10", FromChar('\n'));
- Assertion.AssertEquals("65281", FromChar('\uFF01'));
+ Assert.AreEqual ("97", FromChar ('a'));
+ Assert.AreEqual ("0", FromChar ('\0'));
+ Assert.AreEqual ("10", FromChar ('\n'));
+ Assert.AreEqual ("65281", FromChar ('\uFF01'));
}
[Test]
public void TestFromDate()
{
DateTime d = new DateTime();
- Assertion.AssertEquals("0001-01-01", FromDate(d));
+ Assert.AreEqual ("0001-01-01", FromDate (d));
}
[Test]
public void TestFromDateTime()
{
DateTime d = new DateTime();
- Assertion.AssertEquals("0001-01-01T00:00:00.0000000", FromDateTime(d).Substring (0, 27));
+ Assert.AreEqual ("0001-01-01T00:00:00.0000000", FromDateTime (d).Substring (0, 27));
}
- [Test]
+ [Test] // bug #77500
public void TestFromEnum()
{
long[] ids = {1, 2, 3, 4};
string[] values = {"one", "two", "three"};
-
- Assertion.AssertEquals("one", FromEnum(1, values, ids));
- Assertion.AssertEquals("", FromEnum(0, values, ids));
- try
- {
+ Assert.AreEqual ("one", FromEnum (1, values, ids), "#1");
+ Assert.AreEqual (string.Empty, FromEnum (0, values, ids), "#2");
+ Assert.AreEqual ("one two", FromEnum (3, values, ids), "#3");
+
+ try {
string dummy = FromEnum(4, values, ids);
- Assertion.Fail("This should fail with an array-out-of-bunds error");
+ Assert.Fail("#4");
+ } catch (IndexOutOfRangeException) {
}
- catch (Exception)
- {
+
+ string[] correctValues = {"one", "two", "three", "four"};
+ Assert.AreEqual ("four", FromEnum (4, correctValues, ids), "#5");
+ Assert.AreEqual ("one four", FromEnum (5, correctValues, ids), "#6");
+ Assert.AreEqual ("two four", FromEnum (6, correctValues, ids), "#7");
+ Assert.AreEqual ("one two three four", FromEnum (7, correctValues, ids), "#8");
+
+ string[] flagValues = {"one", "two", "four", "eight"};
+ long[] flagIDs = {1, 2, 4, 8};
+ Assert.AreEqual (string.Empty, FromEnum (0, flagValues, flagIDs), "#9");
+ Assert.AreEqual ("two", FromEnum (2, flagValues, flagIDs), "#10");
+ Assert.AreEqual ("four", FromEnum (4, flagValues, flagIDs), "#1");
+ Assert.AreEqual ("one four", FromEnum (5, flagValues, flagIDs), "#12");
+ Assert.AreEqual ("two four", FromEnum (6, flagValues, flagIDs), "#13");
+ Assert.AreEqual ("one two four", FromEnum (7, flagValues, flagIDs), "#14");
+ Assert.AreEqual ("eight", FromEnum (8, flagValues, flagIDs), "#15");
+ Assert.AreEqual ("one four eight", FromEnum (13, flagValues, flagIDs), "#16");
+
+ string[] unorderedValues = {"one", "four", "two", "zero"};
+ long[] unorderedIDs = {1, 4, 2, 0};
+
+ Assert.AreEqual (string.Empty, FromEnum (0, unorderedValues, unorderedIDs), "#17");
+ Assert.AreEqual ("two", FromEnum (2, unorderedValues, unorderedIDs), "#18");
+ Assert.AreEqual ("four", FromEnum (4, unorderedValues, unorderedIDs), "#19");
+ Assert.AreEqual ("one four", FromEnum (5, unorderedValues, unorderedIDs), "#20");
+ Assert.AreEqual ("four two", FromEnum (6, unorderedValues, unorderedIDs), "#21");
+ Assert.AreEqual ("one four two", FromEnum (7, unorderedValues, unorderedIDs), "#22");
+
+ string[] zeroValues = {"zero", "ten"};
+ long[] zeroIDs = {0, 10};
+
+ Assert.AreEqual ("zero", FromEnum (0, zeroValues, zeroIDs), "#9");
+ Assert.AreEqual ("ten", FromEnum (10, zeroValues, zeroIDs), "#9");
+
+ string[] reverseZeroValues = {"", "zero"};
+ long[] reverseZeroIDs = {4, 0};
+ Assert.AreEqual (string.Empty, FromEnum (0, reverseZeroValues, reverseZeroIDs), "#9");
+ Assert.AreEqual ("zero", FromEnum (4, reverseZeroValues, reverseZeroIDs), "#9");
+
+ string[] emptyValues = { "zero" };
+ long[] emptyIDs = {0};
+ Assert.AreEqual ("zero", FromEnum (0, emptyValues, emptyIDs), "#9");
+ }
+
+ [Test]
+ public void TestFromEnum_InvalidValue ()
+ {
+ long[] ids = {1, 2, 3, 4};
+ string[] values = {"one", "two", "three", "four"};
+
+#if NET_2_0
+ try {
+ FromEnum (8, values, ids);
+ Assert.Fail ("#A1");
+ } catch (InvalidOperationException ex) {
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+ Assert.IsNotNull (ex.Message, "#A3");
+ Assert.IsTrue (ex.Message.IndexOf ("'8'") != -1, "#A4");
+ Assert.IsNull (ex.InnerException, "#A5");
}
+#else
+ Assert.AreEqual ("8", FromEnum (8, values, ids), "#A6");
+#endif
+
+#if NET_2_0
+ try {
+ FromEnum (8, values, ids, "Some.Type.Name");
+ Assert.Fail ("#B1");
+ } catch (InvalidOperationException ex) {
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+ Assert.IsNotNull (ex.Message, "#B3");
+ Assert.IsTrue (ex.Message.IndexOf ("'8'") != -1, "#B4");
+ Assert.IsTrue (ex.Message.IndexOf ("Some.Type.Name") != -1, "#B5");
+ Assert.IsNull (ex.InnerException, "#B6");
+ }
+#endif
+ }
+
+ [Test]
+ [ExpectedException (typeof (NullReferenceException))]
+ public void TestFromEnum_Null_Values ()
+ {
+ long[] ids = { 1, 2, 3, 4 };
+ string[] values = { "one", "two", "three", "four" };
+
+ FromEnum (1, (string[]) null, ids);
+ }
+
+ [Test]
+ [ExpectedException (typeof (NullReferenceException))]
+ public void TestFromEnum_Null_IDs ()
+ {
+ string[] values = { "one", "two", "three", "four" };
+
+ FromEnum (1, values, (long[]) null);
}
[Test]
@@ -138,43 +248,43 @@ namespace MonoTests.System.XmlSerialization {
DateTime d = new DateTime();
// Don't include time zone.
- Assertion.AssertEquals("00:00:00.0000000", FromTime(d).Substring (0, 16));
+ Assert.AreEqual ("00:00:00.0000000", FromTime (d).Substring (0, 16));
}
[Test]
public void TestFromXmlName()
{
- Assertion.AssertEquals("Hello", FromXmlName("Hello"));
- Assertion.AssertEquals("go_x0020_dogs_x0020_go", FromXmlName("go dogs go"));
- Assertion.AssertEquals("what_x0027_s_x0020_up", FromXmlName("what's up"));
- Assertion.AssertEquals("_x0031_23go", FromXmlName("123go"));
- Assertion.AssertEquals("Hello_x0020_what_x0027_s.up", FromXmlName("Hello what's.up"));
+ Assert.AreEqual ("Hello", FromXmlName ("Hello"));
+ Assert.AreEqual ("go_x0020_dogs_x0020_go", FromXmlName ("go dogs go"));
+ Assert.AreEqual ("what_x0027_s_x0020_up", FromXmlName ("what's up"));
+ Assert.AreEqual ("_x0031_23go", FromXmlName ("123go"));
+ Assert.AreEqual ("Hello_x0020_what_x0027_s.up", FromXmlName ("Hello what's.up"));
}
[Test]
public void TestFromXmlNCName()
{
- Assertion.AssertEquals("Hello", FromXmlNCName("Hello"));
- Assertion.AssertEquals("go_x0020_dogs_x0020_go", FromXmlNCName("go dogs go"));
- Assertion.AssertEquals("what_x0027_s_x0020_up", FromXmlNCName("what's up"));
- Assertion.AssertEquals("_x0031_23go", FromXmlNCName("123go"));
- Assertion.AssertEquals("Hello_x0020_what_x0027_s.up", FromXmlNCName("Hello what's.up"));
+ Assert.AreEqual ("Hello", FromXmlNCName ("Hello"));
+ Assert.AreEqual ("go_x0020_dogs_x0020_go", FromXmlNCName ("go dogs go"));
+ Assert.AreEqual ("what_x0027_s_x0020_up", FromXmlNCName ("what's up"));
+ Assert.AreEqual ("_x0031_23go", FromXmlNCName ("123go"));
+ Assert.AreEqual ("Hello_x0020_what_x0027_s.up", FromXmlNCName ("Hello what's.up"));
}
[Test]
public void TestFromXmlNmToken()
{
- Assertion.AssertEquals("Hello", FromXmlNmToken("Hello"));
- Assertion.AssertEquals("go_x0020_dogs_x0020_go", FromXmlNmToken("go dogs go"));
- Assertion.AssertEquals("what_x0027_s_x0020_up", FromXmlNmToken("what's up"));
- Assertion.AssertEquals("123go", FromXmlNmToken("123go"));
- Assertion.AssertEquals("Hello_x0020_what_x0027_s.up", FromXmlNmToken("Hello what's.up"));
+ Assert.AreEqual ("Hello", FromXmlNmToken ("Hello"));
+ Assert.AreEqual ("go_x0020_dogs_x0020_go", FromXmlNmToken ("go dogs go"));
+ Assert.AreEqual ("what_x0027_s_x0020_up", FromXmlNmToken ("what's up"));
+ Assert.AreEqual ("123go", FromXmlNmToken ("123go"));
+ Assert.AreEqual ("Hello_x0020_what_x0027_s.up", FromXmlNmToken ("Hello what's.up"));
}
[Test]
public void TestFromXmlNmTokens()
{
- Assertion.AssertEquals("Hello go dogs_go 123go what_x0027_s.up", FromXmlNmTokens("Hello go dogs_go 123go what's.up"));
+ Assert.AreEqual ("Hello go dogs_go 123go what_x0027_s.up", FromXmlNmTokens ("Hello go dogs_go 123go what's.up"));
}
[Test]
@@ -183,46 +293,44 @@ namespace MonoTests.System.XmlSerialization WriteStartElement("x");
WriteAttribute("a", "b");
WriteEndElement();
- Assertion.AssertEquals("<x a='b' />", Content);
+ Assert.AreEqual ("<x a='b' />", Content);
Reset();
WriteStartElement("x");
WriteAttribute("a", new byte[] {1, 2, 3});
WriteEndElement();
- Assertion.AssertEquals("<x a='AQID' />", Content);
+ Assert.AreEqual ("<x a='AQID' />", Content);
Reset();
WriteStartElement("x");
WriteAttribute("a", "<b");
WriteEndElement();
- Assertion.AssertEquals("<x a='<b' />", Content);
+ Assert.AreEqual ("<x a='<b' />", Content);
Reset();
WriteStartElement("x");
string typedPlaceholder = null;
WriteAttribute("a", typedPlaceholder);
WriteEndElement();
- Assertion.AssertEquals("<x />", Content);
+ Assert.AreEqual ("<x />", Content);
Reset();
WriteStartElement("x");
WriteAttribute("a", "\"");
WriteEndElement();
- Assertion.AssertEquals("<x a='\"' />", Content);
+ Assert.AreEqual ("<x a='\"' />", Content);
Reset();
WriteStartElement("x");
WriteAttribute("a", "b\nc");
WriteEndElement();
- Assertion.AssertEquals("<x a='b
c' />", Content);
+ Assert.AreEqual ("<x a='b
c' />", Content);
Reset();
WriteStartElement("x");
WriteAttribute("a", ANamespace, "b");
WriteEndElement();
- Assertion.AssertEquals("<x d1p1:a='b' xmlns:d1p1='some:urn' />", Content);
-
-
+ Assert.AreEqual ("<x d1p1:a='b' xmlns:d1p1='some:urn' />", Content);
}
[Test]
@@ -243,11 +351,11 @@ namespace MonoTests.System.XmlSerialization public void TestWriteElementString()
{
WriteElementString("x", "a");
- Assertion.AssertEquals("<x>a</x>", Content);
+ Assert.AreEqual ("<x>a</x>", Content);
Reset();
WriteElementString("x", "<a");
- Assertion.AssertEquals("<x><a</x>", Content);
+ Assert.AreEqual ("<x><a</x>", Content);
}
[Test]
@@ -255,27 +363,27 @@ namespace MonoTests.System.XmlSerialization {
byte [] placeHolderArray = null;
WriteElementStringRaw("x", placeHolderArray);
- Assertion.AssertEquals("", Content);
+ Assert.AreEqual ("", Content);
Reset();
WriteElementStringRaw("x", new byte[] {0, 2, 4});
- Assertion.AssertEquals("<x>AAIE</x>", Content);
+ Assert.AreEqual ("<x>AAIE</x>", Content);
Reset();
WriteElementStringRaw("x", new byte[] {});
- Assertion.AssertEquals("<x />", Content);
+ Assert.AreEqual ("<x />", Content);
// Note to reader, the output is not valid xml
Reset();
WriteElementStringRaw("x", "a > 13 && a < 19");
- Assertion.AssertEquals("<x>a > 13 && a < 19</x>", Content);
+ Assert.AreEqual ("<x>a > 13 && a < 19</x>", Content);
}
[Test]
public void TestWriteEmptyTag()
{
WriteEmptyTag("x");
- Assertion.AssertEquals("<x />", Content);
+ Assert.AreEqual ("<x />", Content);
}
[Test]
@@ -286,83 +394,127 @@ namespace MonoTests.System.XmlSerialization WriteStartElement("x");
WriteNamespaceDeclarations(ns);
WriteEndElement();
- Assertion.AssertEquals("<x />", Content);
+ Assert.AreEqual ("<x />", Content);
Reset();
ns.Add("mypref", ANamespace);
WriteStartElement("x");
WriteNamespaceDeclarations(ns);
WriteEndElement();
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x xmlns:mypref='some:urn' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (XmlSerializerTests.Infoset("<x xmlns:mypref='some:urn' />"), XmlSerializerTests.Infoset(Content));
Reset();
ns.Add("ns2", "another:urn");
WriteStartElement("x");
WriteNamespaceDeclarations(ns);
WriteEndElement();
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x xmlns:ns2='another:urn' xmlns:mypref='some:urn' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (XmlSerializerTests.Infoset("<x xmlns:ns2='another:urn' xmlns:mypref='some:urn' />"), XmlSerializerTests.Infoset(Content));
Reset();
ns.Add("ns3", "ya:urn");
WriteStartElement("x");
WriteNamespaceDeclarations(ns);
WriteEndElement();
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x xmlns:ns3='ya:urn' xmlns:ns2='another:urn' xmlns:mypref='some:urn' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (XmlSerializerTests.Infoset("<x xmlns:ns3='ya:urn' xmlns:ns2='another:urn' xmlns:mypref='some:urn' />"), XmlSerializerTests.Infoset(Content));
}
[Test]
public void TestWriteNullableStringLiteral()
{
WriteNullableStringLiteral("x", null, null);
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x d1p1:nil='true' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (XmlSerializerTests.Infoset("<x d1p1:nil='true' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
Reset();
WriteNullableStringLiteral("x", null, "");
- Assertion.AssertEquals("<x />", Content);
+ Assert.AreEqual ("<x />", Content);
Reset();
WriteNullableStringLiteral("x", null, "a<b\'c");
- Assertion.AssertEquals("<x>a<b\'c</x>", Content);
+ Assert.AreEqual ("<x>a<b\'c</x>", Content);
Reset();
WriteNullableStringLiteral("x", ANamespace, "b");
- Assertion.AssertEquals("<x xmlns='some:urn'>b</x>", Content);
+ Assert.AreEqual ("<x xmlns='some:urn'>b</x>", Content);
}
[Test]
public void TestWriteNullableStringLiteralRaw()
{
WriteNullableStringLiteralRaw("x", null, new byte[] {1, 2, 244});
- Assertion.AssertEquals("<x>AQL0</x>", Content);
+ Assert.AreEqual ("<x>AQL0</x>", Content);
}
[Test]
public void TestWriteNullTagEncoded()
{
WriteNullTagEncoded("x");
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x d1p1:nil='true' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (XmlSerializerTests.Infoset("<x d1p1:nil='true' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
}
[Test]
public void TestWriteNullTagLiteral()
{
WriteNullTagLiteral("x");
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x d1p1:nil='true' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (XmlSerializerTests.Infoset("<x d1p1:nil='true' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestWritePotentiallyReferencingElement ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWritePotentiallyReferencingElement ("x", ANamespace, EnumDefaultValue.e1, typeof (EnumDefaultValue), true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>1</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWritePotentiallyReferencingElement ("x", ANamespace, (int) 1, typeof (EnumDefaultValue), true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:int' xmlns:d1p1='{1}' xmlns='{2}'>1</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, ANamespace),
+ xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWritePotentiallyReferencingElement ("x", ANamespace, "something", typeof (string), true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>something</x>", ANamespace), xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWritePotentiallyReferencingElement ("x", ANamespace, "something", null, true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:string' xmlns:d1p1='{1}' xmlns='{2}'>something</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, ANamespace),
+ xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWritePotentiallyReferencingElement ("x", ANamespace, new string[] { "A", "B" }, typeof (string[]), true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<q3:Array id='id1' xmlns:q4='{0}' q3:arrayType='q4:string[2]' xmlns:q3='{1}'>" +
+ "<Item>A</Item>" +
+ "<Item>B</Item>" +
+ "</q3:Array>", XmlSchemaNamespace, SoapEncodingNamespace), xsw.Content, "#5");
}
[Test]
public void TestWriteSerializable()
{
// FIXME
- //Assertion.AssertEquals(, "");
+ //Assert.AreEqual (, "");
}
+ [Test]
public void TestWriteStartDocument()
{
- Assertion.AssertEquals("", Content);
+ Assert.AreEqual ("", Content);
WriteStartDocument();
- Assertion.AssertEquals("<?xml version='1.0' encoding='utf-16'?>", Content);
+ Assert.AreEqual ("<?xml version='1.0' encoding='utf-16'?>", Content);
}
[Test]
@@ -370,66 +522,881 @@ namespace MonoTests.System.XmlSerialization {
WriteStartElement("x");
WriteEndElement();
- Assertion.AssertEquals("<x />", Content);
+ Assert.AreEqual ("<x />", Content);
Reset();
WriteStartElement("x");
WriteValue("a");
WriteEndElement();
- Assertion.AssertEquals("<x>a</x>", Content);
+ Assert.AreEqual ("<x>a</x>", Content);
Reset();
WriteStartElement("x");
WriteStartElement("y", "z");
WriteEndElement();
WriteEndElement();
- Assertion.AssertEquals("<x><y xmlns='z' /></x>", Content);
+ Assert.AreEqual ("<x><y xmlns='z' /></x>", Content);
Reset();
WriteStartElement("x");
WriteStartElement("y", "z", true);
WriteEndElement();
WriteEndElement();
- Assertion.AssertEquals("<x><q1:y xmlns:q1='z' /></x>", Content);
+ Assert.AreEqual ("<x><q1:y xmlns:q1='z' /></x>", Content);
}
-
- public void TestWriteTypedPrimitive()
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_Base64Binary ()
{
- // as long as WriteTypePrimitive's last argument is false, this is OK here.
- WriteTypedPrimitive("x", ANamespace, "hello", false);
- Assertion.AssertEquals("<x xmlns='some:urn'>hello</x>", Content);
+ byte[] byteArray = new byte[] { 255, 20, 10, 5, 0, 7 };
+ string expected = "/xQKBQAH";
- Reset();
- WriteTypedPrimitive("x", ANamespace, 10, false);
- Assertion.AssertEquals("<x xmlns='some:urn'>10</x>", Content);
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
- try
- {
- WriteTypedPrimitive("x", ANamespace, null, false);
- Assertion.Fail("Should not be able to write a null primitive");
- }
- catch (Exception)
- {
- }
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", ANamespace, expected),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x>{0}</x>", expected), xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x>{0}</x>", expected), xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", XmlSchemaNamespace, expected),
+ xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", XmlSchemaInstanceNamespace, expected),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>{1}</>", ANamespace, expected), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, byteArray, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<base64Binary xmlns='{0}'>{1}</base64Binary>",
+ XmlSchemaNamespace, expected), xsw.Content, "#7");
+ }
+
+ [Test]
+ public void TestWriteTypedPrimitive_Base64Binary_XsiType ()
+ {
+ byte[] byteArray = new byte[] { 255, 20, 10, 5, 0, 7 };
+ string expected = "/xQKBQAH";
+
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, byteArray, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:base64Binary' xmlns:d1p1='{1}'>{2}</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, expected),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, byteArray, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:base64Binary' xmlns:d1p1='{1}'>{2}</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, expected),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_Boolean ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>true</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, false, false);
+ Assert.AreEqual ("<x>false</x>", xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, true, false);
+ Assert.AreEqual ("<x>true</x>", xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, false, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>false</x>", XmlSchemaNamespace), xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>true</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, false, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>false</>", ANamespace), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, true, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<boolean xmlns='{0}'>true</boolean>", XmlSchemaNamespace),
+ xsw.Content, "#7");
+ }
+
+ [Test]
+ public void TestWriteTypedPrimitive_Boolean_XsiType ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, true, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:boolean' xmlns:d1p1='{1}'>true</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, false, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:boolean' xmlns:d1p1='{1}'>false</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_Char ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, 'c', false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>99</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, 'a', false);
+ Assert.AreEqual ("<x>97</x>", xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, 'b', false);
+ Assert.AreEqual ("<x>98</x>", xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, 'd', false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>100</x>", XmlSchemaNamespace), xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, 'e', false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>101</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, ' ', false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>32</>", ANamespace), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, '0', false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<char xmlns='{0}'>48</char>", WsdlTypesNamespace),
+ xsw.Content, "#7");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // namespace should be wsdl types ns
+ public void TestWriteTypedPrimitive_Char_XsiType ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, 'c', true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:char' xmlns:d1p1='{1}'>99</x>",
+ WsdlTypesNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, 'a', true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:char' xmlns:d1p1='{1}'>97</x>",
+ WsdlTypesNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_DateTime ()
+ {
+ DateTime dateTime = new DateTime (1973, 08, 13);
+
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", ANamespace, FromDateTime (dateTime)),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x>{0}</x>", FromDateTime (dateTime)), xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x>{0}</x>", FromDateTime (dateTime)), xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", XmlSchemaNamespace,
+ FromDateTime (dateTime)), xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", XmlSchemaInstanceNamespace,
+ FromDateTime (dateTime)), xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>{1}</>", ANamespace, FromDateTime (dateTime)),
+ xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, dateTime, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<dateTime xmlns='{0}'>{1}</dateTime>", XmlSchemaNamespace,
+ FromDateTime (dateTime)), xsw.Content, "#7");
+ }
+
+ [Test]
+ public void TestWriteTypedPrimitive_DateTime_XsiType ()
+ {
+ DateTime dateTime = new DateTime (1973, 08, 13);
+
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, dateTime, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:dateTime' xmlns:d1p1='{1}'>{2}</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace,
+ FromDateTime (dateTime)), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, dateTime, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:dateTime' xmlns:d1p1='{1}'>{2}</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace,
+ FromDateTime (dateTime)), xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // enum name is output instead of integral value
+ public void TestWriteTypedPrimitive_Enum ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, EnumDefaultValue.e1, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>1</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, EnumDefaultValue.e2, false);
+ Assert.AreEqual ("<x>2</x>", xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, EnumDefaultValue.e3, false);
+ Assert.AreEqual ("<x>3</x>", xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, EnumDefaultValue.e1, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>1</x>", XmlSchemaNamespace), xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, EnumDefaultValue.e2, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>2</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, EnumDefaultValue.e3, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>3</>", ANamespace), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, EnumDefaultValue.e2, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<int xmlns='{0}'>2</int>", XmlSchemaNamespace),
+ xsw.Content, "#7");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // InvalidOperationException is thrown
+ public void TestWriteTypedPrimitive_Enum_XsiType ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, EnumDefaultValue.e1, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:int' xmlns:d1p1='{1}'>1</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, EnumDefaultValue.e2, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:int' xmlns:d1p1='{1}'>2</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_Guid ()
+ {
+ Guid guid = new Guid ("CA761232-ED42-11CE-BACD-00AA0057B223");
+ string expectedGuid = "ca761232-ed42-11ce-bacd-00aa0057b223";
+
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", ANamespace, expectedGuid),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x>{0}</x>", expectedGuid), xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x>{0}</x>", expectedGuid), xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", XmlSchemaNamespace, expectedGuid),
+ xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>{1}</x>", XmlSchemaInstanceNamespace, expectedGuid),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>{1}</>", ANamespace, expectedGuid),
+ xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, guid, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<guid xmlns='{0}'>{1}</guid>", WsdlTypesNamespace,
+ expectedGuid), xsw.Content, "#7");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // namespace should be wsdl types ns
+ public void TestWriteTypedPrimitive_Guid_XsiType ()
+ {
+ Guid guid = new Guid ("CA761232-ED42-11CE-BACD-00AA0057B223");
+ string expectedGuid = "ca761232-ed42-11ce-bacd-00aa0057b223";
+
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, guid, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:guid' xmlns:d1p1='{1}'>{2}</x>",
+ WsdlTypesNamespace, XmlSchemaInstanceNamespace, expectedGuid),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, guid, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:guid' xmlns:d1p1='{1}'>{2}</x>",
+ WsdlTypesNamespace, XmlSchemaInstanceNamespace, expectedGuid),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_Int ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, 76665, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>76665</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, -5656, false);
+ Assert.AreEqual ("<x>-5656</x>", xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, 0, false);
+ Assert.AreEqual ("<x>0</x>", xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, 534, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>534</x>", XmlSchemaNamespace), xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, -6756, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>-6756</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, 434, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>434</>", ANamespace), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, 434, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<int xmlns='{0}'>434</int>", XmlSchemaNamespace),
+ xsw.Content, "#7");
+ }
+
+ [Test]
+ public void TestWriteTypedPrimitive_Int_XsiType ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, -6756, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:int' xmlns:d1p1='{1}'>-6756</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, 434, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:int' xmlns:d1p1='{1}'>434</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #8 fails
+ public void TestWriteTypedPrimitive_String ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, "hello", false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>hello</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, "hello", false);
+ Assert.AreEqual ("<x>hello</x>", xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, "hello", false);
+ Assert.AreEqual ("<x>hello</x>", xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, "hello", false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>hello</x>", XmlSchemaNamespace),
+ xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, "hello", false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>hello</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, string.Empty, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}' />", ANamespace), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, "<\"te'st\">", false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'><\"te'st\"></>", ANamespace),
+ xsw.Content, "#7");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, "hello", false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<string xmlns='{0}'>hello</string>", XmlSchemaNamespace),
+ xsw.Content, "#8");
+ }
+
+ [Test]
+ public void TestWriteTypedPrimitive_String_XsiType ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, "hello", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:string' xmlns:d1p1='{1}'>hello</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, "hello", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:string' xmlns:d1p1='{1}'>hello</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#2");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // order of namespace declaration differs from that of MSFT
+ public void TestWriteTypedPrimitive_String_XsiType_Namespace ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, "hello", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:string' xmlns:d1p1='{1}' xmlns='{2}'>hello</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, ANamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, "hello", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='string' xmlns:d1p1='{0}' xmlns='{1}'>hello</x>",
+ XmlSchemaInstanceNamespace, XmlSchemaNamespace),
+ xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, "hello", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:string' xmlns:d1p1='{1}' xmlns='{1}'>hello</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace), xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, string.Empty, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q3='{0}' d1p1:type='q3:string' xmlns:d1p1='{1}' xmlns='{2}' />",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, ANamespace),
+ xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, "<\"te'st\">", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns:q4='{0}' d1p1:type='q4:string' xmlns:d1p1='{1}' xmlns='{2}'><\"te'st\"></>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, ANamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, "hello", true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<string d1p1:type='string' xmlns:d1p1='{0}' xmlns='{1}'>hello</string>",
+ XmlSchemaInstanceNamespace, XmlSchemaNamespace),
+ xsw.Content, "#6");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // #7 fails
+ public void TestWriteTypedPrimitive_UnsignedByte ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, (byte) 5, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>5</x>", ANamespace), xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, (byte) 125, false);
+ Assert.AreEqual ("<x>125</x>", xsw.Content, "#2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, (byte) 0, false);
+ Assert.AreEqual ("<x>0</x>", xsw.Content, "#3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, (byte) 255, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>255</x>", XmlSchemaNamespace), xsw.Content, "#4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, (byte) 128, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>128</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, (byte) 1, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>1</>", ANamespace), xsw.Content, "#6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, (byte) 99, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<unsignedByte xmlns='{0}'>99</unsignedByte>",
+ XmlSchemaNamespace), xsw.Content, "#7");
+ }
+
+ [Test]
+ public void TestWriteTypedPrimitive_UnsignedByte_XsiType ()
+ {
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, (byte) 5, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' d1p1:type='q1:unsignedByte' xmlns:d1p1='{1}'>5</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, (byte) 99, true);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:unsignedByte' xmlns:d1p1='{1}'>99</x>",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ xsw.Content, "#2");
}
+ [Test]
+ [Category ("NotWorking")] // #A7 fails
+ public void TestWriteTypedPrimitive_XmlQualifiedName ()
+ {
+ XmlQualifiedName qname = new XmlQualifiedName ("something", AnotherNamespace);
+
+ XmlSerializarionWriterTester xsw = new XmlSerializarionWriterTester ();
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q1='{0}' xmlns='{1}'>q1:something</x>",
+ AnotherNamespace, ANamespace), xsw.Content, "#A1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}'>q2:something</x>",
+ AnotherNamespace), xsw.Content, "#A2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q3='{0}'>q3:something</x>", AnotherNamespace),
+ xsw.Content, "#A3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q4='{0}' xmlns='{1}'>q4:something</x>", AnotherNamespace,
+ XmlSchemaNamespace), xsw.Content, "#A4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q5='{0}' xmlns='{1}'>q5:something</x>", AnotherNamespace,
+ XmlSchemaInstanceNamespace), xsw.Content, "#A5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns:q6='{0}' xmlns='{1}'>q6:something</>", AnotherNamespace,
+ ANamespace), xsw.Content, "#A6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<QName xmlns:q7='{0}' xmlns='{1}'>q7:something</QName>",
+ AnotherNamespace, XmlSchemaNamespace), xsw.Content, "#A7");
+
+ xsw.Reset ();
+
+ qname = new XmlQualifiedName ("else");
+
+ xsw.ExecuteWriteTypedPrimitive ("x", ANamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>else</x>", ANamespace), xsw.Content, "#B1");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", string.Empty, qname, false);
+ Assert.AreEqual ("<x>else</x>", xsw.Content, "#B2");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", null, qname, false);
+ Assert.AreEqual ("<x>else</x>", xsw.Content, "#B3");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaNamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>else</x>", XmlSchemaNamespace), xsw.Content, "#B4");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive ("x", XmlSchemaInstanceNamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}'>else</x>", XmlSchemaInstanceNamespace),
+ xsw.Content, "#B5");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (string.Empty, ANamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "< xmlns='{0}'>else</>", ANamespace), xsw.Content, "#B6");
+
+ xsw.Reset ();
+
+ xsw.ExecuteWriteTypedPrimitive (null, ANamespace, qname, false);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<QName xmlns='{0}'>else</QName>", XmlSchemaNamespace),
+ xsw.Content, "#B7");
+ }
+
+ [Test]
+ [ExpectedException (typeof (NullReferenceException))]
+ public void TestWriteTypedPrimitive_Null_Value()
+ {
+ WriteTypedPrimitive("x", ANamespace, null, false);
+ }
+
+ [Test]
+ [Category ("NotWorking")] // InvalidOperatinException is not thrown
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void TestWriteTypedPrimitive_NonPrimitive ()
+ {
+ // The type System.Version was not expected. Use the XmlInclude
+ // or SoapInclude attribute to specify types that are not known
+ // statically.
+ WriteTypedPrimitive ("x", ANamespace, new Version (), false);
+ }
+
+ [Test]
public void TestWriteValue()
{
WriteValue("");
- Assertion.AssertEquals("", Content);
+ Assert.AreEqual ("", Content);
Reset();
WriteValue("hello");
- Assertion.AssertEquals("hello", Content);
+ Assert.AreEqual ("hello", Content);
Reset();
string v = null;
WriteValue(v);
- Assertion.AssertEquals("", Content);
+ Assert.AreEqual ("", Content);
Reset();
WriteValue(new byte[] {13, 8, 99});
- Assertion.AssertEquals("DQhj", Content);
+ Assert.AreEqual ("DQhj", Content);
}
public void TestWriteXmlAttribute()
@@ -438,12 +1405,158 @@ namespace MonoTests.System.XmlSerialization // XmlNode related
}
+ [Test]
public void TestWriteXsiType()
{
WriteStartElement("x");
WriteXsiType("pref", null);
WriteEndElement();
- Assertion.AssertEquals(XmlSerializerTests.Infoset("<x d1p1:type='pref' xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' />"), XmlSerializerTests.Infoset(Content));
+ Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
+ "<x d1p1:type='pref' xmlns:d1p1='{0}' />", XmlSchemaInstanceNamespace),
+ Content, "#1");
+
+ Reset ();
+
+ WriteStartElement ("x");
+ WriteXsiType ("int", XmlSchemaNamespace);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
+ "<x xmlns:q2='{0}' d1p1:type='q2:int' xmlns:d1p1='{1}' />",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace),
+ Content, "#2");
+
+ Reset ();
+
+ WriteStartElement ("x");
+ WriteXsiType ("int", ANamespace);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q3='{0}' d1p1:type='q3:int' xmlns:d1p1='{1}' />",
+ ANamespace, XmlSchemaInstanceNamespace), Content, "#3");
+
+ Reset ();
+
+ WriteStartElement ("x");
+ WriteXsiType ("int", XmlSchemaInstanceNamespace);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q4='{0}' q4:type='q4:int' />",
+ XmlSchemaInstanceNamespace), Content, "#4");
+
+ Reset ();
+
+ WriteStartElement ("x");
+ WriteXsiType ("int", string.Empty);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='int' xmlns:d1p1='{0}' />", XmlSchemaInstanceNamespace),
+ Content, "#5");
+
+ Reset ();
+
+ WriteStartElement ("x");
+ WriteXsiType (string.Empty, null);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='' xmlns:d1p1='{0}' />", XmlSchemaInstanceNamespace),
+ Content, "#6");
+
+ Reset ();
+
+ WriteStartElement ("x");
+ WriteXsiType (null, null);
+ WriteEndElement ();
+ Assert.AreEqual ("<x />", Content, "#7");
+ }
+
+ [Test]
+ [Category ("NotWorking")] // order of namespace declaration differs from that of MSFT
+ public void TestWriteXsiType_Namespace ()
+ {
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType ("pref", null);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='pref' xmlns:d1p1='{0}' xmlns='{1}' />",
+ XmlSchemaInstanceNamespace, ANamespace), Content, "#1");
+
+ Reset ();
+
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType ("int", XmlSchemaNamespace);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q5='{0}' d1p1:type='q5:int' xmlns:d1p1='{1}' xmlns='{2}' />",
+ XmlSchemaNamespace, XmlSchemaInstanceNamespace, ANamespace),
+ Content, "#2");
+
+ Reset ();
+
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType ("int", ANamespace);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='int' xmlns:d1p1='{1}' xmlns='{2}' />",
+ ANamespace, XmlSchemaInstanceNamespace, ANamespace),
+ Content, "#3");
+
+ Reset ();
+
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType ("int", XmlSchemaInstanceNamespace);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns:q6='{0}' q6:type='q6:int' xmlns='{1}' />",
+ XmlSchemaInstanceNamespace, ANamespace), Content, "#4");
+
+ Reset ();
+
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType ("int", string.Empty);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='int' xmlns:d1p1='{0}' xmlns='{1}' />",
+ XmlSchemaInstanceNamespace, ANamespace), Content, "#5");
+
+ Reset ();
+
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType (string.Empty, null);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x d1p1:type='' xmlns:d1p1='{0}' xmlns='{1}' />",
+ XmlSchemaInstanceNamespace, ANamespace), Content, "#6");
+
+ Reset ();
+
+ WriteStartElement ("x", ANamespace);
+ WriteXsiType (null, null);
+ WriteEndElement ();
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "<x xmlns='{0}' />", ANamespace), Content, "#7");
+ }
+
+
+#if NET_2_0
+ [Test]
+ public void TestFromEnum_Null_TypeName ()
+ {
+ string[] values = { "one", "two", "three", "four" };
+ long[] ids = { 1, 2, 3, 4 };
+
+ Assert.AreEqual ("one", FromEnum (1, values, ids, (string) null));
+ }
+
+ [Test]
+ public void TestCreateInvalidEnumValueException ()
+ {
+ Exception ex = CreateInvalidEnumValueException("AnInvalidValue", "SomeType");
+ Assert.IsNotNull (ex, "#1");
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNotNull (ex.Message, "#3");
+ Assert.IsTrue (ex.Message.IndexOf ("AnInvalidValue") != -1, "#4");
+ Assert.IsTrue (ex.Message.IndexOf ("SomeType") != -1, "#5");
}
+#endif
}
}
|