0
votes

I have a validator with two RuleSets. The first RuleSet has 4 rules and the second has 2 rules. When I call Validate with each RuleSet individually, I get the correct number of errors (4 and 2) but when I call them together, I get NO errors... For the life of me, I can't figure out why - any help appreciated!

(Note: In all cases, the 6 properties being tested are set to null...)

Validator:

public class ClientValidator : AbstractValidator<Client> {
    public ClientValidator() {
        RuleSet("RequiredHomeValidations", () => {
            RuleFor(client => client.Street)
                .NotEmpty()
                .WithMessage("Client's street address is required.");
            RuleFor(client => client.City)
                .NotEmpty()
                .WithMessage("Client's city is required.");
            RuleFor(client => client.State)
                .NotEmpty()
                .WithMessage("Client's state is required.");
            RuleFor(client => client.ZipCode)
                .NotEmpty()
                .WithMessage("Client's ZIP Code is required.");
        });

        RuleSet("RequiredContactsValidations", () => {
            RuleFor(client => client.PrimaryContactFirstName)
                .NotEmpty()
                .WithMessage("First name of client's primary contact is required.");
            RuleFor(client => client.PrimaryContactLastName)
                .NotEmpty()
                .WithMessage("Last name of client's primary contact is required.");
        });

Calls to Validate:

        //ValidationResult requiredFieldsValidationResult = this.ClientValidator.Validate(client, ruleSet: "RequiredHomeValidations");  <-- 4 ERRORS
        //ValidationResult requiredFieldsValidationResult = this.ClientValidator.Validate(client, ruleSet: "RequiredContactsValidations");  <-- 2 ERRORS
        ValidationResult requiredFieldsValidationResult = this.ClientValidator.Validate(client, ruleSet: "RequiredHomeValidations, RequiredContactsValidations");  <-- 0 ERRORS, .IsValid == true
1

1 Answers

1
votes

This was due to ServiceStack's interned version of FluentValidation being based on an earlier version that didn't support multiple result sets.

This should now be resolved in the latest v4.0.41+ of ServiceStack that's now available on MyGet.