public void DefaultBinarySerializer_Test()
        {
            var o1 = new TestSerializeClass()
            {
                Id   = 1,
                Name = "zhang",
                Age  = 19
            };
            IBinarySerializer binarySerializer = new DefaultBinarySerializer();
            var binary1 = binarySerializer.Serialize(o1);

            var o2 = binarySerializer.Deserialize <TestSerializeClass>(binary1);

            Assert.Equal(o1.Id, o2.Id);
            Assert.Equal(o1.Name, o2.Name);
            Assert.Equal(o1.Age, o2.Age);

            var o3 = (TestSerializeClass)binarySerializer.Deserialize(binary1, typeof(TestSerializeClass));

            Assert.Equal(o1.Id, o3.Id);
            Assert.Equal(o1.Name, o3.Name);
            Assert.Equal(o1.Age, o3.Age);
        }
Exemple #2
0
        public void DefaultJsonSerializer_Test()
        {
            var o1 = new TestSerializeClass()
            {
                Id   = 1,
                Name = "zhang",
                Age  = 19
            };
            IJsonSerializer jsonSerializer = new DefaultJsonSerializer();
            var             json1          = jsonSerializer.Serialize(o1);

            var o2 = jsonSerializer.Deserialize <TestSerializeClass>(json1);

            Assert.Equal(o1.Id, o2.Id);
            Assert.Equal(o1.Name, o2.Name);
            Assert.Equal(o1.Age, o2.Age);

            var o3 = (TestSerializeClass)jsonSerializer.Deserialize(json1, typeof(TestSerializeClass));

            Assert.Equal(o1.Id, o3.Id);
            Assert.Equal(o1.Name, o3.Name);
            Assert.Equal(o1.Age, o3.Age);
        }
        public void DefaultXmlSerializer_Test()
        {
            var o1 = new TestSerializeClass()
            {
                Id   = 1,
                Name = "zhang",
                Age  = 19
            };
            IXmlSerializer xmlSerializer = new DefaultXmlSerializer();
            var            xml1          = xmlSerializer.Serialize(o1);

            var o2 = xmlSerializer.Deserialize <TestSerializeClass>(xml1);

            Assert.Equal(o1.Id, o2.Id);
            Assert.Equal(o1.Name, o2.Name);
            Assert.Equal(o1.Age, o2.Age);

            var o3 = (TestSerializeClass)xmlSerializer.Deserialize(xml1, typeof(TestSerializeClass));

            Assert.Equal(o1.Id, o3.Id);
            Assert.Equal(o1.Name, o3.Name);
            Assert.Equal(o1.Age, o3.Age);
        }