Reputation: 2899
Here is the rule I am trying to test:
RuleFor(m => m.Groups)
.SetValidator(new MustContainAtLeastOne<AuthGroup>())
.OverridePropertyName("Roles");
Test:
validator.ShouldHaveValidationErrorFor(m => m.Groups,new List<AuthGroup>());
Question:
It fails when I have .OverridePropertyName("Roles")
but when I remove it, test passes.
Is this an issue with Fluent Validation Validator class?
Upvotes: 1
Views: 2803
Reputation: 1
It is happening because your property name is Groups but while validating it is getting property name as roles due to OverridePropertyName.
Upvotes: 0
Reputation: 2899
Post a issue on the project site:
https://github.com/JeremySkinner/FluentValidation/issues/359
I believe the TestHelper compares the name of the property specified in the lambda expression to the property name in the generated error message. In this case, because you've overridden the property name they won't match and so the assertion fails. You'll need to perform the assertion manually rather than using the TestHelper in this situation.
Upvotes: 2