public void WhenNoAsyncHandlerRegistereded_ThenInvokesOnThreadPoolAndPersistsToStore() { var command = new FooCommand { Id = 5 }; var handler = new Mock <ICommandHandler <FooCommand> >(); handler.Setup(x => x.IsAsync).Returns(true); var handlerCalled = false; handler.Setup(x => x.Handle(It.IsAny <FooCommand>(), It.IsAny <IDictionary <string, object> >())) .Callback <FooCommand, IDictionary <string, object> >((c, h) => handlerCalled = true); var store = new Mock <IMessageStore <IDomainCommand> >(); var bus = new CommandRegistry <IDomainCommand>(store.Object, new[] { handler.Object }); bus.Execute(command); while (!handlerCalled) { System.Threading.Thread.Sleep(10); } handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >())); store.Verify(x => x.Save(command, It.IsAny <IDictionary <string, object> >())); }
public void WhenAsyncHandlerRegisteredForBaseType_ThenThrowsForExecuteWithDerivedClass() { var command = new FooCommand { Id = 5 }; var handler = Mock.Of <ICommandHandler <BaseCommand> >(); var bus = new CommandRegistry <IDomainCommand>(new[] { handler }, action => action()); Assert.Throws <InvalidOperationException>(() => bus.Execute(command)); }
public void WhenNoStoreSpecifiedAndMatchingHandlerRegistered_ThenExecuteSucceeds() { var command = new FooCommand { Id = 5 }; var handler = Mock.Of <ICommandHandler <FooCommand> >(x => x.IsAsync == true); var bus = new CommandRegistry <IDomainCommand>(new[] { handler }); bus.Execute(command); }
public void WhenHandlerRegisteredForSpecificType_ThenPersistsToStore() { var command = new FooCommand { Id = 5 }; var handler = Mock.Of <ICommandHandler <FooCommand> >(); var store = new Mock <IMessageStore <IDomainCommand> >(); var bus = new CommandRegistry <IDomainCommand>(store.Object, new[] { handler }); bus.Execute(command); store.Verify(x => x.Save(command, It.IsAny <IDictionary <string, object> >())); }
public void WhenHandlerRegisteredForSpecificType_ThenHandlesOnExecute() { var command = new FooCommand { Id = 5 }; var handler = new Mock <CommandHandler <FooCommand> > { CallBase = true }; var bus = new CommandRegistry <IDomainCommand>(new[] { handler.Object }); bus.Execute(command); handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >())); }
public void WhenAsyncHandlerRegisteredForSpecificType_ThenInvokesAsyncRunner() { var command = new FooCommand { Id = 5 }; var handler = new Mock <CommandHandler <FooCommand> > { CallBase = true }; handler.Setup(x => x.IsAsync).Returns(true); var asyncCalled = false; Action <Action> asyncRunner = action => asyncCalled = true; var bus = new CommandRegistry <IDomainCommand>(new[] { handler.Object }, asyncRunner); bus.Execute(command); handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >()), Times.Never()); Assert.True(asyncCalled); }
public void WhenAsyncHandlerRegisteredForSpecificType_ThenCanUseDefaultAsyncRunner() { var command = new FooCommand { Id = 5 }; var handlerCalled = false; var handler = new Mock <ICommandHandler <FooCommand> >(); handler.Setup(x => x.IsAsync).Returns(true); handler.Setup(x => x.Handle(It.IsAny <FooCommand>(), It.IsAny <IDictionary <string, object> >())) .Callback <FooCommand, IDictionary <string, object> >((c, h) => handlerCalled = true); var bus = new CommandRegistry <IDomainCommand>(new[] { handler.Object }); bus.Execute(command); while (!handlerCalled) { System.Threading.Thread.Sleep(10); } handler.Verify(x => x.Handle(command, It.IsAny <IDictionary <string, object> >())); }