@@ -43,9 +43,31 @@ public static void Xml_ByteArrayAsRoot()
4343 Assert . Equal ( x , y ) ;
4444 }
4545
46+ [ Fact ]
47+ public static void Xml_ByteArrayNull ( )
48+ {
49+ Assert . Null ( SerializeAndDeserialize < byte [ ] > ( null ,
50+ @"<?xml version=""1.0""?>
51+ <base64Binary d1p1:nil=""true"" xmlns:d1p1=""http://www.w3.org/2001/XMLSchema-instance"" />" ) ) ;
52+ byte [ ] x = new byte [ ] { 1 , 2 } ;
53+ byte [ ] y = SerializeAndDeserialize < byte [ ] > ( x ,
54+ @"<?xml version=""1.0""?>
55+ <base64Binary>AQI=</base64Binary>" ) ;
56+ Assert . Equal ( x , y ) ;
57+ }
58+
4659 [ Fact ]
4760 public static void Xml_CharAsRoot ( )
4861 {
62+ Assert . StrictEqual ( char . MinValue , SerializeAndDeserialize < char > ( char . MinValue ,
63+ @"<?xml version=""1.0""?>
64+ <char>0</char>" ) ) ;
65+ Assert . StrictEqual ( char . MaxValue , SerializeAndDeserialize < char > ( char . MaxValue ,
66+ @"<?xml version=""1.0""?>
67+ <char>65535</char>" ) ) ;
68+ Assert . StrictEqual ( 'a' , SerializeAndDeserialize < char > ( 'a' ,
69+ @"<?xml version=""1.0""?>
70+ <char>97</char>" ) ) ;
4971 Assert . StrictEqual ( '\u00F1 ' , SerializeAndDeserialize < char > ( '\u00F1 ' ,
5072@"<?xml version=""1.0""?>
5173<char>241</char>" ) ) ;
@@ -2313,14 +2335,32 @@ public static void Xml_Soap_ObjectAsRoot()
23132335 "<?xml version=\" 1.0\" ?>\r \n <anyType d1p1:type=\" boolean\" xmlns:d1p1=\" http://www.w3.org/2001/XMLSchema-instance\" xmlns=\" http://www.w3.org/2001/XMLSchema\" >true</anyType>" ,
23142336 ( ) => ser ) ) ;
23152337
2338+ Assert . Equal (
2339+ "abc" ,
2340+ SerializeAndDeserialize < object > (
2341+ "abc" ,
2342+ "<?xml version=\" 1.0\" ?>\r \n <anyType d1p1:type=\" string\" xmlns:d1p1=\" http://www.w3.org/2001/XMLSchema-instance\" xmlns=\" http://www.w3.org/2001/XMLSchema\" >abc</anyType>" ,
2343+ ( ) => ser ) ) ;
2344+
2345+ var nullDeserialized = SerializeAndDeserialize < object > (
2346+ null ,
2347+ "<?xml version=\" 1.0\" ?>\r \n <xsd:anyType xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\" http://www.w3.org/2001/XMLSchema\" />" ,
2348+ ( ) => ser ) ;
2349+ Assert . NotNull ( nullDeserialized ) ;
2350+ Assert . True ( typeof ( object ) == nullDeserialized . GetType ( ) ) ;
2351+ }
2352+
2353+ [ Fact ]
2354+ public static void Xml_Soap_ObjectAsRoot_Nullable ( )
2355+ {
23162356 XmlTypeMapping nullableTypeMapping = new SoapReflectionImporter ( ) . ImportTypeMapping ( typeof ( TypeWithNullableObject ) ) ;
2317- var nullableSer = new XmlSerializer ( nullableTypeMapping ) ;
2357+ var ser = new XmlSerializer ( nullableTypeMapping ) ;
23182358
23192359 var value = new TypeWithNullableObject { MyObject = null } ;
23202360 TypeWithNullableObject actual = SerializeAndDeserialize (
23212361 value ,
23222362 "<?xml version=\" 1.0\" ?>\r \n <TypeWithNullableObject xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\" http://www.w3.org/2001/XMLSchema\" id=\" id1\" >\r \n <MyObject xsi:nil=\" true\" />\r \n </TypeWithNullableObject>" ,
2323- ( ) => nullableSer ) ;
2363+ ( ) => ser ) ;
23242364 Assert . NotNull ( actual ) ;
23252365 Assert . Null ( actual . MyObject ) ;
23262366 }
@@ -2449,6 +2489,34 @@ public static void XmlSerializationGeneratedCodeTest()
24492489 Assert . NotNull ( cg ) ;
24502490 }
24512491
2492+ [ Fact ]
2493+ // XmlTypeMapping is not included in System.Xml.XmlSerializer 4.0.0.0 facade in GAC
2494+ public static void Xml_FromMappings ( )
2495+ {
2496+ var types = new [ ] { typeof ( Guid ) , typeof ( List < string > ) } ;
2497+ XmlReflectionImporter importer = new XmlReflectionImporter ( ) ;
2498+ XmlTypeMapping [ ] mappings = new XmlTypeMapping [ types . Length ] ;
2499+ for ( int i = 0 ; i < types . Length ; i ++ )
2500+ {
2501+ mappings [ i ] = importer . ImportTypeMapping ( types [ i ] ) ;
2502+ }
2503+ var serializers = XmlSerializer . FromMappings ( mappings , typeof ( object ) ) ;
2504+ Xml_GuidAsRoot_Helper ( serializers [ 0 ] ) ;
2505+ Xml_ListGenericRoot_Helper ( serializers [ 1 ] ) ;
2506+ }
2507+
2508+ [ Fact ]
2509+ // XmlTypeMapping is not included in System.Xml.XmlSerializer 4.0.0.0 facade in GAC
2510+ public static void Xml_ConstructorWithTypeMapping ( )
2511+ {
2512+ XmlTypeMapping mapping = null ;
2513+ XmlSerializer serializer = null ;
2514+ Assert . Throws < ArgumentNullException > ( ( ) => { new XmlSerializer ( mapping ) ; } ) ;
2515+
2516+ mapping = new XmlReflectionImporter ( null , null ) . ImportTypeMapping ( typeof ( List < string > ) ) ;
2517+ serializer = new XmlSerializer ( mapping ) ;
2518+ Xml_ListGenericRoot_Helper ( serializer ) ;
2519+ }
24522520
24532521 [ Fact ]
24542522 public static void XmlMembersMapping_PrimitiveValue ( )
0 commit comments