public void forward_command_to_handler() { var command = new FooCommand(); var venga = new Venga(); venga.RegisterHandler(new FooHandler()); venga.Handle(command); Assert.True(command.WasHandled); }
public void throw_if_no_handler_registered_for_command() { var venga = new Venga(); var command = new FooCommand(); var exception = Record.Exception(() => venga.Handle(command)); Assert.NotNull(exception); Assert.IsType <UnhandledCommandException>(exception); Assert.Equal("No handler registered for FooCommand", exception.Message); }
public void forward_same_command_to_multiple_different_handlers() { var venga = new Venga(); var command = new FooCommand(); var aFooHandler = new FooHandler(); var anotherFooHandler = new OtherFooHandler(); venga.RegisterHandler(aFooHandler); venga.RegisterHandler(anotherFooHandler); venga.Handle(command); Assert.True(command.WasHandledBy.Any(handler => handler is FooHandler)); Assert.True(command.WasHandledBy.Any(handler => handler is OtherFooHandler)); }
public void forward_command_to_composite_handler() { var barCommand = new BarCommand(); var venga = new Venga(); var handlers = new List <HandleCommand <BarCommand> > { new BarHandler(), new FakeLoggingBarHandler() }; var compositeHandler = new CompositeHandler(handlers); venga.RegisterHandler(compositeHandler); venga.Handle(barCommand); Assert.True(barCommand.WasHandled); Assert.True(barCommand.WasLogged); }