public void when_execute_command_throws_then_rethrows_original_exception() { var command = new Command(); var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x => x.GetExtensions <ICommandHandler <Command> >() == new[] { new ThrowingCommandHandler() })); var ex = Assert.Throws <InvalidOperationException>(() => bus.Execute((ICommand)command)); Assert.Equal("Invalid", ex.Message); }
public void when_executing_non_public_command_handler_then_invokes_handler_with_result() { var handler = new NonPublicCommandHandlerWithResults(new Result()); var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x => x.GetExtensions <ICommandHandler <CommandWithResults, IEnumerable <Result> > >() == new[] { handler })); var results = bus.Execute(new CommandWithResults()); Assert.Equal(1, results.Count()); }
public void when_executing_command_as_explicit_ICommand_then_invokes_handler() { var handler = new Mock <ICommandHandler <Command> >(); var command = new Command(); var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x => x.GetExtensions <ICommandHandler <Command> >() == new[] { handler.Object })); bus.Execute((ICommand)command); handler.Verify(x => x.Execute(command)); }
public void when_executing_sync_command_then_invokes_sync_handler_with_result() { var handler = new Mock <ICommandHandler <CommandWithResult, Result> >(); var command = new CommandWithResult(); var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x => x.GetExtensions <ICommandHandler <CommandWithResult, Result> >() == new[] { handler.Object })); bus.Execute(command); handler.Verify(x => x.Execute(command)); }
public void when_executing_sync_command_with_result_then_invokes_sync_handler_with_result() { var handler = new Mock <ICommandHandler <CommandWithResult, Result> >(); var command = new CommandWithResult(); var expected = new Result(); handler.Setup(x => x.Execute(command)).Returns(expected); var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x => x.GetExtensions <ICommandHandler <CommandWithResult, Result> >() == new[] { handler.Object })); var result = bus.Execute(command); Assert.Same(expected, result); }
public void when_executing_command_with_result_without_handler_then_throws() { var bus = new CommandBusComponent(Mock.Of <IComponentModel>()); Assert.Throws <NotSupportedException> (() => bus.Execute <Result> (new CommandWithResult())); }