public void Should_Deserialize_DataTable_Using_Clr_Types() { string testData = "{\"name\":\"Table1\"," + "\"columns\":[{\"name\":\"Int32\",\"type\":\"System.Int32\"},{\"name\":\"Int16\",\"type\":\"System.Int16\"}," + "{\"name\":\"Int64\",\"type\":\"System.Int64\"},{\"name\":\"Decimal\",\"type\":\"System.Decimal\"}," + "{\"name\":\"Float\",\"type\":\"System.Single\"},{\"name\":\"Double\",\"type\":\"System.Double\"}," + "{\"name\":\"String\",\"type\":\"System.String\"},{\"name\":\"DateTime\",\"type\":\"System.DateTime\"}," + "{\"name\":\"Boolean\",\"type\":\"System.Boolean\"}]," + "\"keys\":[\"Int32\",\"Int16\"]," + "\"rows\":[[12,2,3,123.4,543.21,321.98,\"Hello!\",1416873600000,true]," + "[23,1,null,null,null,null,null,null,false]]}"; var settings = new JsonSerializerSettings { Converters = new List <JsonConverter> { new DataTableJsonConverter(useClrTypes: true) } }; DataTable actual = JsonConvert.DeserializeObject <DataTable>(testData, settings); DataTable expected = TestDataHelper.GetTestData(); Assert.Equal(expected.TableName, actual.TableName); Assert.Equal(expected.Columns.Count, actual.Columns.Count); Assert.Equal(expected.PrimaryKey.Length, actual.PrimaryKey.Length); Assert.Equal(expected.Rows.Count, actual.Rows.Count); AssertHelper.AssertColumns(expected.Columns, actual.Columns, true); AssertHelper.AssertPrimaryKeys(expected.PrimaryKey, actual.PrimaryKey); AssertHelper.AssertRows(expected, actual, true); }
public void Should_Deserialize_DataView_WithoutKeys() { string testData = "{\"name\":\"Table1\"," + "\"columns\":[{\"name\":\"Int32\",\"type\":\"number\"},{\"name\":\"Int16\",\"type\":\"number\"}," + "{\"name\":\"Int64\",\"type\":\"number\"},{\"name\":\"Decimal\",\"type\":\"number\"}," + "{\"name\":\"Float\",\"type\":\"number\"},{\"name\":\"Double\",\"type\":\"number\"}," + "{\"name\":\"String\",\"type\":\"string\"},{\"name\":\"DateTime\",\"type\":\"datetime\"}," + "{\"name\":\"Boolean\",\"type\":\"boolean\"}]," + "\"rows\":[[12,2,3,123.4,543.21,321.98,\"Hello!\",1416873600000,true]," + "[23,1,null,null,null,null,null,null,false]]}"; var settings = new JsonSerializerSettings { Converters = new List <JsonConverter> { new DataViewJsonConverter() } }; DataView actual = JsonConvert.DeserializeObject <DataView>(testData, settings); DataTable expected = TestDataHelper.GetTestDataWithoutKeys(); Assert.Equal(expected.TableName, actual.Table.TableName); Assert.Equal(expected.Columns.Count, actual.Table.Columns.Count); Assert.Equal(expected.PrimaryKey.Length, actual.Table.PrimaryKey.Length); Assert.Equal(expected.Rows.Count, actual.Table.Rows.Count); AssertHelper.AssertColumns(expected.Columns, actual.Table.Columns); AssertHelper.AssertRows(expected, actual.Table); }