public void Controller_Contas_Get_DevePassar() { // Arrange var conta = ContaObjectMother.GetContaValida(); var response = new List <Conta>() { conta }.AsQueryable(); _contaServiceMock.Setup(s => s.GetAll(0)).Returns(response); // Action var callback = _contasController.Get(); //Assert _contaServiceMock.Verify(s => s.GetAll(0), Times.Once); var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <List <ContaViewModel> > >().Subject; httpResponse.Content.Should().NotBeNullOrEmpty(); httpResponse.Content.First().Id.Should().Be(conta.Id); }
public async Task GetOk() { var serviceMock = new Mock <IContaService>(); serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync( new ContaDto { Id = Guid.NewGuid(), Name = "PV Conta", Description = "Conta Corrente", Balance = 0, Status = true } ); _controller = new ContasController(serviceMock.Object); var result = await _controller.Get(Guid.NewGuid()); Assert.True(result is OkObjectResult); }
public async Task GetBadRequest() { var serviceMock = new Mock <IContaService>(); serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync( new ContaDto { Id = Guid.NewGuid(), Name = "PV Conta", Description = "Conta Corrente", Balance = 0, Status = true } ); _controller = new ContasController(serviceMock.Object); _controller.ModelState.AddModelError("Id", "Formato Inválido"); var result = await _controller.Get(Guid.NewGuid()); Assert.True(result is BadRequestObjectResult); }