流利的验证单元测试

Fluent Validation Unit Testing

这是我要测试的规则:

 RuleFor(m => m.Groups)
      .SetValidator(new MustContainAtLeastOne<AuthGroup>())
      .OverridePropertyName("Roles");

测试:

validator.ShouldHaveValidationErrorFor(m => m.Groups,new List<AuthGroup>());

问题:

当我有 .OverridePropertyName("Roles") 时它失败了,但是当我删除它时,测试通过了。

这是 Fluent Validation Validator class 的问题吗?

Post 项目站点上的一个问题:

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.