Esempio n. 1
0
        public void TestDefaultValue()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(CompatibilityTest3));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(CompatibilityTest2));
            var s3 = new XmSerializerModel();

            s3.AddType(typeof(CompatibilityTest1));

            var dto  = new CompatibilityTest2();
            var xml  = s2.Serialize(dto);
            var dto2 = s.Deserialize <CompatibilityTest3>(xml);

            Assert.IsNotNull(dto2);
            Assert.AreEqual("barfoo", dto2.Foobar);

            var dto3 = new CompatibilityTest1 {
                Foobar = "foobar"
            };
            var xml2 = s3.Serialize(dto3);
            var dto4 = s.Deserialize <CompatibilityTest3>(xml2);

            Assert.AreEqual("foobar", dto4.Foobar);
        }
Esempio n. 2
0
        public void TestDeactivation()
        {
            var s1 = new XmSerializerModel();

            s1.AddType(typeof(DeactivationTestClass1));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(DeactivationTestClass2));

            var dto1 = new DeactivationTestClass1 {
                Foobar = "foo"
            };
            var dto2 = new DeactivationTestClass2 {
                Foobar = "bar"
            };

            var xml1    = s1.Serialize(dto1);
            var result1 = s2.Deserialize <DeactivationTestClass2>(xml1);
            var result2 = s1.Deserialize <DeactivationTestClass1>(xml1);

            Assert.AreEqual(result1.Foobar, dto1.Foobar);
            Assert.IsNull(result2.Foobar);

            var xml2    = s2.Serialize(dto2);
            var result3 = s2.Deserialize <DeactivationTestClass2>(xml2);
            var result4 = s1.Deserialize <DeactivationTestClass1>(xml2);

            Assert.IsNull(result3.Foobar);
            Assert.IsNull(result4.Foobar);
        }
Esempio n. 3
0
        public void TestValueConversion()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(ValueConversionTestClass1));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(ValueConversionTestClass2));

            var dto = new ValueConversionTestClass1()
            {
                V1 = 5,
                V2 = 6,
                V3 = 7,
                V4 = 8,
                V5 = 9,
                V6 = 10,
                V7 = 11,
            };
            var xml = s.Serialize(dto);

            var result = s2.Deserialize <ValueConversionTestClass2>(xml);

            Assert.AreEqual(result.V1, dto.V1);
            Assert.AreEqual(result.V2, dto.V2);
            Assert.AreEqual(result.V3, dto.V3);
            Assert.AreEqual(result.V4, dto.V4);
            Assert.AreEqual(result.V5, dto.V5);
            Assert.AreEqual(result.V6, dto.V6);
            Assert.AreEqual(result.V7, dto.V7);
        }
Esempio n. 4
0
        public void TestReducedNumberOfTypeParametersParsing()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(Foo <, ,>));

            var s2 = new XmSerializerModel();

            s2.AddType(typeof(Foo <,>));

            var s3 = new XmSerializerModel();

            s3.AddType(typeof(Foo));

            var obj = new Foo <string, int, bool>
            {
                Field1 = "foobar",
                Field2 = 42,
                Field3 = true
            };

            var xml    = s.Serialize(obj);
            var result = (Foo <string, int>)s2.Deserialize <object>(xml);

            Assert.AreEqual(result.Field1, obj.Field1);
            Assert.AreEqual(result.Field2, obj.Field2);
            Assert.AreEqual(result.Field3, obj.Field3);

            var result2 = s3.Deserialize <Foo>(xml);

            Assert.AreEqual(result2.Field1, obj.Field1);
            Assert.AreEqual(result2.Field2, obj.Field2);
            Assert.AreEqual(result2.Field3, obj.Field3);
        }
Esempio n. 5
0
        public void TestDeserializingPriority()
        {
            var serializer = new XmSerializerModel();

            serializer.AddType(typeof(PriorityCallbackTestClass));

            var instance = new PriorityCallbackTestClass();
            var xml      = serializer.Serialize(instance);
            var result   = serializer.Deserialize <PriorityCallbackTestClass>(xml);

            Assert.AreEqual("-1,0,1,2,9", result.DeserializeOrder);
        }
Esempio n. 6
0
        public static T TestSerialization <T>(T dto, XmSerializerModel serializer)
        {
            var xml  = serializer.Serialize(dto);
            var ret  = serializer.Deserialize <T>(xml);
            var xml2 = serializer.Serialize(ret);

            Assert.AreEqual(xml.ToString(), xml2.ToString());
            Assert.AreEqual(dto.GetType(), ret.GetType());
            Directory.CreateDirectory(@"output\");
            File.WriteAllText($@"output\{typeof(T).Name}.csv", xml2.ToString());
            return(ret);
        }
Esempio n. 7
0
        public void TestSkipConstructor()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(ConstructorTestClass2));

            var obj    = new ConstructorTestClass2();
            var xml    = s.Serialize(obj);
            var result = s.Deserialize <ConstructorTestClass2>(xml);

            Assert.IsNull(result.TestField);
            Assert.IsNull(result.TestField2);
        }
Esempio n. 8
0
        public void TestConstructor()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(ConstructorTestClass));

            var obj    = new ConstructorTestClass();
            var xml    = s.Serialize(obj);
            var result = s.Deserialize <ConstructorTestClass>(xml);

            Assert.AreEqual(obj.TestField, result.TestField);
            Assert.AreEqual(obj.TestField2, result.TestField2);
        }
Esempio n. 9
0
        public void TestBackwardCompatibility()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(CompatibilityTest1));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(CompatibilityTest2));

            var dto  = new CompatibilityTest2();
            var xml  = s2.Serialize(dto);
            var dto2 = s.Deserialize <CompatibilityTest1>(xml);

            Assert.IsNotNull(dto2);
        }
Esempio n. 10
0
        public void TestOverriddedCallbacks()
        {
            var serializer = new XmSerializerModel();

            serializer.AddType(typeof(OverriddenCallbackTestClass1));
            serializer.AddType(typeof(OverriddenCallbackTestClass2));

            var instance = new OverriddenCallbackTestClass2();
            var xml      = serializer.Serialize(instance);
            var result   = serializer.Deserialize <OverriddenCallbackTestClass2>(xml);

            Assert.AreEqual(11, result.FooCounter);
            Assert.AreEqual(11, result.BarCounter);
            Assert.AreEqual(22, result.FooBarCounter);
        }
Esempio n. 11
0
        public void TestSkipInstantiating()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(SkipInstantiatingTestClass));

            var obj = new SkipInstantiatingTestClass();

            obj.TestList.Add("test");
            var xml    = s.Serialize(obj);
            var result = s.Deserialize <SkipInstantiatingTestClass>(xml);

            Assert.AreEqual("foobar", result.TestList[0]);
            Assert.AreEqual("test", result.TestList[1]);
            Assert.AreEqual(2, result.TestList.Count);
        }
Esempio n. 12
0
        public void TestForwardCompatibility()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(CompatibilityTest1));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(CompatibilityTest2));

            var dto = new CompatibilityTest1 {
                Foobar = "foobar"
            };
            var xml  = s.Serialize(dto);
            var dto2 = s2.Deserialize <CompatibilityTest2>(xml);

            Assert.IsNotNull(dto2);
        }
Esempio n. 13
0
        public void TestClassCompatibility()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(CompatibilityTest1));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(CompatibilityTest3));

            var dto = new CompatibilityTest1 {
                Foobar = "foobar"
            };
            var xml  = s.Serialize(dto);
            var dto2 = s2.Deserialize <CompatibilityTest3>(xml);

            Assert.IsNotNull(dto2);
            Assert.AreEqual(dto.Foobar, dto2.Foobar);
        }
Esempio n. 14
0
        public void TestCallbacks()
        {
            var serializer = new XmSerializerModel();

            serializer.AddType(typeof(CallbackTestClass));

            var instance = new CallbackTestClass();

            instance.DeSerializeTestValue3 = "test";
            var xml    = serializer.Serialize(instance);
            var result = serializer.Deserialize <CallbackTestClass>(xml);

            Assert.AreEqual("OnSerialized", instance.SerializeTestValue);
            Assert.AreEqual("OnSerialized", instance.SerializeTestValue2);
            Assert.AreEqual("OnSerializing", result.SerializeTestValue);
            Assert.AreEqual("OnSerializing", result.SerializeTestValue2);
            Assert.AreEqual("test", result.DeSerializeTestValue3);
            Assert.IsNull(result.DeSerializeTestValue4);
            Assert.AreEqual("OnDeserialized", result.DeSerializeTestValue);
            Assert.AreEqual("OnDeserialized", result.DeSerializeTestValue2);
        }
Esempio n. 15
0
        public void TestLegacyName()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(OldTestClass));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(NewTestClass));

            var dto = new OldTestClass {
                Foobar = "foobar"
            };
            var xml  = s.Serialize(dto);
            var dto2 = s2.Deserialize <NewTestClass>(xml);

            Assert.IsNotNull(dto2);
            Assert.AreEqual(dto.Foobar, dto2.Barfoo);

            var dto3 = BasicTest.TestSerialization(dto2, s2);

            Assert.IsNotNull(dto3);
            Assert.AreEqual(dto.Foobar, dto3.Barfoo);
        }
Esempio n. 16
0
        public void TestEnumCompatibility()
        {
            var s = new XmSerializerModel();

            s.AddType(typeof(FooBar1));
            var s2 = new XmSerializerModel();

            s2.AddType(typeof(FooBar2));
            var s3 = new XmSerializerModel();

            s3.AddType(typeof(FooBar3));

            var dto = FooBar1.Bar;
            var xml = s.Serialize(dto);

            var result2 = s2.Deserialize <FooBar2>(xml);

            Assert.AreEqual(FooBar2.Bar, result2);

            var result3 = s3.Deserialize <FooBar3>(xml);

            Assert.AreEqual(FooBar3.Bar1, result3);
        }