I\'m using dotCover to analyze code coverage of my unit tests, and I\'m getting some strange results... I have an iterator method for which the coverage is not complete, but the
In addition to your question and the in detail answer, I had the following behaviour.
// less than 100% coverage
public static IEnumerable ForEachYieldDo(this IEnumerable source, Action action)
{
foreach (var x in source)
{
action(x);
yield return x;
}
}
// 100% code coverage
public static IEnumerable ForEachSelectDo(this IEnumerable source, Action action)
{
return source.Select(x =>
{
action(x);
return x;
});
}
Both functions have the same behaviour. The action is only executed, if the item is processed. If the retrieval of the items is stopped, the action is not executed.