public void Document_with_table() { //Arrange var documentData = new DocumentData(); var t = new DocumentDataTable("TableA"); var row = new Dictionary <string, string>(); row.Add("Row1A", "RowData1A"); row.Add("Row1B", "RowData1B"); row.Add("Row1C", "RowData1C"); t.AddRow(row); var row2 = new Dictionary <string, string>(); row2.Add("Row2A", "RowData2A"); row2.Add("Row2B", "RowData2A"); row2.Add("Row2C", "RowData2A"); t.AddRow(row2); documentData.Add(t); var xml = documentData.ToXml(); //Act var other = DocumentData.Load(xml); //Assert Assert.AreEqual(documentData.Get("A"), other.Get("A")); Assert.AreEqual(documentData.GetDataTable("TableA").Rows.Count, other.GetDataTable("TableA").Rows.Count); Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[0]).Columns.First().Key, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[0]).Columns.First().Key); Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[0]).Columns.First().Value, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[0]).Columns.First().Value); Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[1]).Columns.First().Key, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[1]).Columns.First().Key); Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[1]).Columns.First().Value, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[1]).Columns.First().Value); Assert.AreEqual(xml.OuterXml, other.ToXml().OuterXml); }
public void When_serializing_and_deserializing_data_with_group_lines() { //Arrange var originalDocumentData = new DocumentData(); var tableData = new DocumentDataTable("A"); tableData.AddGroup("Group1"); tableData.AddRow(new Dictionary <string, string> { { "Col1", "Data1A" }, { "Col2", "Data2A" } }); tableData.AddRow(new Dictionary <string, string> { { "Col1", "Data1B" }, { "Col2", "Data2B" } }); tableData.AddGroup("Group2"); tableData.AddRow(new Dictionary <string, string> { { "Col1", "Data1C" }, { "Col2", "Data2C" } }); originalDocumentData.Add(tableData); var xmlDocumentData = originalDocumentData.ToXml(); //Act var loadedDocumentData = DocumentData.Load(xmlDocumentData); //Assert Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count, loadedDocumentData.GetDataTable("A").Rows.Count); Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableData), loadedDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableData)); Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableGroup), loadedDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableGroup)); Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content); Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.Last(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content, (loadedDocumentData.GetDataTable("A").Rows.Last(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content); Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Key, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Key); Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Value, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Value); }
public void Default_Document() { //Arrange var documentData = new DocumentData(); var xml = documentData.ToXml(); //Act var other = DocumentData.Load(xml); //Assert Assert.AreEqual(documentData.Get("A"), other.Get("A")); Assert.AreEqual(documentData.GetDataTable("TableA"), other.GetDataTable("TableA")); Assert.AreEqual(xml.OuterXml, other.ToXml().OuterXml); }