我有这个规则来验证一个属性是否具有有效值,具体取决于另一个属性中的允许值列表。
model.RuleFor(c => c)
.Must(c => string.IsNullOrEmpty(c.CurrentValue) || (!string.IsNullOrEmpty(c.CurrentValue) && c.AllowedValues.Contains(c.CurrentValue)))
这很好,但我想创建一个单元测试,但总是失败。我认为是因为 RuleFor 不是针对特定属性,而是对象本身。
this.validator.ShouldNotHaveValidationErrorFor(c => c.CurrentValue, this.model);
如何改进验证器或测试?