Esempio n. 1
0
        public void Deserialize_ValidInput_ObjectDeserialized()
        {
            // Setup the test.
            string text = @"{""propertyOne"":""This is a property to serialize."",""propertyTwo"":""This is another property to serialize.""}";

            // Run the test.
            JsonSerializer         serializer = new JsonSerializer();
            SerializableTestObject results    = serializer.Deserialize <SerializableTestObject>(text);

            // Validate the results.
            Assert.AreEqual("This is a property to serialize.", results.PropertyOne);
            Assert.AreEqual("This is another property to serialize.", results.PropertyTwo);
        }
Esempio n. 2
0
        public void Serialize_ValidInput_ObjectSerialized()
        {
            // Setup the test.
            SerializableTestObject value = new SerializableTestObject
            {
                PropertyOne = "This is a property to serialize.",
                PropertyTwo = "This is another property to serialize.",
            };

            string expectedResults = @"{""propertyOne"":""This is a property to serialize."",""propertyTwo"":""This is another property to serialize.""}";

            // Run the test.
            JsonSerializer serializer = new JsonSerializer();
            string         results    = serializer.Serialize <SerializableTestObject>(value);

            // Validate the results.
            Assert.AreEqual(expectedResults, results);
        }
Esempio n. 3
0
        public void Serialize_NullObject_ThrowsArgumentNullExceptionn()
        {
            try
            {
                // Setup the test.
                JsonSerializer         serializer = new JsonSerializer();
                SerializableTestObject value      = null;

                // Run the test.
                serializer.Serialize <SerializableTestObject>(value);
            }
            catch (ArgumentNullException ex)
            {
                // Validate the results.
                Assert.AreEqual("value", ex.ParamName);
                throw;
            }
        }