예제 #1
0
        public async Task Handle_EventBusThrowsException_ThrowException(
            [Frozen] Mock <IBasketRepository> mockBasketRepository,
            [Frozen] Mock <IEventBus> mockEventBus,
            CheckoutCommandHandler sut,
            CheckoutCommand command,
            CustomerBasket basket
            )
        {
            //Arrange
            mockBasketRepository.Setup(_ => _.GetBasketAsync(
                                           It.IsAny <string>()
                                           ))
            .ReturnsAsync(basket);

            mockEventBus.Setup(_ => _.Publish(It.IsAny <IntegrationEvent>()))
            .Throws <Exception>();

            //Act
            Func <Task> func = async() => await sut.Handle(command, CancellationToken.None);

            //Assert
            await func.Should().ThrowAsync <Exception>();

            mockBasketRepository.Verify(x => x.GetBasketAsync(
                                            It.IsAny <string>()
                                            ));
        }
예제 #2
0
        public async Task Handle_BasketDoesNotExist_ReturnNull(
            [Frozen] Mock <IBasketRepository> mockBasketRepository,
            [Frozen] Mock <IEventBus> mockEventBus,
            CheckoutCommandHandler sut,
            CheckoutCommand command
            )
        {
            //Arrange

            //Act
            var result = await sut.Handle(command, CancellationToken.None);

            //Assert
            result.Should().BeNull();
            mockBasketRepository.Verify(x => x.GetBasketAsync(
                                            It.IsAny <string>()
                                            ));
            mockEventBus.Verify(_ => _.Publish(It.IsAny <IntegrationEvent>()), Times.Never);
        }
예제 #3
0
        public async Task Handle_BasketExists_ReturnBasket(
            [Frozen] Mock <IBasketRepository> mockBasketRepository,
            [Frozen] Mock <IEventBus> mockEventBus,
            CheckoutCommandHandler sut,
            CheckoutCommand command,
            CustomerBasket basket
            )
        {
            //Arrange
            mockBasketRepository.Setup(_ => _.GetBasketAsync(
                                           It.IsAny <string>()
                                           ))
            .ReturnsAsync(basket);

            //Act
            var result = await sut.Handle(command, CancellationToken.None);

            //Assert
            result.Should().BeEquivalentTo(basket);
            mockBasketRepository.Verify(_ => _.GetBasketAsync(
                                            It.IsAny <string>()
                                            ));
            mockEventBus.Verify(_ => _.Publish(It.IsAny <IntegrationEvent>()));
        }