コード例 #1
0
        public void ShouldSerializeObjectWithTypeName()
        {
            var target = new SerializationTestTarget {
                Id = "42"
            };
            const string expected = "{\"$type\":\"" + TestTargetTypeName + "\",\"Id\":\"42\"}";

            JsonAssert.SerializesTo(target, expected);
        }
コード例 #2
0
        public void ShouldDeserializeObjectWithoutTypeInfo()
        {
            const string json     = "{\"$type\":\"" + TestTargetTypeName + "\",\"Id\":\"HalliGalli\"}";
            var          expected = new SerializationTestTarget {
                Id = "HalliGalli"
            };

            JsonAssert.DeserializesTo(json, expected);
        }
コード例 #3
0
        public void ShouldNotSerializeNullProperty()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            var target = new SerializationTestTarget {
                Id = null
            };
            const string expected = "{\"$type\":\"" + TestTargetTypeName + "\"}";

            JsonAssert.SerializesTo(target, expected);
        }
コード例 #4
0
        public void ShouldPrettyPrintObject()
        {
            var target = new SerializationTestTarget {
                Id = "Foo"
            };
            const string expected = "{\r\n" +
                                    "    \"Id\": \"Foo\"\r\n" +
                                    "}";
            var actual = target.ToPrettyPrintJson();

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void ShouldNotSerializeNullPropertyWhenFormatting()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            var target = new SerializationTestTarget {
                Id = null
            };
            const string expected = "{\r\n" +
                                    "    \"$type\": \"" + TestTargetTypeName + "\"\r\n" +
                                    "}";
            var actual = target.ToFormattedJson();

            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
        public void ShouldSerializeFormatted()
        {
            var target = new SerializationTestTarget {
                Id = "666"
            };
            const string expected = "{\r\n" +
                                    "    \"$type\": \"" + TestTargetTypeName + "\",\r\n" +
                                    "    \"Id\": \"666\"\r\n" +
                                    "}";
            var actual = target.ToFormattedJson();

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
 private bool Equals(SerializationTestTarget other)
 {
     return(string.Equals(Id, other.Id));
 }