public async Task AddItem_success()
        {
            //arrange
            var          clienteId = "123";
            var          carrinho  = GetCarrinhoClienteFake(clienteId);
            ItemCarrinho input     = new ItemCarrinho("004", "004", "produto 004", 45.67m, 4);
            var          itens     = carrinho.Itens;

            itens.Add(input);
            _carrinhoRepositoryMock
            .Setup(c => c.AddCarrinhoAsync(clienteId, It.IsAny <ItemCarrinho>()))
            .ReturnsAsync(new CarrinhoCliente
            {
                ClienteId = clienteId,
                Itens     = itens
            })
            .Verifiable();

            var controller = new CarrinhoController(
                _carrinhoRepositoryMock.Object,
                _identityServiceMock.Object,
                _serviceBusMock.Object);

            //act
            ActionResult <CarrinhoCliente> actionResult = await controller.AddItem(clienteId, input);

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

            Assert.Equal(4, carrinhoCliente.Itens.Count());
            _carrinhoRepositoryMock.Verify();
            _identityServiceMock.Verify();
            _serviceBusMock.Verify();
        }
        public async Task AddItem_carrinho_invalid_model()
        {
            //arrange
            var          clienteId = "123";
            ItemCarrinho input     = new ItemCarrinho("004", "004", "produto 004", 45.67m, 4);

            _carrinhoRepositoryMock
            .Setup(c => c.AddCarrinhoAsync(clienteId, It.IsAny <ItemCarrinho>()))
            .ThrowsAsync(new KeyNotFoundException());
            var controller = new CarrinhoController(
                _carrinhoRepositoryMock.Object,
                _identityServiceMock.Object,
                _serviceBusMock.Object);

            controller.ModelState.AddModelError("ProdutoId", "Required");

            //act
            ActionResult <CarrinhoCliente> actionResult = await controller.AddItem(clienteId, input);

            //assert
            Assert.IsType <BadRequestObjectResult>(actionResult.Result);
        }
        public async Task AddItem_carrinho_notfound()
        {
            //arrange
            var          clienteId = "123";
            ItemCarrinho input     = new ItemCarrinho("004", "004", "produto 004", 45.67m, 4);

            _carrinhoRepositoryMock
            .Setup(c => c.AddCarrinhoAsync(clienteId, It.IsAny <ItemCarrinho>()))
            .ThrowsAsync(new KeyNotFoundException());
            var controller = new CarrinhoController(
                _carrinhoRepositoryMock.Object,
                _identityServiceMock.Object,
                _serviceBusMock.Object);

            //act
            ActionResult <CarrinhoCliente> actionResult = await controller.AddItem(clienteId, input);

            //assert
            NotFoundObjectResult notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(actionResult.Result);

            Assert.Equal(clienteId, notFoundObjectResult.Value);
        }