public async Task Get_carrinho_cliente_carrinho_not_found() { //arrange string clienteId = "123"; CarrinhoCliente carrinhoFake = GetCarrinhoClienteFake(clienteId); _carrinhoRepositoryMock .Setup(r => r.GetCarrinhoAsync(clienteId)) .ReturnsAsync((CarrinhoCliente)null) .Verifiable(); var controller = new CarrinhoController(_carrinhoRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); //act IActionResult actionResult = await controller.Get(clienteId); //assert OkObjectResult okObjectResult = Assert.IsType <OkObjectResult>(actionResult); CarrinhoCliente carrinhoCliente = Assert.IsAssignableFrom <CarrinhoCliente>(okObjectResult.Value); Assert.Equal(clienteId, carrinhoCliente.ClienteId); _carrinhoRepositoryMock.Verify(); }
public async Task Get_carrinho_cliente_sucesso() { //Arrange var fakeClienteId = "1"; var carrinhoFake = GetCarrinhoClienteFake(fakeClienteId); _carrinhoRepositoryMock .Setup(x => x.GetCarrinhoAsync(It.IsAny <string>())) .Returns(Task.FromResult(carrinhoFake)) .Verifiable(); _identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeClienteId); _serviceBusMock.Setup(x => x.Publish(It.IsAny <CheckoutEvent>(), null)); //Act var carrinhoController = new CarrinhoController( _carrinhoRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); var actionResult = await carrinhoController.Get(fakeClienteId) as OkObjectResult; //Assert OkObjectResult okObjectResult = Assert.IsType <OkObjectResult>(actionResult); CarrinhoCliente carrinhoCliente = Assert.IsAssignableFrom <CarrinhoCliente>(okObjectResult.Value); Assert.Equal(fakeClienteId, carrinhoCliente.ClienteId); Assert.Equal(carrinhoFake.Itens[0].ProdutoId, carrinhoCliente.Itens[0].ProdutoId); Assert.Equal(carrinhoFake.Itens[1].ProdutoId, carrinhoCliente.Itens[1].ProdutoId); Assert.Equal(carrinhoFake.Itens[2].ProdutoId, carrinhoCliente.Itens[2].ProdutoId); _carrinhoRepositoryMock.Verify(); _identityServiceMock.Verify(); _serviceBusMock.Verify(); }
public async Task Get_carrinho_cliente_no_client() { //arrange var controller = new CarrinhoController(_carrinhoRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); //act IActionResult actionResult = await controller.Get(null); //assert BadRequestObjectResult badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actionResult); Assert.IsType <SerializableError>(badRequestObjectResult.Value); }