@@ -508,6 +508,32 @@ public void Can_Deserialize_Boolean_From_String()
508508 Assert . True ( output . Value ) ;
509509 }
510510
511+ [ Fact ]
512+ public void Can_Deserialize_Empty_Elements_With_Attributes_to_Nullable_Values ( )
513+ {
514+ var doc = CreateXmlWithAttributesAndNullValues ( ) ;
515+
516+ var xml = new XmlDeserializer ( ) ;
517+ var output = xml . Deserialize < NullableValues > ( new RestResponse { Content = doc } ) ;
518+
519+ Assert . Null ( output . Id ) ;
520+ Assert . Null ( output . StartDate ) ;
521+ Assert . Null ( output . UniqueId ) ;
522+ }
523+
524+ [ Fact ]
525+ public void Can_Deserialize_Mixture_Of_Empty_Elements_With_Attributes_And_Populated_Elements ( )
526+ {
527+ var doc = CreateXmlWithAttributesAndNullValuesAndPopulatedValues ( ) ;
528+
529+ var xml = new XmlDeserializer ( ) ;
530+ var output = xml . Deserialize < NullableValues > ( new RestResponse { Content = doc } ) ;
531+
532+ Assert . Null ( output . Id ) ;
533+ Assert . Null ( output . StartDate ) ;
534+ Assert . Equal ( new Guid ( GuidString ) , output . UniqueId ) ;
535+ }
536+
511537 private static string CreateUnderscoresXml ( )
512538 {
513539 var doc = new XDocument ( ) ;
@@ -753,5 +779,39 @@ private static string CreateXmlWithEmptyInlineList()
753779
754780 return doc . ToString ( ) ;
755781 }
782+
783+ private static string CreateXmlWithAttributesAndNullValues ( )
784+ {
785+ var doc = new XDocument ( ) ;
786+ var root = new XElement ( "NullableValues" ) ;
787+
788+ var idElement = new XElement ( "Id" , null ) ;
789+ idElement . SetAttributeValue ( "SomeAttribute" , "SomeAttribute_Value" ) ;
790+ root . Add ( idElement ,
791+ new XElement ( "StartDate" , null ) ,
792+ new XElement ( "UniqueId" , null )
793+ ) ;
794+
795+ doc . Add ( root ) ;
796+
797+ return doc . ToString ( ) ;
798+ }
799+
800+ private static string CreateXmlWithAttributesAndNullValuesAndPopulatedValues ( )
801+ {
802+ var doc = new XDocument ( ) ;
803+ var root = new XElement ( "NullableValues" ) ;
804+
805+ var idElement = new XElement ( "Id" , null ) ;
806+ idElement . SetAttributeValue ( "SomeAttribute" , "SomeAttribute_Value" ) ;
807+ root . Add ( idElement ,
808+ new XElement ( "StartDate" , null ) ,
809+ new XElement ( "UniqueId" , new Guid ( GuidString ) )
810+ ) ;
811+
812+ doc . Add ( root ) ;
813+
814+ return doc . ToString ( ) ;
815+ }
756816 }
757817}
0 commit comments