public void Should_deserialize_using_configured_JsonSerializerSettings()
        {
            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(StandardSettings);

            string serialized = "{\"StringProperty\":\"\\u003chtml\\u003e\\u003c/html\\u003e\",\"IntProperty\":1}";

            SampleClass deserialized = serializer.Deserialize(serialized);

            deserialized.ShouldBeEquivalentTo(new
            {
                IntProperty    = 1,
                StringProperty = "<html></html>"
            });
        }
        public void Should_serialize_using_configured_JsonSerializerSettings()
        {
            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(StandardSettings);

            SampleClass objectToSerialize = new SampleClass()
            {
                StringProperty = "<html></html>",
                IntProperty    = 1
            };

            string serialized = serializer.Serialize(objectToSerialize);

            serialized.Should().Be("{\"StringProperty\":\"\\u003chtml\\u003e\\u003c/html\\u003e\",\"IntProperty\":1}");
        }
Example #3
0
        public void Should_deserialize_null_to_default_value()
        {
            Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings()
            {
                StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml
            };

            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(settings);

            string serialized = null;

            SampleClass deserialized = serializer.Deserialize(serialized);

            deserialized.Should().BeNull();
        }
Example #4
0
        public void Should_serialize_default_value_to_null()
        {
            Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings()
            {
                StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml
            };

            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(settings);

            SampleClass objectToSerialize = default(SampleClass);

            string serialized = serializer.Serialize(objectToSerialize);

            serialized.Should().BeNull();
        }
Example #5
0
        public void Should_deserialize_using_configured_JsonSerializerSettings()
        {
            Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings()
            {
                StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml
            };

            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(settings);

            string serialized = "{\"StringProperty\":\"\\u003chtml\\u003e\\u003c/html\\u003e\",\"IntProperty\":1}";

            SampleClass deserialized = serializer.Deserialize(serialized);

            deserialized.ShouldBeEquivalentTo(new
            {
                IntProperty    = 1,
                StringProperty = "<html></html>"
            });
        }
Example #6
0
        public void Should_serialize_using_configured_JsonSerializerSettings()
        {
            Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings()
            {
                StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml
            };

            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(settings);

            SampleClass objectToSerialize = new SampleClass()
            {
                StringProperty = "<html></html>",
                IntProperty    = 1
            };

            string serialized = serializer.Serialize(objectToSerialize);

            serialized.Should().Be("{\"StringProperty\":\"\\u003chtml\\u003e\\u003c/html\\u003e\",\"IntProperty\":1}");
        }
        public void Should_roundtrip_all_variants_of_reference_type(SampleClass testValue)
        {
            JsonSerializer <SampleClass> serializer = new JsonSerializer <SampleClass>(StandardSettings);

            serializer.Deserialize(serializer.Serialize(testValue)).ShouldBeEquivalentTo(testValue);
        }