Exemplo n.º 1
0
        public async Task AddProductToBasketShouldReturn404NotFoundForBasket()
        {
            var basketServiceMock = new Mock <IBasketService>(MockBehavior.Strict);

            basketServiceMock.Setup(service => service.Exists(null)).ReturnsAsync(false);

            var productServiceMock = new Mock <IProductService>(MockBehavior.Strict);

            var controller = new BasketsController(basketServiceMock.Object, productServiceMock.Object);

            var result = await controller.AddProductToBasket(null, 0);

            Assert.IsType <NotFoundObjectResult>(result);

            productServiceMock.VerifyAll();

            basketServiceMock.Verify(service => service.AddProductToBasket(null, 0), Times.Never);
            basketServiceMock.Verify(service => service.Exists(null), Times.Once);
            basketServiceMock.VerifyAll();
        }
Exemplo n.º 2
0
        public async Task AddProductToBasketShouldReturn204NoContent()
        {
            var basketServiceMock = new Mock <IBasketService>(MockBehavior.Strict);

            basketServiceMock.Setup(service => service.AddProductToBasket(null, 0)).Returns(Task.CompletedTask);
            basketServiceMock.Setup(service => service.Exists(null)).ReturnsAsync(true);

            var productServiceMock = new Mock <IProductService>(MockBehavior.Strict);

            productServiceMock.Setup(service => service.Exists(0)).ReturnsAsync(true);

            var controller = new BasketsController(basketServiceMock.Object, productServiceMock.Object);

            var result = await controller.AddProductToBasket(null, 0);

            Assert.IsType <NoContentResult>(result);

            productServiceMock.Verify(service => service.Exists(0), Times.Once);
            productServiceMock.VerifyAll();

            basketServiceMock.Verify(service => service.AddProductToBasket(null, 0), Times.Once);
            basketServiceMock.Verify(service => service.Exists(null), Times.Once);
            basketServiceMock.VerifyAll();
        }