public void ForValuesShouldPassConfigurationActionToBuilder([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.GetContextForValue(It.IsAny <Func <ValidatedObject, IEnumerable <char> > >(), context, false)) .Returns(ruleContext); Mock.Get(ruleContextFactory) .Setup(x => x.GetContextForValue <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.ForValues(x => x.AProperty, configAction); Mock.Get(valueBuilderFactory) .Verify(x => x.GetValueAccessorBuilder <ValidatedObject, char>(ruleContext, configAction), Times.Once); }
public void ForValuesShouldAddBuilderReturnedFromValueBuilderFactory([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.GetContextForValue(It.IsAny <Func <ValidatedObject, IEnumerable <char> > >(), context, false)) .Returns(ruleContext); Mock.Get(ruleContextFactory) .Setup(x => x.GetContextForValue <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.ForValues(x => x.AProperty, c => {}); Assert.That(sut.GetManifestValue().Children.Single(), Is.SameAs(value)); }