public void Should_Be_Able_To_Serialize_Advanced_Objects()
        {
            /* Setup */
            var advanced = new AdvancedTestClass
            {
                IntProp  = 3,
                ListProp = new List <string> {
                    "One", "Two"
                },
                ObjectRef = new SerializerTestClass
                {
                    StringProp = "Sub-object property"
                }
            };

            /* Test */
            var result = _serializer.Serialize(advanced);

            /* Assert */
            Assert.That(result, Is.StringStarting("{"), "Correct json object opening");
            Assert.That(result, Is.StringEnding("}"), "Correct json closing");
            Assert.That(result, Is.StringContaining("\"IntProp\":3"));
            Assert.That(result, Is.StringContaining("\"ObjectRef\":{\"StringProp\":\"Sub-object property\"}"));
            Assert.That(result, Is.StringContaining("\"ListProp\":[\"One\",\"Two\"]"));
        }
        public void Should_Be_Able_To_Deserialize_Objects()
        {
            /* Setup */
            var expected = new AdvancedTestClass
            {
                IntProp  = 3,
                ListProp = new List <string> {
                    "One", "Two"
                },
                ObjectRef = new SerializerTestClass
                {
                    StringProp = "Sub-object property"
                }
            };
            var input = JsonConvert.SerializeObject(expected);

            /* Test */
            var result = _serializer.Deserialize <AdvancedTestClass>(input);

            /* Assert */
            Assert.That(result.IntProp, Is.EqualTo(expected.IntProp));
            Assert.That(result.ObjectRef.StringProp, Is.EqualTo(expected.ObjectRef.StringProp));
            Assert.That(result.ListProp[0], Is.EqualTo(expected.ListProp[0]));
            Assert.That(result.ListProp[1], Is.EqualTo(expected.ListProp[1]));
        }
예제 #3
0
        public void Should_Be_Able_To_Serialize_Advanced_Objects()
        {
            /* Setup */
            var advanced = new AdvancedTestClass
            {
                IntProp  = 3,
                ListProp = new List <string> {
                    "One", "Two"
                },
                ObjectRef = new SerializerTestClass
                {
                    StringProp = "Sub-object property"
                }
            };

            /* Test */
            var result = _serializer.Serialize(advanced);

            /* Assert */
            Assert.That(result, Is.StringStarting("<?xml version=\"1.0\"?>"), "Correct xml object opening");
            Assert.That(result, Is.StringContaining("<IntProp>3</IntProp>"));
        }