~euantorano/system.text.json-object-serialization

ref: 361368ff9bdcb75072c0895dfcdbc2317bf3c744 system.text.json-object-serialization/JsonEncodeTest/SerializeTests.cs -rw-r--r-- 1.4 KiB
361368ffEuan Torano Initial commit 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Xunit;

namespace JsonEncodeTest
{
    public class SerializeTests
    {
        [Theory]
        [InlineData(true)]
        [InlineData(false)]
        public void TestBaseClassToJson(bool useNewtonSoft)
        {
            const string expected = "{\"int_val\":42}";

            var bc = new BaseClass
            {
                IntVal = 42
            };

            var actual = useNewtonSoft ? bc.ToJsonJsonNet() : bc.ToJsonSystemText();

            Assert.Equal(expected, actual);
        }

        [Theory]
        [InlineData(true)]
        [InlineData(false)]
        public void TestSubClassToJson(bool useNewtonSoft)
        {
            const string expected = "{\"string_val\":\"hello world\",\"int_val\":42}";

            var sc = new SubClass
            {
                StringVal = "hello world",
                IntVal = 42
            };

            var actual = useNewtonSoft ? sc.ToJsonJsonNet() : sc.ToJsonSystemText();

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void TestBrokenSubClassToJson()
        {
            const string expected = "{\"int_val\":42}";

            var sc = new SubClass
            {
                StringVal = "hello world",
                IntVal = 42
            };

            var actual = sc.ToJsonSystemTextBroken();

            Assert.Equal(expected, actual);
        }
    }
}