我试图根据属性值对设置子验证器的能力进行单元测试。
RuleFor(x => x.Property2)
.SetValidator(new Property2Validator())
.When(x => x.Property1 == 1);
在我的单元测试中,我有以下断言
validatorUnderTest.ShouldHaveChildValidator(x => x.Property2, typeof(Property2Validator));
然而,这总是失败,因为验证器仅在验证发生时附加。如果我删除'何时'它条款很好。