public void FindRows_ByKeys()
{
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(new object[] { "3", "3-String1" });
});
dv.Sort = "String1,ChildId";
// Find = wrong sort, can not find
Assert.Throws<FormatException>(() =>
{
dvArr = dv.FindRows(new object[] { "3", "3-String1" });
});
dv.Sort = "ChildId,String1";
//get expected results
DataRow[] drExpected = dt.Select("ChildId=3 and String1='3-String1'");
// FindRows - check count
dvArr = dv.FindRows(new object[] { "3", "3-String1" });
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);
}