Inheritance: IXmlSerializerOptions
Ejemplo n.º 1
0
        public void EnumAttributeDeserializesCorrectlyWhenExtraTypesArePassedIn()
        {
            var xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<EnumAttributeContainer xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" MyEnum=""Value2"" />";

            var serializer = new CustomSerializer <EnumAttributeContainer>(null, TestXmlSerializerOptions.WithExtraTypes(typeof(IFoo)));

            var container = (EnumAttributeContainer)serializer.DeserializeObject(xml);

            Assert.That(container.MyEnum, Is.EqualTo(MyEnum.Value2));
        }
Ejemplo n.º 2
0
        public void EnumAttributeDeserializesCorrectlyWhenIgnoreCaseForEnumIsPassedIn()
        {
            var xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<EnumAttributeContainer xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" MyEnum=""vALUE1"" />";

            var serializer = new CustomSerializer <EnumAttributeContainer>(null, TestXmlSerializerOptions.WithExtraTypes());

            var container = (EnumAttributeContainer)serializer.DeserializeObject(xml, new TestSerializeOptions {
                ShouldIgnoreCaseForEnum = true
            });

            Assert.That(container.MyEnum, Is.EqualTo(MyEnum.Value1));
        }
Ejemplo n.º 3
0
        public void EnumAttributeSerializesCorrectlyWhenExtraTypesArePassedIn()
        {
            var container = new EnumAttributeContainer
            {
                MyEnum = MyEnum.Value2
            };

            var serializer = new CustomSerializer <EnumAttributeContainer>(null, TestXmlSerializerOptions.WithExtraTypes(typeof(IFoo)));

            var xml = serializer.SerializeObject(container, Encoding.UTF8, Formatting.Indented, new TestSerializeOptions());

            Assert.That(xml, Contains.Substring("Value2"));
        }