public void SignedNumericConversionsExportTest() { SignedNumericConversionsTest value = new SignedNumericConversionsTest() { TestInt = 42, TestLong = 43L, TestFloat = 44.5F, TestDouble = 46.7 }; string expectedJson = "{\"TestInt\":42,\"TestLong\":43,\"TestFloat\":44.5,\"TestDouble\":46.7}"; Assert.AreEqual(expectedJson, JsonMapper.ToJson(value)); // Test with Long.MaxValue value.TestLong = 9223372036854775807; expectedJson = "{\"TestInt\":42,\"TestLong\":9223372036854775807,\"TestFloat\":44.5,\"TestDouble\":46.7}"; Assert.AreEqual(expectedJson, JsonMapper.ToJson(value)); }
public void SignedNumericConversionsImportTest() { string json = @" { ""TestInt"": 42, ""TestLong"": 43, ""TestFloat"": 44, ""TestDouble"": 45 }"; SignedNumericConversionsTest value = JsonMapper.ToObject <SignedNumericConversionsTest>(json); Assert.AreEqual(value.TestInt, 42); Assert.AreEqual(value.TestLong, 43L); Assert.AreEqual(value.TestFloat, 44F); Assert.AreEqual(value.TestDouble, 45.0); json = @" { ""TestFloat"": 42.3, ""TestDouble"": 44.5 }"; value = JsonMapper.ToObject <SignedNumericConversionsTest>(json); Assert.AreEqual(value.TestFloat, 42.3F); Assert.AreEqual(value.TestDouble, 44.5); json = "{ \"TestInt\": 42.2 }"; bool exceptionThrown = false; try { JsonMapper.ToObject <SignedNumericConversionsTest> (json); } catch (JsonException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); json = "{ \"TestLong\": 42.2 }"; exceptionThrown = false; try { JsonMapper.ToObject <SignedNumericConversionsTest> (json); } catch (JsonException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); }