You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ChildRules will use a RuleSetValidatorSelector with a rule set "*". This will overwrite rule sets to be validated specified in the validation context. This will make the child validator malfunctioned.
Steps to Reproduce
[Fact]publicvoidChildRules_works_with_SetValidator_and_RuleSet(){varvalidator=new RulesetChildValidatorRulesValidator();// If the validator inside a child rule specifies a rule set "b",// the rules inside the rule set "b" should not be used for the validation// if the validation context specified the ruleset "a"varresult= validator.Validate(new Person {Orders=newList<Order>{new Order()}},options => options.IncludeRuleSets("a"));
result.Errors.Count.ShouldEqual(1);
result.Errors[0].PropertyName.ShouldEqual("Surname");// They shouldn't be executed if a different ruleset is chosen.result= validator.Validate(new Person {Orders=newList<Order>{new Order()}},options => options.IncludeRuleSets("other"));
result.Errors.Count.ShouldEqual(0);}privateclassRulesetChildValidatorRulesValidator:AbstractValidator<Person>{publicRulesetChildValidatorRulesValidator(){
RuleSet("a, b",()=>{ RuleFor(x => x.Surname).NotEmpty(); RuleFor(x => x).ChildRules(child =>{ child.RuleForEach(o => o.Orders).SetValidator(new RulesetOrderValidator());});});}privateclassRulesetOrderValidator:AbstractValidator<Order>{publicRulesetOrderValidator(){
RuleSet("b",()=>{ RuleFor(o => o.ProductName).NotEmpty();});}}}
The text was updated successfully, but these errors were encountered:
Thanks - good catch. I think your fix in #1982 is correct although I need to test some other scenarios. Once I've done this I'll push out a new release.
FluentValidation version
Any older than 9.4
ASP.NET version
No response
Summary
The ChildRules will use a RuleSetValidatorSelector with a rule set "*". This will overwrite rule sets to be validated specified in the validation context. This will make the child validator malfunctioned.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: