I have a block of code like this (class/property names have been changed to meet company guidelines):
if (output.ExecutionStatus == RuleExecutionStatus.Success &&
!obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id))
{
obj.AddConcreteType(output.ConcreteObj);
}
Before adding && !obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id)
this line was 100% covered. I added one test, called Test 2
down below.
So, after adding the new test, this block is almost 100% covered; but I can't figure out what isn't getting covered. It states 1
block is not covered. The tests executing now have the following attributes:
0
in ListOfObjs
, no match, adds successfully.2
in ListOfObjs
, 1
matches on Id
, does not add.What I've Tried
ListOfObjs
, no match, adds successfully. I thought maybe the issue was surrounding the fact that it didn't cover the Any
case where 0
matched.
It sounds like you haven't got a test where the execution status isn't success - in other words, the first operand of your &&
expression is true
for all tests, so you're not checking that it's relevant.
(In general, if you can remove some of your production code without any of your tests breaking, that's a bad sign - or it's a sign that it was non-functional, e.g. an optimization.)
See more on this question at Stackoverflow