public void ParseBadType2()
        {
            var root = @"<Root></Root>".ToXmlView();
            var d = new GenericDeserializer(new XmlMapper());

            d.Deserialize<BadType2>(root);
        }
        public void BadParse3()
        {
            var root =
            @"<Root NInt2='' Int2=''></Root>".ToXmlView();
            var d = new GenericDeserializer();

            d.Deserialize<TestType1>(root);
        }
        public void ParseCollection()
        {
            var root =
            @"<root coll='5'><coll>-5</coll></root>".ToXmlView();
            var d = new GenericDeserializer();

            var tc = d.Deserialize<ComplexTest>(root);

            CollectionAssert.AreEqual(new sbyte[] { 5, -5 }, tc.Coll);
        }
        public void ParseArray2()
        {
            var root =
            @"<root array='123'><array>345</array></root>".ToXmlView();
            var d = new GenericDeserializer();

            var tc = d.Deserialize<ComplexTest>(root);

            CollectionAssert.AreEqual(new int[] { 123, 345 }, tc.Array);
        }
        public void ParseGoodType_Blob()
        {
            var root =
            @"<Root xmlBlob='MTIz'></Root>".ToXmlView();
            var d = new GenericDeserializer(new XmlMapper());

            var t = d.Deserialize<GoodType>(root);

            Assert.That(t.Blob, Is.EquivalentTo(new byte[] {49, 50, 51}));
        }
        public void ParseGoodType2()
        {
            var root =
            @"<Root Ignored='1'><xmlInner xmlNInt='321'></xmlInner></Root>".ToXmlView();
            var d = new GenericDeserializer(new XmlMapper());

            var t = d.Deserialize<GoodType>(root);

            Assert.IsFalse(t.Ignored);
            Assert.IsNotNull(t.Inner);
            Assert.AreEqual(321, t.Inner.NInt);
        }
        public void ParseEmptyCollections()
        {
            var root =
            @"<Root></Root>".ToXmlView();
            var d = new GenericDeserializer();

            var tc = d.Deserialize<ComplexTest>(root);

            CollectionAssert.IsEmpty(tc.Array);
            CollectionAssert.IsEmpty(tc.Coll);
            Assert.IsNull(tc.Inner);
            CollectionAssert.IsEmpty(tc.InnerList);
        }
        public void ParseGoodType1()
        {
            var root =
            @"<Root Ignored='true'><xmlNInt>123</xmlNInt></Root>".ToXmlView();
            var d = new GenericDeserializer(new XmlMapper());

            var t = d.Deserialize<GoodType>(root);

            Assert.IsFalse(t.Ignored);
            Assert.AreEqual(123, t.NInt);
            Assert.IsNull(t.Inner);
            Assert.AreEqual(0, t.InnerList.Count);
        }
        public void EmptyParse()
        {
            var root =
            @"<root ignored='true' nint2='' int2='123' cfgNode2='' ><inner2 NInt=''/></root>".ToXmlView();
            var d = new GenericDeserializer();

            var t = d.Deserialize<TestType1>(root);

            Assert.AreEqual(false, t.Ignored);

            Assert.AreEqual(null, t.Inner1);
            Assert.NotNull(t.Inner2);
            Assert.AreEqual(123, t.Int2);
            Assert.AreEqual(null, t.NInt2);
        }
        public void BadParsePath()
        {
            try
            {
                var root =
            @"<Root NInt2='1' Int2='1'><CfgNode2 /><Inner1 /></Root>".ToXmlView();
                var d = new GenericDeserializer();

                d.Deserialize<TestType1>(root);
            }
            catch (DeserializeChildException ex)
            {
                var fullPath = string.Join("/", ex.FullPath);
                Assert.That(fullPath, Is.EqualTo("Inner1/NInt"));
                Assert.That(ex.Reason, Is.InstanceOf<FormatException>());
            }
        }
 public static void Deserialize <T, U>(this ListTreeNode <T> self, ref U value)
     where T : IListTreeItem, IValue <T>
 {
     GenericDeserializer <T, U> .Deserialize(self, ref value);
 }
Пример #12
0
 private static T Deserialize <T>(Func <string> func)
 {
     return(GenericDeserializer.Deserialize(func, JsonConvert.DeserializeObject <T>));
 }
        public void ParseInnerList()
        {
            var root =
            @"<root><innerlist coll='5'><coll>-5</coll></innerlist><innerlist coll='6'><coll>-6</coll></innerlist></root>".ToXmlView();
            var d = new GenericDeserializer();

            var tc = d.Deserialize<ComplexTest>(root);

            CollectionAssert.AreEqual(new sbyte[] { 5, -5 }, tc.InnerList[0].Coll);
            CollectionAssert.AreEqual(new sbyte[] { 6, -6 }, tc.InnerList[1].Coll);
        }
        public void ParsePrimitiveType()
        {
            var root = @"<Config
            TextField='val1' TextProp='val2'
            BoolField='+' BoolProp='false'
            NBoolField='T' NBoolProp=''
            ByteField='123' ByteProp='12'
            NByteProp=''
            EnProp='One'
            ><NByteField>0</NByteField></Config>".ToXmlView();
            var d = new GenericDeserializer();

            var tc = d.Deserialize<PrimitiveTypeCollection>(root);

            Assert.AreEqual("val1", tc.TextField);
            Assert.AreEqual("val2", tc.TextProp);

            Assert.AreEqual(true, tc.BoolField);
            Assert.AreEqual(false, tc.BoolProp);
            Assert.AreEqual(true, tc.NBoolField);
            Assert.AreEqual(null, tc.NBoolProp);
            Assert.AreEqual(123, tc.ByteField);
            Assert.AreEqual(12, tc.ByteProp);
            Assert.AreEqual(0, tc.NByteField);
            Assert.AreEqual(null, tc.NByteProp);
            Assert.AreEqual(TestEn.One, tc.EnProp);
        }
        public void RequiredNullable()
        {
            var root =
            @"<Root NInt=''></Root>".ToXmlView();
            var d = new GenericDeserializer();

            var t = d.Deserialize<TestType2>(root);

            Assert.AreEqual(null, t.NInt);
        }