We're using VS2012 Ultimate (thanks BizSpark!) and we've started to get into integration testing to ensure our Dapper queries are working with the DB in the loop. I'm trying to ensure 100% code coverage for all the database related classes.
In one of our classs, code coverage report from tests for our AddDelay()
function is showing that the lines declaring and initialising the data anonymous object aren't covered, however it must be for the Execute to work. There's a mock object being passed in and everything seems to be working but I can't figure out why the code coverage isn't 100% for that method.
Any suggestions as to why the report is showing it's not covered given it's a super simple function, and the data
object is passed to the execute function as a parameter?
public bool AddDelay(DelayInformationModel delay)
{
const string sql = @"INSERT INTO EquipmentDelay(EquipmentID, DelayID, StartTime, EndTime, Actual, Comment) VALUES (@EquipmentID, @DelayID, @StartTime, @EndTime, @Actual, @Comment)";
using (IDbConnection con = DataFactory.CreateOpenConnection())
{
var data = new
{
EquipmentID = delay.EquipmentID,
DelayID = delay.DelayCode,
StartTime = delay.StartTime,
EndTime = delay.EndTime,
Actual = delay.Actual,
Comment = (delay.Comment ?? "")
};
con.Execute(sql, data);
return true;
}
}
I think problem with
Comment = (delay.Comment ?? "")
delay.Comment is not null so this check will never execute. Use temp variable and get value in it
something like this
var a= delay.Comment;
var data = new
{
EquipmentID = delay.EquipmentID,
DelayID = delay.DelayCode,
StartTime = delay.StartTime,
EndTime = delay.EndTime,
Actual = delay.Actual,
Comment = a ?? ""
};