规则未设置FluentValidation子验证器

时间:2018-10-05 11:12:20

标签: c# fluentvalidation

我在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));
        }

0 个答案:

没有答案