What kind of tests should be carried out in unit testing when comparing Datatables that are supposed to be different and have multiple rows.
[TestMethod]
public void ExecuteOutWithMultipleDataTables()
{
//Arrange
int id1 = TestOrderBuilder.New().Build();
DataTable dtDefault = CreateDefaultDataTable(id1, "OUT", "TableDesc", DateTime.Now);
//Act
object[] result = OracleDatabase.ExecuteOut(SqlStatements.Cursor, procedureParameters);
DataTable dtResults = result[0] as DataTable;
//Assert
Assert.IsNotNull(dtDefault);
Assert.IsNotNull(dtResults);
Assert.AreNotEqual(dtDefault, dtResults);
Assert.AreNotSame(dtDefault.Rows[0][0], dtResults.Rows[0][0]);
Assert.AreNotSame(dtDefault.Rows[0][1], dtResults.Rows[0][1]);
}
This is an example of some of what I have wrote already, but I am unsure if I am on the right track.
Does anyone have advice?
Mac
You need to write a helper method if you need to verify each row and column value.
Also , it does not looks like an unit test because it looks you are calling real database rather then mocking it.
may be something like below
private bool IsTableSame(DataTable t1, DataTable t2)
{
if (t1 == null)
return false;
if (t2 == null)
return false;
if (t1.Rows.Count != t2.Rows.Count)
return false;
if (t1.Columns.Count != t2.Columns.Count)
return false;
if (t1.Columns.Cast<DataColumn>().Any(dc => !t2.Columns.Contains(dc.ColumnName)))
{
return false;
}
for (int i = 0; i <= t1.Rows.Count-1; i++)
{
if (t1.Columns.Cast<DataColumn>().Any(dc1 => t1.Rows[i][dc1.ColumnName].ToString() != t2.Rows[i][dc1.ColumnName].ToString()))
{
return false;
}
}
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With