public void FindRows_ByKey()
{
DataRowView[] dvArr = null;
//create the source datatable
DataTable dt = DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
// FindRows ,no sort - exception
Assert.Throws<ArgumentException>(() =>
{
dvArr = dv.FindRows(3);
});
dv.Sort = "String1";
// Find = wrong sort, can not find
dvArr = dv.FindRows(3);
Assert.Equal(0, dvArr.Length);
dv.Sort = "ChildId";
//get expected results
DataRow[] drExpected = dt.Select("ChildId=3");
// FindRows - check count
dvArr = dv.FindRows(3);
Assert.Equal(drExpected.Length, dvArr.Length);
// FindRows - check data
//check that result is ok
bool Succeed = true;
for (int i = 0; i < dvArr.Length; i++)
{
Succeed = (int)dvArr[i]["ChildId"] == (int)drExpected[i]["ChildId"];
if (!Succeed) break;
}
Assert.Equal(true, Succeed);
}