public void XmlTest4()
{
//Create a parent table and create child tables
MakeParentTable1();
MakeChildTable();
MakeSecondChildTable();
//Relate the parent and the children
MakeDataRelation();
using (FileStream stream = new FileStream(_tempFile, FileMode.Create))
{
//WriteXml on any of the children
WriteXmlSerializable(stream, _childTable);
}
DataTable table = new DataTable();
ReadXmlSerializable(_tempFile, table);
//Test Schema
//Check Properties of Table
Assert.Equal(string.Empty, table.Namespace);
Assert.Null(table.DataSet);
Assert.Equal(3, table.Columns.Count);
Assert.Equal(false, table.CaseSensitive);
Assert.Equal("ChildTable", table.TableName);
Assert.Equal(string.Empty, table.Prefix);
Assert.Equal(1, table.Constraints.Count);
Assert.Equal("Constraint1", table.Constraints[0].ToString());
Assert.Equal(typeof(UniqueConstraint), table.Constraints[0].GetType());
Assert.Equal(0, table.PrimaryKey.Length);
Assert.Equal(0, table.ParentRelations.Count);
Assert.Equal(0, table.ChildRelations.Count);
//Check properties of each column
//First Column
DataColumn col = table.Columns[0];
Assert.Equal(true, col.AllowDBNull);
Assert.Equal(0, col.AutoIncrementSeed);
Assert.Equal(1, col.AutoIncrementStep);
Assert.Equal("Element", col.ColumnMapping.ToString());
Assert.Equal("ChildID", col.ColumnName);
Assert.Equal(typeof(int), col.DataType);
Assert.Equal(string.Empty, col.DefaultValue.ToString());
Assert.Equal(false, col.DesignMode);
Assert.Equal("System.Data.PropertyCollection", col.ExtendedProperties.ToString());
Assert.Equal(-1, col.MaxLength);
Assert.Equal(0, col.Ordinal);
Assert.Equal(string.Empty, col.Prefix);
Assert.Equal("ChildTable", col.Table.ToString());
Assert.Equal(true, col.Unique);
//Second Column
col = table.Columns[1];
Assert.Equal(true, col.AllowDBNull);
Assert.Equal(0, col.AutoIncrementSeed);
Assert.Equal(1, col.AutoIncrementStep);
Assert.Equal("Element", col.ColumnMapping.ToString());
Assert.Equal("ChildItem", col.Caption);
Assert.Equal("ChildItem", col.ColumnName);
Assert.Equal(typeof(string), col.DataType);
Assert.Equal(string.Empty, col.DefaultValue.ToString());
Assert.Equal(false, col.DesignMode);
Assert.Equal("System.Data.PropertyCollection", col.ExtendedProperties.ToString());
Assert.Equal(-1, col.MaxLength);
Assert.Equal(1, col.Ordinal);
Assert.Equal(string.Empty, col.Prefix);
Assert.Equal("ChildTable", col.Table.ToString());
Assert.Equal(false, col.Unique);
//Third Column
col = table.Columns[2];
Assert.Equal(true, col.AllowDBNull);
Assert.Equal(false, col.AutoIncrement);
Assert.Equal(0, col.AutoIncrementSeed);
Assert.Equal(1, col.AutoIncrementStep);
Assert.Equal("Element", col.ColumnMapping.ToString());
Assert.Equal("ParentID", col.Caption);
Assert.Equal("ParentID", col.ColumnName);
Assert.Equal(typeof(int), col.DataType);
Assert.Equal(string.Empty, col.DefaultValue.ToString());
Assert.Equal(false, col.DesignMode);
Assert.Equal("System.Data.PropertyCollection", col.ExtendedProperties.ToString());
Assert.Equal(-1, col.MaxLength);
Assert.Equal(2, col.Ordinal);
Assert.Equal(string.Empty, col.Prefix);
Assert.Equal("ChildTable", col.Table.ToString());
Assert.Equal(false, col.Unique);
//Test the Xml
Assert.Equal(6, table.Rows.Count);
//Test values of each row
DataRow row = table.Rows[0];
Assert.Equal(1, row["ChildID"]);
Assert.Equal("ChildItem 1", row["ChildItem"]);
Assert.Equal(1, row["ParentID"]);
row = table.Rows[1];
Assert.Equal(2, row["ChildID"]);
Assert.Equal("ChildItem 2", row["ChildItem"]);
Assert.Equal(1, row["ParentID"]);
row = table.Rows[2];
Assert.Equal(5, row["ChildID"]);
Assert.Equal("ChildItem 1", row["ChildItem"]);
Assert.Equal(2, row["ParentID"]);
row = table.Rows[3];
Assert.Equal(6, row["ChildID"]);
Assert.Equal("ChildItem 2", row["ChildItem"]);
Assert.Equal(2, row["ParentID"]);
row = table.Rows[4];
Assert.Equal(10, row["ChildID"]);
Assert.Equal("ChildItem 1", row["ChildItem"]);
Assert.Equal(3, row["ParentID"]);
row = table.Rows[5];
Assert.Equal(11, row["ChildID"]);
Assert.Equal("ChildItem 2", row["ChildItem"]);
Assert.Equal(3, row["ParentID"]);
}