Thanks for the quick response Remco.
I understand better now why this occurs, but that suggests there might be something else not quite right.
The very next statement after the aforementioned one is:
var fullErrorMessage = string.Join("; ", errorMessages);
And this statement is recognised as fully covered.
The full method shown below, is a private member of a Repository class and it simply wraps a call to the SaveChanges method of an internal DbContext. All the method does is provide a more informative message, when DbEntityValidationException is caught.
private void SaveChanges()
{
try
{
this.context.SaveChanges();
}
catch (DbEntityValidationException exception)
{
var errorMessages = exception.EntityValidationErrors
.SelectMany(x => x.ValidationErrors)
.Select(x => x.ErrorMessage);
var fullErrorMessage = string.Join("; ", errorMessages);
var exceptionMessage = string.Concat(exception.Message, " The validation errors are: ", fullErrorMessage);
throw new DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
}
}
The only two lines that are flagged as not covered are the Select* lines. In this case I can "fix" the coverage stats by restoring it to a single line (the chances of this class being changed again are very small), which will please the people complaining about the total coverage on the solution being below 95%, but it would be interesting to understand more.
Mike