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)); }
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()); }
public void StringToJsonRoundtripTest(string input) { string value = SerDeExtensions.FromJson <string>(SerDeExtensions.ToJson(input)); Assert.Equal(input, value); }