Using FluentValidation, is it possible to throw an exception on a single rule failure? For example, I would like to call Validate() and for the first rule below to simply validate but the second to throw an exception if false.
RuleFor(x => x.Title)
.NotEmpty()
.WithMessage("Please add a title for the project");
RuleFor(x => x.UserId)
.NotEmpty()
.WithMessage("User not supplied");
I’m probably trying to force FluentValidation to do something it is not designed to do. And I am aware of the ValidateAndThrow() method, but this will throw an exception on any failure.
Yes. Try something along these lines –
Add FluentValidation and FluentValidation.TestHelper to your directives.