我在FluentPropertyValidator类中具有的规则之一是
RuleFor(p => p.SecurityAddress).SetValidator(new FluentAddressValidator()).When(p => p.CorrespondanceAddressIsSecurityAddress == false);
当FluentAddressValidator
的值为false时,此规则应将类型为p.CorrespondanceAddressIsSecurityAddress
的子验证程序设置为p.SecurityAddress属性。
但是,当我在测试项目中运行以下测试时,该测试失败并显示找不到验证器。
FluentValidation.TestHelper.ValidationTestException : Expected property 'SecurityAddress' to have a child validator of type 'FluentAddressValidator.'. Instead found 'none'
在我看来,这应该起作用,CorrespondanceAddressIsSecurityAddress设置为null,因此应该设置FluentAddressValidator的子验证器。为什么这不起作用?
[Test]
public void FluentPropertyValidatorSetsAddressValidatorForSecurityAddressIfFlagSetToFalse()
{
property = new Property
{
PropertyId = 1,
InstructionId = 1,
ReferenceNumber = 1,
CaseOwner = "JM",
AmountBorrowed = 50000,
Tenure = TenureTypes.Freehold,
Jurisdiction = JurisdictionTypes.EnglandWales,
Funder = FunderTypes.LT,
CorrespondanceAddressIsSecurityAddress = false,
CorrespondanceAddress = correspondanceAddress,
SecurityAddress = securityAddress
};
validator.ShouldHaveChildValidator(p => p.SecurityAddress, typeof(FluentAddressValidator));
}