Esempio n. 1
0
        public void ForMemberShouldPassConfigurationActionToBuilder([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                    [Frozen] IGetsValidatorBuilderContext ruleContextFactory,
                                                                    [Frozen] IGetsValueAccessorBuilder valueBuilderFactory,
                                                                    ValidatorBuilder <ValidatedObject> sut,
                                                                    [ManifestModel] ValidatorBuilderContext ruleContext,
                                                                    IBuildsValueAccessor <ValidatedObject, string> valueBuilder,
                                                                    [ManifestModel] ManifestValue value)
        {
            Mock.Get(ruleContextFactory)
            .Setup(x => x.GetContextForMember(It.IsAny <Expression <Func <ValidatedObject, string> > >(), context, false))
            .Returns(ruleContext);
            Mock.Get(valueBuilderFactory)
            .Setup(x => x.GetValueAccessorBuilder <ValidatedObject, string>(ruleContext, It.IsAny <Action <IConfiguresValueAccessor <ValidatedObject, string> > >()))
            .Returns(valueBuilder);
            Mock.Get(valueBuilder)
            .Setup(x => x.GetManifestValue())
            .Returns(() => value);

            Action <IConfiguresValueAccessor <ValidatedObject, string> > configAction = c => c.AddRuleWithParent <StringValueRule>();

            sut.ForMember(x => x.AProperty, configAction);

            Mock.Get(valueBuilderFactory)
            .Verify(x => x.GetValueAccessorBuilder <ValidatedObject, string>(ruleContext, configAction), Times.Once);
        }
Esempio n. 2
0
 public void ForMemberShouldThrowIfValidateAsAncestorHasAlreadyBeenUsed([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                        ValidatorBuilder <ValidatedObject> sut,
                                                                        [ManifestModel] ManifestValue parent)
 {
     context.ManifestValue.Parent = parent;
     sut.ValidateAsAncestor(1);
     Assert.That(() => sut.ForMember(x => x.AProperty, v => { }), Throws.InvalidOperationException);
 }
Esempio n. 3
0
        public void ValidateAsAncestorShouldThrowIfForMemberHasAlreadyBeenUsed([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                               [Frozen] IGetsValidatorBuilderContext ruleContextFactory,
                                                                               [Frozen] IGetsValueAccessorBuilder valueBuilderFactory,
                                                                               ValidatorBuilder <ValidatedObject> sut,
                                                                               ValidatorBuilderContext ruleContext,
                                                                               IBuildsValueAccessor <ValidatedObject, string> valueBuilder,
                                                                               [ManifestModel] ManifestValue value)
        {
            Mock.Get(ruleContextFactory)
            .Setup(x => x.GetContextForMember(It.IsAny <Expression <Func <ValidatedObject, string> > >(), context, false))
            .Returns(ruleContext);
            Mock.Get(valueBuilderFactory)
            .Setup(x => x.GetValueAccessorBuilder <ValidatedObject, string>(ruleContext, It.IsAny <Action <IConfiguresValueAccessor <ValidatedObject, string> > >()))
            .Returns(valueBuilder);
            Mock.Get(valueBuilder)
            .Setup(x => x.GetManifestValue())
            .Returns(() => value);

            sut.ForMember(x => x.AProperty, v => { });
            Assert.That(() => sut.ValidateAsAncestor(1), Throws.InvalidOperationException);
        }
Esempio n. 4
0
        public void ForMemberShouldAddBuilderReturnedFromValueBuilderFactory([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                             [Frozen] IGetsValidatorBuilderContext ruleContextFactory,
                                                                             [Frozen] IGetsValueAccessorBuilder valueBuilderFactory,
                                                                             ValidatorBuilder <ValidatedObject> sut,
                                                                             ValidatorBuilderContext ruleContext,
                                                                             IBuildsValueAccessor <ValidatedObject, string> valueBuilder,
                                                                             [ManifestModel] ManifestValue value)
        {
            Mock.Get(ruleContextFactory)
            .Setup(x => x.GetContextForMember(It.IsAny <Expression <Func <ValidatedObject, string> > >(), context, false))
            .Returns(ruleContext);
            Mock.Get(valueBuilderFactory)
            .Setup(x => x.GetValueAccessorBuilder <ValidatedObject, string>(ruleContext, It.IsAny <Action <IConfiguresValueAccessor <ValidatedObject, string> > >()))
            .Returns(valueBuilder);
            Mock.Get(valueBuilder)
            .Setup(x => x.GetManifestValue())
            .Returns(() => value);

            sut.ForMember(x => x.AProperty, c => {});

            Assert.That(sut.GetManifestValue().Children.Single(), Is.SameAs(value));
        }