简体   繁体   English

流利的验证单元测试

[英]Fluent Validation Unit Testing

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. 当我有.OverridePropertyName("Roles")时,它将失败,但是当我删除它时,测试通过了。

Is this an issue with Fluent Validation Validator class? 这是Fluent Validation Validator类的问题吗?

Post a issue on the project site: 在项目站点上发布问题:

https://github.com/JeremySkinner/FluentValidation/issues/359 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. 我相信TestHelper会将lambda表达式中指定的属性名称与生成的错误消息中的属性名称进行比较。 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. 在这种情况下,您需要手动执行断言,而不是使用TestHelper。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM