Skip to content

MemberNameValidatorSelector does not work with property path to child rule after version 11.1.1 #2055

@abramchev

Description

@abramchev

FluentValidation version

11.1.1

ASP.NET version

No response

Summary

I have old working code which uses MemberNameValidatorSelector to validate particular property path from the entity. In any version higher than 11.1.0 code stops working without any messages or exceptions. Error is not generate when expected.
Might be that MemberNameValidatorSelector utilization is not correct from the begging. It's taken from some samples time ago.

Steps to Reproduce

Please, see working dotnetfiddle example https://dotnetfiddle.net/5o03Fy
Simply downgrade FluentValidation version to 11.1.0 to get correct results.
Thanks!

var validator = new RulesetChildValidatorRulesValidator();
var validatorSelector = new MemberNameValidatorSelector(new[] { "Orders.Quantity" });
var person = new Person
{
   Orders = new List<Order>
   {
      new() { Quantity = 0 }
   }
};
var fluentValidationContext =
     new ValidationContext<Person>(
     instanceToValidate: person,
     propertyChain: new PropertyChain(),
     validatorSelector: validatorSelector
);
ValidationResult result = await validator.ValidateAsync(fluentValidationContext);
//ERROR is Expected here

private class RulesetChildValidatorRulesValidator : AbstractValidator<Person> {
    public RulesetChildValidatorRulesValidator() {
        RuleFor(x => x.Surname).NotEmpty();
        RuleForEach(x => x.Orders).ChildRules(x => {
            x.RuleFor(y => y.Quantity).GreaterThan(0);
        });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions