public void Handle_Success_ShouldDispatchEventAfterCommandHandled( [Frozen] Mock<ICommandHandler<ICommandThatSubscribesToEvents>> commandHandler, [Frozen] Mock<IApplicationEventDispatcher> eventDispatcher, ICommandThatSubscribesToEvents command, ApplicationEventDispatcherDecorator<ICommandThatSubscribesToEvents> decorator) { // Arrange and assert var callOrder = 0; commandHandler.Setup(d => d.Handle(command)).Callback(() => callOrder++.Should().Be(0)); eventDispatcher.Setup(d => d.Dispatch(command)).Callback(() => callOrder++.Should().Be(1)); // Act decorator.Handle(command); }
public void Handle_Exception_ShouldNotDispatchEvent( [Frozen] Mock<ICommandHandler<ICommandThatSubscribesToEvents>> commandHandler, [Frozen] Mock<IApplicationEventDispatcher> eventDispatcher, ICommandThatSubscribesToEvents command, ApplicationEventDispatcherDecorator<ICommandThatSubscribesToEvents> decorator) { // Arrange commandHandler.Setup(d => d.Handle(It.IsAny<ICommandThatSubscribesToEvents>())).Throws<Exception>(); // Act Assert.Throws<Exception>(() => decorator.Handle(command)); // Assert eventDispatcher.Verify(d => d.Dispatch(It.IsAny<ICommandThatSubscribesToEvents>()), Times.Never); }