public void Validation_command_attributes_should_generate_exception_for_bad_command() { // Arrange pipelineService.ServiceProvider = new FuncServiceProvider(Ns01_InterfacesResolver); pipelineService.PipelineContainer.AddCommandPipeline() .AddMiddleware(new Commands.PipelineMiddlewares.CommandValidationMiddleware()) .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerLocatorMiddleware( typeof(CommandsTests).GetTypeInfo().Assembly)) .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerExecutorMiddleware() { UseParametersResolve = true }); var cmd = new Ns08_CommandWithValidation { PercentInt = -10, Name = string.Empty, }; // Act & assert Assert.Throws <Domain.Exceptions.ValidationException>(() => { pipelineService.HandleCommand(cmd); }); Assert.NotEqual(10, cmd.PercentInt); cmd.PercentInt = 20; cmd.Name = "Mr Robot"; pipelineService.HandleCommand(cmd); Assert.Equal(10, cmd.PercentInt); }
public void Validation_command_attributes_should_not_generate_exception_for_good_command() { // Arrange pipelineService.PipelineContainer.AddCommandPipeline() .AddMiddleware(new Commands.PipelineMiddlewares.CommandValidationMiddleware()) .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerLocatorMiddleware( typeof(CommandsTests).GetTypeInfo().Assembly)) .AddMiddleware(new Commands.PipelineMiddlewares.CommandHandlerExecutorMiddleware { UseParametersResolve = true }); var cmd = new Ns08_CommandWithValidation { PercentInt = 20, Name = "Mr Robot", }; // Act pipelineService.HandleCommand(cmd); // Assert Assert.Equal(10, cmd.PercentInt); }