public async Task GetAllOk() { var serviceMock = new Mock <IContaService>(); serviceMock.Setup(m => m.GetAll()).ReturnsAsync( new List <ContaDto> { new ContaDto { Id = Guid.NewGuid(), Name = "PV Conta", Description = "Conta Corrente", Balance = 0, Status = true }, new ContaDto { Id = Guid.NewGuid(), Name = "PV Conta", Description = "Conta Corrente", Balance = 0, Status = true } } ); _controller = new ContasController(serviceMock.Object); var result = await _controller.GetAll(); Assert.True(result is OkObjectResult); }
public async Task GetAllBadRequest() { var serviceMock = new Mock <IContaService>(); serviceMock.Setup(m => m.GetAll()).ReturnsAsync( new List <ContaDto> { new ContaDto { Id = Guid.NewGuid(), Name = "PV Conta", Description = "Conta Corrente", Balance = 0, Status = true }, 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.GetAll(); Assert.True(result is BadRequestObjectResult); }
public async Task ReturnsList() { var optionsBuilder = new DbContextOptionsBuilder <DataContext>(); optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ContasDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"); var context = new DataContext(optionsBuilder.Options); var service = new ContaService(context); var sut = new ContasController(new NullLogger <ContasController>(), service); var result = await sut.GetAll() as ObjectResult; Assert.IsType <List <ContaAjustada> >(result.Value); Assert.Equal(200, result.StatusCode); }