public void Generate()
{
DataTable dtParent;
dtParent = DataProvider.CreateParentDataTable();
Exception tmpEx = new Exception();
//------ check ForeignKeyConstraint ---------
DataTable dtChild = DataProvider.CreateChildDataTable();
var ds = new DataSet();
ds.Tables.Add(dtChild);
ds.Tables.Add(dtParent);
ds.Relations.Add(new DataRelation("myRelation", dtParent.Columns[0], dtChild.Columns[0], true));
//update to value which is not exists in Parent table
// InvalidConstraintException - update child row
Assert.Throws<InvalidConstraintException>(() =>
{
dtChild.Rows[0]["ParentId"] = 99;
});
//Add another relation to the same column of the existing relation in child table
// InvalidConstraintException - Add Relation Child
Assert.Throws<InvalidConstraintException>(() =>
{
ds.Relations.Add(new DataRelation("test", dtParent.Columns[2], dtChild.Columns[0], true));
});
//Attempt to clear rows from parent table
// InvalidConstraintException - RowsCollection.Clear
Assert.Throws<InvalidConstraintException>(() =>
{
dtParent.Rows.Clear();
});
//try to run commands on two different datasets
DataSet ds1 = new DataSet();
ds1.Tables.Add(dtParent.Copy());
// InvalidConstraintException - Add relation with two DataSets
Assert.Throws<InvalidConstraintException>(() =>
{
ds.Relations.Add(new DataRelation("myRelation", ds1.Tables[0].Columns[0], dtChild.Columns[0], true));
});
}
}