I use fluentvalidation as follows:
public class ProjectValidator : AbstractValidator<Project> { public ProjectValidator() { RuleFor(project => project.Name).NotEmpty().WithMessage("Project name cannot be empty."); } }
in some service:
IValidator<Project> _projectValidator; _projectValidator.ValidateAndThrow(project);
part of the integration test:
var validationException = Assert.Throws<ValidationException>(() => projectRepository.SaveOrUpdate(project)); Assert.That(validationException.Message, Is.EqualTo("Project name cannot be empty."));
This obviously does not work, since a validationException potentially contains many errors. Even if it contains only one error, the line looks like this:
Verification failed: - The project name cannot be empty.
How do you verify that the verification message indicated / indicated the verification message?
Project name cannot be empty.
source share