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

            Action <IConfiguresValueAccessor <ValidatedObject, char> > configAction = c => c.AddRuleWithParent <CharValueRule>();

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

            Mock.Get(valueBuilderFactory)
            .Verify(x => x.GetValueAccessorBuilder <ValidatedObject, char>(ruleContext, configAction), Times.Once);
        }
Beispiel #2
0
        public void ForMemberItemsShouldAddBuilderReturnedFromValueBuilderFactory([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                                  [Frozen] IGetsValidatorBuilderContext ruleContextFactory,
                                                                                  [Frozen] IGetsValueAccessorBuilder valueBuilderFactory,
                                                                                  ValidatorBuilder <ValidatedObject> sut,
                                                                                  [ManifestModel] ValidatorBuilderContext ruleContext,
                                                                                  IBuildsValueAccessor <ValidatedObject, char> valueBuilder,
                                                                                  [ManifestModel] ManifestValue value)
        {
            Mock.Get(ruleContextFactory)
            .Setup(x => x.GetContextForMember(It.IsAny <Expression <Func <ValidatedObject, IEnumerable <char> > > >(), context, false))
            .Returns(ruleContext);
            Mock.Get(ruleContextFactory)
            .Setup(x => x.GetContextForMember <ValidatedObject, char>(null, ruleContext, true))
            .Returns(ruleContext);
            Mock.Get(valueBuilderFactory)
            .Setup(x => x.GetValueAccessorBuilder <ValidatedObject, char>(ruleContext, It.IsAny <Action <IConfiguresValueAccessor <ValidatedObject, char> > >()))
            .Returns(valueBuilder);
            Mock.Get(valueBuilder)
            .Setup(x => x.GetManifestValue())
            .Returns(() => value);

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

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