Beispiel #1
0
        public void ValidateAsyncShouldReturnTheWrappedValidatorResultIfOptionsDisableMessageGeneration([Frozen] IValidator <object> validator,
                                                                                                        [Frozen] IAddsFailureMessagesToResult failureMessageEnricher,
                                                                                                        MessageEnrichingValidatorDecorator <object> sut,
                                                                                                        [RuleResult] ValidationResult <object> originalResult,
                                                                                                        [RuleResult] ValidationResult <object> resultWithMessages,
                                                                                                        object validatedObject,
                                                                                                        ValidationOptions options)
        {
            options.EnableMessageGeneration = false;
            Mock.Get(validator).Setup(x => x.ValidateAsync(validatedObject, options, default)).Returns(Task.FromResult <IQueryableValidationResult <object> >(originalResult));

            Assert.That(async() => await sut.ValidateAsync(validatedObject, options), Is.SameAs(originalResult));
            Mock.Get(failureMessageEnricher).Verify(x => x.GetResultWithMessagesAsync <object>(It.IsAny <IQueryableValidationResult <object> >(), It.IsAny <CancellationToken>()), Times.Never);
        }
Beispiel #2
0
 public void ValidateAsyncShouldReturnTheWrappedValidatorResultIfOptionsAreOmitted([Frozen] IValidator <object> validator,
                                                                                   [Frozen] IAddsFailureMessagesToResult failureMessageEnricher,
                                                                                   MessageEnrichingValidatorDecorator <object> sut,
                                                                                   [RuleResult] ValidationResult <object> originalResult,
                                                                                   [RuleResult] ValidationResult <object> resultWithMessages,
                                                                                   object validatedObject)
 {
     Mock.Get(validator).Setup(x => x.ValidateAsync(validatedObject, default, default)).Returns(Task.FromResult <IQueryableValidationResult <object> >(originalResult));
Beispiel #3
0
        public void ValidateAsyncShouldUseTheWrappedValidatorThenReturnTheResultEnrichedWithMessagesIfOptionsEnableIt([Frozen] IValidator <object> validator,
                                                                                                                      [Frozen] IAddsFailureMessagesToResult failureMessageEnricher,
                                                                                                                      MessageEnrichingValidatorDecorator <object> sut,
                                                                                                                      [RuleResult] ValidationResult <object> originalResult,
                                                                                                                      [RuleResult] ValidationResult <object> resultWithMessages,
                                                                                                                      object validatedObject,
                                                                                                                      ValidationOptions options)
        {
            options.EnableMessageGeneration = true;
            Mock.Get(validator).Setup(x => x.ValidateAsync(validatedObject, options, default)).Returns(Task.FromResult <IQueryableValidationResult <object> >(originalResult));
            Mock.Get(failureMessageEnricher).Setup(x => x.GetResultWithMessagesAsync(originalResult, default)).Returns(Task.FromResult <IQueryableValidationResult <object> >(resultWithMessages));

            Assert.That(async() => await sut.ValidateAsync(validatedObject, options), Is.SameAs(resultWithMessages));
        }