Ejemplo n.º 1
0
        public void FromJsonTest()
        {
            Assert.Null(SerDeExtensions.FromJson <ITestInterface>(null));
            Assert.Null(SerDeExtensions.FromJson <ITestInterface>(string.Empty));

            Assert.Equal(0, SerDeExtensions.FromJson <int>(null));
            Assert.Equal(0, SerDeExtensions.FromJson <long>(string.Empty));

            string str = "Foo Bar";

            Assert.Equal(str, SerDeExtensions.FromJson <string>(str));
        }
Ejemplo n.º 2
0
        public void ToJsonTest()
        {
            Assert.Equal(string.Empty, SerDeExtensions.ToJson(null));

            string str = "Foo Bar";

            Assert.Equal(str, SerDeExtensions.ToJson(str));

            ITestInterface testObj = new TestClass("Foo")
            {
                Prop2 = 100
            };
            string json         = SerDeExtensions.ToJson(testObj);
            string expectedJson = @"{""Prop1"":""Foo"",""Prop2"":100}";

            Assert.Equal(expectedJson, json);

            ITestInterface jsonConvertedObj = SerDeExtensions.FromJson <TestClass>(json);

            Assert.NotNull(jsonConvertedObj);
            Assert.Equal("Foo", jsonConvertedObj.GetProp1());
            Assert.Equal(100, jsonConvertedObj.GetProp2());
        }
Ejemplo n.º 3
0
        public void StringToJsonRoundtripTest(string input)
        {
            string value = SerDeExtensions.FromJson <string>(SerDeExtensions.ToJson(input));

            Assert.Equal(input, value);
        }