public void executing_message_handler_without_registering_should_throw_an_exception() { var executor = new MessageHandlerExecutor(new PoorMansDependencyInjection()); Func <Task> action = () => executor.Execute(new AppleCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); action.ShouldThrow <TypeAccessException>(); }
public void executing_message_handler_without_registering_should_throw_an_exception() { var serviceProvider = new ServiceCollection() .BuildServiceProvider(); var executor = new MessageHandlerExecutor(new MicrosoftDependencyInjectionDependencyResolver(serviceProvider)); Func <Task> action = () => executor.Execute(new AppleCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); action.ShouldThrow <TypeAccessException>(); }
public void register_message_handler_as_an_indirect_implementation_should_resolve_and_execute() { var dependencyInjection = new PoorMansDependencyInjection(); dependencyInjection.AddMessageHandler(() => new BananaCommandHandler()); var executor = new MessageHandlerExecutor(dependencyInjection); var task = executor.Execute(new BananaCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); task.IsCompleted.Should().BeTrue(); }
public void register_message_handler_as_an_indirect_implementation_should_resolve_and_execute() { var serviceProvider = new ServiceCollection() .AddScoped <IMessageHandler <BananaCommand>, BananaCommandHandler>() .BuildServiceProvider(); var executor = new MessageHandlerExecutor(new MicrosoftDependencyInjectionDependencyResolver(serviceProvider)); var task = executor.Execute(new BananaCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); task.IsCompleted.Should().BeTrue(); }
public void thrown_exception_in_message_handler_should_call_exception_handler_and_throw() { Exception exception = null; Func <MessageHandlingExceptionRaisedEventArgs, Task> exceptionHandler = a => { exception = a.Exception; return(Task.CompletedTask); }; var dependencyInjection = new PoorMansDependencyInjection(); dependencyInjection.AddMessageHandler(() => new RottenAppleCommandHandler()); var executor = new MessageHandlerExecutor(dependencyInjection, exceptionHandler); Func <Task> action = () => executor.Execute(new AppleCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); action.ShouldThrow <Exception>(); exception.Message.Should().Be("Rotten Apple"); }
public void thrown_exception_in_message_handler_should_call_exception_handler_and_throw() { Exception exception = null; Func <MessageHandlingExceptionRaisedEventArgs, Task> exceptionHandler = a => { exception = a.Exception; return(Task.CompletedTask); }; var serviceProvider = new ServiceCollection() .AddScoped <IMessageHandler <AppleCommand>, RottenAppleCommandHandler>() .BuildServiceProvider(); var executor = new MessageHandlerExecutor(new MicrosoftDependencyInjectionDependencyResolver(serviceProvider), exceptionHandler); Func <Task> action = () => executor.Execute(new AppleCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); action.ShouldThrow <Exception>(); exception.Message.Should().Be("Rotten Apple"); }
protected void when_handling_message() => action = () => messageHandlerExecutor.Execute(new AppleCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken());
void when_executing_handler() { action = () => executor.Execute(new AppleCommand(), Substitute.For <IMessageContext>(), new System.Threading.CancellationToken()); }