public void DataSetClearTest()
{
var ds = new DataSet();
DataTable parent = ds.Tables.Add("Parent");
DataTable child = ds.Tables.Add("Child");
parent.Columns.Add("id", typeof(int));
child.Columns.Add("ref_id", typeof(int));
child.Constraints.Add(new ForeignKeyConstraint("fk_constraint", parent.Columns[0], child.Columns[0]));
DataRow dr = parent.NewRow();
dr[0] = 1;
parent.Rows.Add(dr);
dr.AcceptChanges();
dr = child.NewRow();
dr[0] = 1;
child.Rows.Add(dr);
dr.AcceptChanges();
try
{
ds.Clear(); // this should clear all the rows in parent & child tables
}
catch (Exception e)
{
throw (new Exception("Exception should not have been thrown at Clear method" + e.ToString()));
}
Assert.Equal(0, parent.Rows.Count);
Assert.Equal(0, child.Rows.Count);
}