public async Task Should_pass_happy_path_when_request_valid(OnFailureBehavior behavior)
        {
            var commandProcessor = new CommandProcessor(ResolverAccessor, cfg =>
            {
                cfg.UseFluentValidation(behavior);
            });

            var queryService = new QueryService(ResolverAccessor, cfg =>
            {
                cfg.UseFluentValidation(behavior);
            });

            switch (behavior)
            {
            case OnFailureBehavior.ThrowException:

                Assert.DoesNotThrowAsync(() => commandProcessor.ProcessAsync(new TestCommand("some")));
                Assert.DoesNotThrowAsync(() => queryService.QueryAsync(new TestQuery("some")));

                break;

            case OnFailureBehavior.ReturnEither:
                var(commandResult, commandValidationState) =
                    await commandProcessor.ProcessAsync(new TestCommandWithEitherResult("some"));

                var(queryResult, queryValidationState) =
                    await queryService.QueryAsync(new TestQueryWithEitherResult("some"));

                Assert.IsTrue(commandValidationState.IsValid);
                Assert.IsTrue(queryValidationState.IsValid);
                Assert.IsNotEmpty(commandResult);
                Assert.IsNotEmpty(queryResult);

                break;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Configure queries validation
 /// </summary>
 /// <param name="configurator">Pipeline configurator</param>
 /// <param name="behavior">Behavior on failure</param>
 public static void UseFluentValidation(
     this IPipeConfigurator <IQueryHandlingContext> configurator,
     OnFailureBehavior behavior)
 {
     configurator.AddPipeSpecification(new ValidationSpecification(behavior));
 }
 public ValidationSpecification(OnFailureBehavior behavior)
 {
     _behavior = behavior;
 }
Beispiel #4
0
 public CommandValidationFilter(OnFailureBehavior behavior)
 {
     _behavior = behavior;
 }
 public QueryValidationFilter(OnFailureBehavior behavior)
 {
     _behavior = behavior;
 }