Beispiel #1
0
        public async Task <IActionResult> UpdateQuantity([FromBody] UpdateQuantityInput input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            UpdateQuantityOutput value = await basketService.UpdateItem(GetUserId(), input);

            if (value == null)
            {
                return(NotFound(input));
            }

            return(base.Ok(value));
        }
Beispiel #2
0
        public async Task UpdateItem_success()
        {
            //arrange
            var        customerId = "123";
            var        basket     = GetCustomerBasketFake(customerId);
            BasketItem input      = new BasketItem("004", "004", "produto 004", 45.67m, 4);
            var        items      = basket.Items;

            items.Add(input);
            _basketRepositoryMock
            .Setup(c => c.UpdateBasketAsync(customerId, It.IsAny <UpdateQuantityInput>()))
            .ReturnsAsync(new UpdateQuantityOutput(input,
                                                   new CustomerBasket
            {
                CustomerId = customerId,
                Items      = items
            }))
            .Verifiable();

            var controller = new BasketController(
                _basketRepositoryMock.Object,
                _identityServiceMock.Object,
                _serviceBusMock.Object,
                _loggerMock.Object,
                _configurationMock.Object);

            //act
            ActionResult <UpdateQuantityOutput> actionResult = await controller.UpdateItem(customerId, new UpdateQuantityInput(input.ProductId, input.Quantity));

            //assert
            OkObjectResult       okObjectResult         = Assert.IsType <OkObjectResult>(actionResult.Result);
            UpdateQuantityOutput updateQuantidadeOutput = Assert.IsAssignableFrom <UpdateQuantityOutput>(okObjectResult.Value);

            Assert.Equal(input.ProductId, updateQuantidadeOutput.BasketItem.ProductId);
            _basketRepositoryMock.Verify();
            _identityServiceMock.Verify();
            _serviceBusMock.Verify();
        }