public async Task <IActionResult> PutCompra([FromRoute] int id, [FromBody] Compra compra) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != compra.Id) { return(BadRequest()); } _context.Entry(compra).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompraExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEvento([FromRoute] long id, [FromBody] Evento evento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != evento.Id) { return(BadRequest()); } _context.Entry(evento).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async void GetEventos() { // Arrange var options = new DbContextOptionsBuilder <AlpmysContext>() .UseInMemoryDatabase("GetTest") .Options; AlpmysContext context = new AlpmysContext(options); Evento e = new Evento(); e.Nome = "Evento!"; Evento e2 = new Evento(); e2.Nome = "Evento2"; context.Evento.Add(e); context.Evento.Add(e2); await context.SaveChangesAsync(); EventosController controller = new EventosController(context); // Act var result = await controller.GetEvento(); // Assert Assert.IsType <OkObjectResult>(result); Assert.Equal(2, context.Evento.Count()); }
public async void GetUsuarios() { // Arrange var options = new DbContextOptionsBuilder <AlpmysContext>() .UseInMemoryDatabase("GetTest") .Options; AlpmysContext context = new AlpmysContext(options); Usuario u = new Usuario(); u.Email = "*****@*****.**"; Usuario u2 = new Usuario(); u2.Email = "*****@*****.**"; context.Usuario.Add(u); context.Usuario.Add(u2); await context.SaveChangesAsync(); UsuariosController controller = new UsuariosController(context); // Act var result = await controller.GetUsuario(); // Assert Assert.IsType <OkObjectResult>(result); Assert.Equal(2, context.Usuario.Count()); }