public async Task Post_carrinho_cliente_not_found() { //Arrange var fakeClienteId = "1"; var fakeCarrinhoCliente = GetCarrinhoClienteFake(fakeClienteId); _carrinhoRepositoryMock.Setup(x => x.UpdateCarrinhoAsync(It.IsAny <CarrinhoCliente>())) .ThrowsAsync(new KeyNotFoundException()) .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.Post(fakeCarrinhoCliente); //Assert NotFoundResult notFoundResult = Assert.IsType <NotFoundResult>(actionResult); _carrinhoRepositoryMock.Verify(); _identityServiceMock.Verify(); _serviceBusMock.Verify(); }
public async Task Post_carrinho_cliente_sucesso() { //Arrange var fakeClienteId = "1"; var fakeCarrinhoCliente = GetCarrinhoClienteFake(fakeClienteId); _carrinhoRepositoryMock.Setup(x => x.UpdateCarrinhoAsync(It.IsAny <CarrinhoCliente>())) .Returns(Task.FromResult(fakeCarrinhoCliente)) .Verifiable(); _serviceBusMock.Setup(x => x.Publish(It.IsAny <CheckoutEvent>(), null)) .Verifiable(); //Act var carrinhoController = new CarrinhoController( _carrinhoRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); var actionResult = await carrinhoController.Post(fakeCarrinhoCliente) as OkObjectResult; //Assert Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK); Assert.Equal(((CarrinhoCliente)actionResult.Value).ClienteId, fakeClienteId); _carrinhoRepositoryMock.Verify(); }
public async Task Post_carrinho_cliente_invalid_model() { //Arrange var controller = new CarrinhoController( _carrinhoRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); controller.ModelState.AddModelError("ClienteId", "Required"); //Act var actionResult = await controller.Post(new CarrinhoCliente()); //Assert BadRequestObjectResult badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actionResult); }