Пример #1
0
        public void GetValidatorFromManifestModelShouldReturnValidatorUsingManifestCreatedFromModelWrappedInThrowingBehaviour([Frozen, AutofixtureServices] IServiceProvider serviceProvider,
                                                                                                                              [Frozen] IGetsBaseValidator baseValidatorFactory,
                                                                                                                              [Frozen] IWrapsValidatorWithExceptionBehaviour exceptionBehaviourWrapper,
                                                                                                                              [Frozen] IWrapsValidatorWithMessageSupport messageWrapper,
                                                                                                                              [Frozen] IGetsValidationManifestFromModel manifestFromModelProvider,
                                                                                                                              ValidatorFactory sut,
                                                                                                                              [ManifestModel] Value manifestModel,
                                                                                                                              Type validatedType,
                                                                                                                              [ManifestModel] ValidationManifest manifest,
                                                                                                                              IValidator baseValidator)
        {
            var expectedValidatorMock = new Mock <IValidator <ValidatedObject> >();
            var expectedValidator     = expectedValidatorMock.As <IValidator>().Object;
            var messageValidatorMock  = new Mock <IValidator <ValidatedObject> >();
            var messageValidator      = messageValidatorMock.As <IValidator>().Object;

            Mock.Get(manifestFromModelProvider).Setup(x => x.GetValidationManifest(manifestModel, validatedType)).Returns(manifest);
            Mock.Get(baseValidatorFactory).Setup(x => x.GetValidator(manifest)).Returns(baseValidator);
            Mock.Get(messageWrapper).Setup(x => x.GetValidatorWithMessageSupport(baseValidator)).Returns(messageValidator);
            Mock.Get(exceptionBehaviourWrapper).Setup(x => x.WrapValidator(messageValidator)).Returns(expectedValidator);

            Assert.That(() => sut.GetValidator(manifestModel, validatedType), Is.SameAs(expectedValidator));
        }
Пример #2
0
        public void GetValidatorFromBuilderShouldReturnValidatorUsingBaseValidatorWrappedInThrowingBehaviour([Frozen, AutofixtureServices] IServiceProvider serviceProvider,
                                                                                                             [Frozen] IGetsBaseValidator baseValidatorFactory,
                                                                                                             [Frozen] IWrapsValidatorWithExceptionBehaviour exceptionBehaviourWrapper,
                                                                                                             [Frozen] IWrapsValidatorWithMessageSupport messageWrapper,
                                                                                                             ValidatorFactory sut,
                                                                                                             ValidatedObjectValidator builder,
                                                                                                             IValidator <ValidatedObject> baseValidator)
        {
            var expectedValidatorMock = new Mock <IValidator <ValidatedObject> >();

            expectedValidatorMock.As <IValidator>();
            var expectedValidator    = expectedValidatorMock.Object;
            var messageValidatorMock = new Mock <IValidator <ValidatedObject> >();

            messageValidatorMock.As <IValidator>();
            var messageValidator = messageValidatorMock.Object;

            Mock.Get(baseValidatorFactory).Setup(x => x.GetValidator(builder)).Returns(baseValidator);
            Mock.Get(messageWrapper).Setup(x => x.GetValidatorWithMessageSupport(baseValidator)).Returns(messageValidator);
            Mock.Get(exceptionBehaviourWrapper).Setup(x => x.WrapValidator(messageValidator)).Returns(expectedValidator);

            Assert.That(() => sut.GetValidator(builder), Is.SameAs(expectedValidator));
        }