DbContext GetValidationErrors and unit test code coverage

I am not trying unit test EF, but my business logic.

if (_context.GetValidationErrors.Count > 0) { foreach (DbEntityValidationResult validationResult in _context.ValidationErrors) { foreach (DbValidationError error in validationResult.ValidationErrors) { // add ErrorMessage to a list } } } else { _context.SaveChanges(); } 

I use Mock in my unit tests. I can easily make fun of the number of validation errors, but mocking the lists in foreach loops really puzzles me. I would like to be able to mock loops for the sake of code coverage.

+4
source share

All Articles