Author: lluis
Date: 2005-03-31 03:40:30 -0500 (Thu, 31 Mar 2005)
New Revision: 42417
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/DeserializeTests.cs
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTestClasses.cs
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
Log:
2005-03-30 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* XmlSerializerTests.cs:
* XmlReflectionImporterTests.cs:
* DeserializeTests.cs:
* XmlSerializerTestClasses.cs: Added tests for serialization of choices.
Modified: trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
2005-03-31 08:38:38 UTC (rev 42416)
+++ trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
2005-03-31 08:40:30 UTC (rev 42417)
@@ -1,3 +1,10 @@
+2005-03-30 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * XmlSerializerTests.cs:
+ * XmlReflectionImporterTests.cs:
+ * DeserializeTests.cs:
+ * XmlSerializerTestClasses.cs: Added tests for serialization of choices.
+
2005-03-29 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* XmlSerializerTests.cs:
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/DeserializeTests.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/DeserializeTests.cs
2005-03-31 08:38:38 UTC (rev 42416)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/DeserializeTests.cs
2005-03-31 08:40:30 UTC (rev 42417)
@@ -177,5 +177,21 @@
Assertion.Assert ("#1", c.node is XmlText);
Assertion.AssertEquals ("#2", "text", c.node.Value);
}
+
+ [Test]
+ public void TestDeserializeChoices ()
+ {
+ Choices ch = (Choices) Deserialize (typeof(Choices),
"<Choices><ChoiceZero>choice text</ChoiceZero></Choices>");
+ Assertion.AssertEquals ("#1", "choice text",
ch.MyChoice);
+ Assertion.AssertEquals ("#2",
ItemChoiceType.ChoiceZero, ch.ItemType);
+
+ ch = (Choices) Deserialize (typeof(Choices),
"<Choices><ChoiceOne>choice text</ChoiceOne></Choices>");
+ Assertion.AssertEquals ("#1", "choice text",
ch.MyChoice);
+ Assertion.AssertEquals ("#2",
ItemChoiceType.StrangeOne, ch.ItemType);
+
+ ch = (Choices) Deserialize (typeof(Choices),
"<Choices><ChoiceTwo>choice text</ChoiceTwo></Choices>");
+ Assertion.AssertEquals ("#1", "choice text",
ch.MyChoice);
+ Assertion.AssertEquals ("#2", ItemChoiceType.ChoiceTwo,
ch.ItemType);
+ }
}
}
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
2005-03-31 08:38:38 UTC (rev 42416)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
2005-03-31 08:40:30 UTC (rev 42417)
@@ -429,7 +429,13 @@
AssertEquals("Int32", tm.TypeName);
AssertEquals("System.Int32", tm.TypeFullName);
}
-
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void TestSerializeWrongChoice ()
+ {
+ new XmlSerializer (typeof(WrongChoices));
+ }
}
}
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTestClasses.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTestClasses.cs
2005-03-31 08:38:38 UTC (rev 42416)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTestClasses.cs
2005-03-31 08:40:30 UTC (rev 42417)
@@ -147,5 +147,38 @@
public class NodeContainer
{
public XmlNode node;
- }
+ }
+
+ public class Choices
+ {
+ [XmlElementAttribute("ChoiceZero", typeof(string),
IsNullable=false)]
+ [XmlElementAttribute("ChoiceOne", typeof(string),
IsNullable=false)]
+ [XmlElementAttribute("ChoiceTwo", typeof(string),
IsNullable=false)]
+ [XmlChoiceIdentifier("ItemType")]
+ public string MyChoice;
+
+ [XmlIgnore]
+ public ItemChoiceType ItemType;
+ }
+
+ [XmlType(IncludeInSchema = false)]
+ public enum ItemChoiceType
+ {
+ ChoiceZero,
+ [XmlEnum ("ChoiceOne")]
+ StrangeOne,
+ ChoiceTwo,
+ }
+
+ public class WrongChoices
+ {
+ [XmlElementAttribute("ChoiceZero", typeof(string),
IsNullable=false)]
+ [XmlElementAttribute("StrangeOne", typeof(string),
IsNullable=false)]
+ [XmlElementAttribute("ChoiceTwo", typeof(string),
IsNullable=false)]
+ [XmlChoiceIdentifier("ItemType")]
+ public string MyChoice;
+
+ [XmlIgnore]
+ public ItemChoiceType ItemType;
+ }
}
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
2005-03-31 08:38:38 UTC (rev 42416)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
2005-03-31 08:40:30 UTC (rev 42417)
@@ -698,6 +698,22 @@
c.node = doc.CreateTextNode("text");
Serialize (c);
AssertEquals(Infoset("<NodeContainer
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><node>text</node></NodeContainer>"),
WriterText);
+ }
+
+ [Test]
+ public void TestSerializeChoice ()
+ {
+ Choices ch = new Choices ();
+ ch.MyChoice = "choice text";
+ ch.ItemType = ItemChoiceType.ChoiceZero;
+ Serialize (ch);
+ AssertEquals(Infoset("<Choices
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><ChoiceZero>choice
text</ChoiceZero></Choices>"), WriterText);
+ ch.ItemType = ItemChoiceType.StrangeOne;
+ Serialize (ch);
+ AssertEquals(Infoset("<Choices
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><ChoiceOne>choice
text</ChoiceOne></Choices>"), WriterText);
+ ch.ItemType = ItemChoiceType.ChoiceTwo;
+ Serialize (ch);
+ AssertEquals(Infoset("<Choices
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><ChoiceTwo>choice
text</ChoiceTwo></Choices>"), WriterText);
}
public static string Infoset (string sx)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches