Bläddra i källkod

* System.Xml.Serialization/XmlSerializerTestClasses.cs,
System.Xml.Serialization/XmlSerializerTests.cs: Test nullable
enums.

svn path=/trunk/mcs/; revision=99517

Lluis Sanchez 18 år sedan
förälder
incheckning
9d4657431e

+ 5 - 0
mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog

@@ -1,3 +1,8 @@
+2008-04-01  Lluis Sanchez Gual <[email protected]> 
+
+	* XmlSerializerTestClasses.cs, XmlSerializerTests.cs: Test nullable
+	  enums.
+
 2008-03-31  Gert Driesen  <[email protected]>
 
 	* XmlCodeExporterTests.cs: Remove CWL.

+ 19 - 0
mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTestClasses.cs

@@ -147,6 +147,25 @@ namespace MonoTests.System.Xml.TestClasses
 			nestedinner = new GenNestedClass<T1, T2>.InnerClass<T1> ();
 		}
 	}
+		
+	public class WithNulls
+	{
+		[XmlElement (IsNullable=true)]
+		public int? nint;
+		
+		[XmlElement (IsNullable=true)]
+		public TestEnumWithNulls? nenum;
+		
+		[XmlElement (IsNullable=true)]
+		public DateTime? ndate;
+	}
+	
+	public enum TestEnumWithNulls
+	{
+		aa,
+		bb
+	}
+	
 #endif
 
 	#endregion // GenericsTestClasses

+ 52 - 0
mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs

@@ -2213,6 +2213,58 @@ namespace MonoTests.System.XmlSerialization
 			int? i = (int?) ser.Deserialize (new StringReader (sw.ToString ()));
 			Assert.AreEqual (5, i);
 		}
+
+		[Test]
+		public void NullableEnums ()
+		{
+			WithNulls w = new WithNulls ();
+			XmlSerializer ser = new XmlSerializer (typeof(WithNulls));
+			StringWriter tw = new StringWriter ();
+			ser.Serialize (tw, w);
+
+			string expected = "<?xml version='1.0' encoding='utf-16'?>" +
+				"<WithNulls xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
+					"<nint xsi:nil='true' />" +
+					"<nenum xsi:nil='true' />" +
+					"<ndate xsi:nil='true' />" +
+					"</WithNulls>";
+			
+			Assert.AreEqual (Infoset (expected), Infoset (tw.ToString ()));
+			
+			StringReader sr = new StringReader (tw.ToString ());
+			w = (WithNulls) ser.Deserialize (sr);
+			
+			Assert.IsFalse (w.nint.HasValue);
+			Assert.IsFalse (w.nenum.HasValue);
+			Assert.IsFalse (w.ndate.HasValue);
+			
+			DateTime t = new DateTime (2008,4,1);
+			w.nint = 4;
+			w.ndate = t;
+			w.nenum = TestEnumWithNulls.bb;
+			
+			tw = new StringWriter ();
+			ser.Serialize (tw, w);
+			
+			expected = "<?xml version='1.0' encoding='utf-16'?>" +
+				"<WithNulls xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
+					"<nint>4</nint>" +
+					"<nenum>bb</nenum>" +
+					"<ndate>2008-04-01T00:00:00</ndate>" +
+					"</WithNulls>";
+			
+			Assert.AreEqual (Infoset (expected), Infoset (tw.ToString ()));
+			
+			sr = new StringReader (tw.ToString ());
+			w = (WithNulls) ser.Deserialize (sr);
+			
+			Assert.IsTrue (w.nint.HasValue);
+			Assert.IsTrue (w.nenum.HasValue);
+			Assert.IsTrue (w.ndate.HasValue);
+			Assert.AreEqual (4, w.nint.Value);
+			Assert.AreEqual (TestEnumWithNulls.bb, w.nenum.Value);
+			Assert.AreEqual (t, w.ndate.Value);
+		}
 #endif
 
 		[Test]