public async void DispatchAsync_BuildGenericCommandHandlerAndGetFromContainer_ShouldHandleCommandOnANewThread(
            [Frozen] Mock<IContainer> container,
            [Frozen] Mock<ICommandHandler<FakeCommand>> commandHandler,
            FakeCommand command,
            CommandDispatcher dispatcher)
        {
            // Arrange

            var genericTypeName = typeof (ICommandHandler<FakeCommand>).FullName;

            container.Setup(c => c.GetInstance(It.Is<Type>(t => t.FullName == genericTypeName)))
                     .Returns(commandHandler.Object);

            // Act

            await dispatcher.DispatchAsync(command);

            // Assert

            commandHandler.Verify(t => t.Handle(command), Times.Once);
        }
        public async void DispatchAsync_CommandThrowsActivationException_ShouldThrowCommandHandlerNotFoundException(
            [Frozen] Mock<IContainer> container,
            [Frozen] Mock<ICommandHandler<ICommand>> commandHandler,
            FakeCommand command,
            CommandDispatcher dispatcher)
        {
            // Arrange

            commandHandler.Setup(h => h.Handle(It.IsAny<FakeCommand>())).Throws<Exception>();

            container.Setup(c => c.GetInstance(It.IsAny<Type>())).Throws<Exception>();

            container.Setup(c => c.IsActivationException(It.IsAny<Exception>())).Returns(true);

            // Act and assert

            await Assert.ThrowsAsync<CommandHandlerNotFoundException>(() => dispatcher.DispatchAsync(command));
        }
 public async void DispatchAsync_NullCommand_ThrowsArgumentNullException(CommandDispatcher dispatcher)
 {
     await Assert.ThrowsAsync<ArgumentNullException>(() => dispatcher.DispatchAsync(null));
 }
        public async void DispatchAsync_CommandThrowsGenericException_ShouldJustRethrow(
            [Frozen] Mock<IContainer> container,
            [Frozen] Mock<ICommandHandler<ICommand>> commandHandler,
            FakeCommand command,
            CommandDispatcher dispatcher)
        {
            // Arrange

            commandHandler.Setup(h => h.Handle(It.IsAny<FakeCommand>())).Throws<Exception>();

            var genericTypeName = typeof(ICommandHandler<FakeCommand>).FullName;

            container.Setup(c => c.GetInstance(It.Is<Type>(t => t.FullName == genericTypeName)))
                     .Returns(commandHandler.Object);

            // Act

            await Assert.ThrowsAsync<Exception>(() => dispatcher.DispatchAsync(command));

            // Assert

            commandHandler.Verify(t => t.Handle(It.IsAny<ICommand>()), Times.Once);
        }