@@ -78,6 +78,26 @@ public void Can_serialize_simple_POCO_With_DateFormat_Specified() {
7878 Assert . Equal ( expected . ToString ( ) , doc . ToString ( ) ) ;
7979 }
8080
81+ [ Fact ]
82+ public void Can_serialize_simple_POCO_With_XmlFormat_Specified ( )
83+ {
84+ var poco = new Person
85+ {
86+ Name = "Foo" ,
87+ Age = 50 ,
88+ Price = 19.95m ,
89+ StartDate = new DateTime ( 2009 , 12 , 18 , 10 , 2 , 23 ) ,
90+ IsCool = false
91+ } ;
92+
93+ var xml = new XmlSerializer ( ) ;
94+ xml . DateFormat = DateFormat . Iso8601 ;
95+ var doc = xml . Serialize ( poco ) ;
96+ var expected = GetSimplePocoXDocWithXmlProperty ( ) ;
97+
98+ Assert . Equal ( expected . ToString ( ) , doc . ToString ( ) ) ;
99+ }
100+
81101 [ Fact ]
82102 public void Can_serialize_simple_POCO_With_Different_Root_Element ( ) {
83103 var poco = new Person {
@@ -158,6 +178,7 @@ private class Person
158178 public decimal Price { get ; set ; }
159179 public DateTime StartDate { get ; set ; }
160180 public List < Item > Items { get ; set ; }
181+ public bool ? IsCool { get ; set ; }
161182 }
162183
163184 private class Item
@@ -220,6 +241,21 @@ private XDocument GetSimplePocoXDocWithIsoDate() {
220241 return doc ;
221242 }
222243
244+ private XDocument GetSimplePocoXDocWithXmlProperty ( )
245+ {
246+ var doc = new XDocument ( ) ;
247+ var root = new XElement ( "Person" ) ;
248+ root . Add ( new XElement ( "Name" , "Foo" ) ,
249+ new XElement ( "Age" , 50 ) ,
250+ new XElement ( "Price" , 19.95m ) ,
251+ new XElement ( "StartDate" , new DateTime ( 2009 , 12 , 18 , 10 , 2 , 23 ) . ToString ( "s" ) ) ,
252+ new XElement ( "IsCool" , false ) ) ;
253+
254+ doc . Add ( root ) ;
255+
256+ return doc ;
257+ }
258+
223259 private XDocument GetSimplePocoXDocWithRoot ( ) {
224260 var doc = new XDocument ( ) ;
225261 var root = new XElement ( "Result" ) ;
0 commit comments