public void ImportValueTypesTest() { string json = @" { ""TestByte"": 200, ""TestChar"": 'P', ""TestDateTime"": ""12/22/2012 00:00:00"", ""TestDecimal"": 10.333, ""TestSByte"": -5, ""TestShort"": 1024, ""TestUShort"": 30000, ""TestUInt"": 90000000, ""TestULong"": 1 }"; ValueTypesTest test = JsonMapper.ToObject <ValueTypesTest> (json); Assert.AreEqual(200, test.TestByte, "A1"); Assert.AreEqual('P', test.TestChar, "A2"); Assert.AreEqual(new DateTime(2012, 12, 22), test.TestDateTime, "A3"); Assert.AreEqual(10.333m, test.TestDecimal, "A4"); Assert.AreEqual(-5, test.TestSByte, "A5"); Assert.AreEqual(1024, test.TestShort, "A6"); Assert.AreEqual(30000, test.TestUShort, "A7"); Assert.AreEqual(90000000, test.TestUInt, "A8"); Assert.AreEqual(1L, test.TestULong, "A9"); }
public void ImportValueTypesTest() { string json = @" { ""TestByte"": 200, ""TestChar"": 'P', ""TestDateTime"": ""12/22/2012 00:00:00"", ""TestDecimal"": 10.333, ""TestSByte"": -5, ""TestShort"": 1024, ""TestUShort"": 30000, ""TestUInt"": 90000000, ""TestULong"": 18446744073709551615, ""TestDateTimeOffset"": ""2019-09-18T16:47:50.1234567+08:00"" }"; ValueTypesTest test = JsonMapper.ToObject <ValueTypesTest> (json); Assert.AreEqual(200, test.TestByte, "A1"); Assert.AreEqual('P', test.TestChar, "A2"); Assert.AreEqual(new DateTime(2012, 12, 22), test.TestDateTime, "A3"); Assert.AreEqual(10.333m, test.TestDecimal, "A4"); Assert.AreEqual(-5, test.TestSByte, "A5"); Assert.AreEqual(1024, test.TestShort, "A6"); Assert.AreEqual(30000, test.TestUShort, "A7"); Assert.AreEqual(90000000, test.TestUInt, "A8"); Assert.AreEqual(18446744073709551615L, test.TestULong, "A9"); Assert.AreEqual( new DateTimeOffset(2019, 9, 18, 16, 47, 50, 123, TimeSpan.FromHours(8)).AddTicks(4567), test.TestDateTimeOffset, "A10"); }
public void ExportValueTypesTest() { ValueTypesTest test = new ValueTypesTest(); test.TestByte = 200; test.TestChar = 'P'; test.TestDateTime = new DateTime(2012, 12, 22); test.TestDecimal = 10.333m; test.TestSByte = -5; test.TestShort = 1024; test.TestUShort = 30000; test.TestUInt = 90000000; test.TestULong = 0xFFFFFFFFFFFFFFFF; // = =18446744073709551615 test.TestDateTimeOffset = new DateTimeOffset(2019, 9, 18, 16, 47, 50, 123, TimeSpan.FromHours(8)).AddTicks(4567); string json = JsonMapper.ToJson(test); string expected = "{\"TestByte\":200,\"TestChar\":\"P\",\"TestDateTime\":" + "\"12/22/2012 00:00:00\",\"TestDecimal\":10.333," + "\"TestSByte\":-5,\"TestShort\":1024,\"TestUShort\":30000" + ",\"TestUInt\":90000000,\"TestULong\":18446744073709551615" + ",\"TestDateTimeOffset\":\"2019-09-18T16:47:50.1234567+08:00\"}"; Assert.AreEqual(expected, json); }
public void CustomImporterTest() { // Custom DateTime importer that only uses the Year value // (assuming January 1st of that year) ImporterFunc <long, DateTime> importer = delegate(long obj) { return(new DateTime((int)obj, 1, 1)); }; JsonMapper.RegisterImporter <long, DateTime> (importer); string json = "{ \"TestDateTime\" : 1980 }"; ValueTypesTest sample = JsonMapper.ToObject <ValueTypesTest> (json); JsonMapper.UnregisterImporters(); Assert.AreEqual(new DateTime(1980, 1, 1), sample.TestDateTime); }
public void ExportValueTypesTest() { ValueTypesTest test = new ValueTypesTest(); test.TestByte = 200; test.TestChar = 'P'; test.TestDateTime = new DateTime(2012, 12, 22); test.TestDecimal = 10.333m; test.TestSByte = -5; test.TestShort = 1024; test.TestUShort = 30000; test.TestUInt = 90000000; test.TestULong = 1L; string json = JsonMapper.ToJson(test); string expected = "{\"TestByte\":200,\"TestChar\":\"P\",\"TestDateTime\":" + "\"12/22/2012 00:00:00\",\"TestDecimal\":10.333," + "\"TestSByte\":-5,\"TestShort\":1024,\"TestUShort\":30000" + ",\"TestUInt\":90000000,\"TestULong\":1}"; Assert.AreEqual(expected, json); }
public void ExportValueTypesTest() { ValueTypesTest test = new ValueTypesTest (); test.TestByte = 200; test.TestChar = 'P'; test.TestDateTime = new DateTime (2012, 12, 22); test.TestDecimal = 10.333m; test.TestSByte = -5; test.TestShort = 1024; test.TestUShort = 30000; test.TestUInt = 90000000; test.TestULong = 1l; string json = JsonMapper.ToJson (test); string expected = "{\"TestByte\":200,\"TestChar\":\"P\",\"TestDateTime\":" + "\"12/22/2012 00:00:00\",\"TestDecimal\":10.333," + "\"TestSByte\":-5,\"TestShort\":1024,\"TestUShort\":30000" + ",\"TestUInt\":90000000,\"TestULong\":1}"; Assert.AreEqual (expected, json); }