public void RoleGetsProperlySerialized() { //Arrange ------------------ string columnJson = null; var column = new Column(ColumnType.String) { Role = ColumnRole.Annotation }; //Act ---------------------- MemoryStream ms = null; try { ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); column.GetJson(sw); sw.Flush(); ms.Position = 0; using (var sr = new StreamReader(ms)) { columnJson = sr.ReadToEnd(); } } catch (System.Exception) { if (ms != null) { ms.Dispose(); } } //Assert ------------------- Assert.That(columnJson != null); //check the values ColumnTested restoredCol = JsonHelper.GetFromJson <ColumnTested>(columnJson); Assert.That(restoredCol.p.role.ToString() == ColumnRole.Annotation); }
public void DataTable_GetSimpleJsonWithColumnsWithDateTimeFormat() { //Arrange ------------ DataTable dt = GetNewDataTableInstance(); Column col = new Column(ColumnType.String, "Year"); Column col2 = new Column(ColumnType.Date, "DateTime"); dt.AddColumn(col); dt.AddColumn(col2); var row = dt.NewRow(); row.AddCell(new Cell() { Value = "Year", Formatted = "MyYears" }); row.AddCell(new Cell() { Value = new DateTime(2013, 01, 01), Formatted = "Now" }); dt.AddRow(row); //Act ----------------- var json = dt.GetJson(); //Assert -------------- Assert.IsTrue(json != null); ColumnTested jsonObject = JsonHelper.GetFromJson <ColumnTested>(json); //retrieving the ordinal position of the object var value = jsonObject.rows[0].c[0].v.ToString(); var formatted = jsonObject.rows[0].c[0].f.ToString(); var valueCell2 = jsonObject.rows[0].c[1].v.ToString(); var formattedCell2 = jsonObject.rows[0].c[1].f.ToString(); Assert.That(value == "Year"); Assert.That(formatted == "MyYears"); Assert.That(valueCell2 == "Date(2013, 0, 1)"); Assert.That(formattedCell2 == "Now"); }
public void Column_Property_And_Role_Specified() { //Arrange ------------------ string columnJson; string PROP_VALUE = "value"; var column = new Column(ColumnType.String) { Role = ColumnRole.Annotation }; column.AddProperty(new Property("property1", PROP_VALUE)); //Act ---------------------- using (var ms = new MemoryStream()) { var sw = new StreamWriter(ms); column.GetJson(sw); sw.Flush(); ms.Position = 0; using (var sr = new StreamReader(ms)) { columnJson = sr.ReadToEnd(); } } //Assert ------------------- Assert.That(columnJson != null); ColumnTested restoredCol = JsonHelper.GetFromJson <ColumnTested>(columnJson); Assert.That(restoredCol.p.role.ToString() == ColumnRole.Annotation); Assert.That(restoredCol.p.property1.ToString() == PROP_VALUE); }