public void GetContaPagar() { var options = new DbContextOptionsBuilder <ContaContext>() .UseInMemoryDatabase(databaseName: "WebAPI") .Options; using (var context = new ContaContext(options)) { context.Add(new Conta { Nome = "Conta 01", ValorOriginal = 100, DataVencimento = Convert.ToDateTime("2021-01-01"), DataPagamento = Convert.ToDateTime("2021-01-20") }); context.SaveChanges(); } using (var context = new ContaContext(options)) { ContaPagarController contaPagarController = new ContaPagarController(context); var result = contaPagarController.Get() as ObjectResult; var contas = Assert.IsType <List <Conta> >(result.Value); Assert.True(contas.Count > 0); } }
public IActionResult Post([FromBody] Conta conta) { if (conta == null) { return(BadRequest("Conta é null.")); } if (conta.IsValid()) { conta.Calcular(); _contaContext.Add(conta); _contaContext.SaveChanges(); return(Ok("Conta adicionada com sucesso.")); } else { return(BadRequest(conta.Errors())); } }
public void Commit() { _context.SaveChanges(); }
public void Add(Conta item) { _context.Contas.Add(item); _context.SaveChanges(); }
public void Save() { _context.SaveChanges(); }
public int SaveChanges() { return(Db.SaveChanges()); }