Beispiel #1
0
        public void GetManifestRulesShouldIterateOverEveryRuleAdded([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                    [Frozen] IGetsValidatorBuilderContext ruleContextFactory,
                                                                    [Frozen] IGetsRuleBuilder ruleBuilderFactory,
                                                                    ValidatorBuilder <ValidatedObject> sut,
                                                                    [ManifestModel] ManifestValue value)
        {
            Mock.Get(ruleBuilderFactory)
            .Setup(x => x.GetRuleBuilder <ObjectRule>(It.IsAny <ValidatorBuilderContext>(), It.IsAny <Action <IConfiguresRule <ObjectRule> > >()))
            .Returns(() => {
                var ruleBuilder = new Mock <IBuildsRule <ObjectRule> >();
                ruleBuilder
                .Setup(x => x.GetManifestValue())
                .Returns(() => value);
                return(ruleBuilder.Object);
            });

            sut.AddRule <ObjectRule>();
            sut.AddRule <ObjectRule>();

            sut.GetManifestValue();

            Mock.Get(ruleBuilderFactory)
            .Verify(x => x.GetRuleBuilder <ObjectRule>(context, It.IsAny <Action <IConfiguresRule <ObjectRule> > >()),
                    Times.Exactly(2));
        }
Beispiel #2
0
        public void AddRuleShouldAddRuleCreatedFromFactoryUsingContext([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                       [Frozen] IGetsValidatorBuilderContext ruleContextFactory,
                                                                       [Frozen] IGetsRuleBuilder ruleBuilderFactory,
                                                                       IBuildsRule <ObjectRule> ruleBuilder,
                                                                       ValidatorBuilder <ValidatedObject> sut,
                                                                       [ManifestModel] ManifestValue value)
        {
            Mock.Get(ruleBuilderFactory)
            .Setup(x => x.GetRuleBuilder <ObjectRule>(context, It.IsAny <Action <IConfiguresRule <ObjectRule> > >()))
            .Returns(ruleBuilder);
            Mock.Get(ruleBuilder)
            .Setup(x => x.GetManifestValue())
            .Returns(() => value);

            sut.AddRule <ObjectRule>();

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