public async void ValidPost() { // Arrange var options = new DbContextOptionsBuilder <AlpmysContext>() .UseInMemoryDatabase("CreateNewEvent") .Options; AlpmysContext context = new AlpmysContext(options); EventosController controller = new EventosController(context); Evento e = new Evento(); e.Nome = "Evento!"; // Act await controller.PostEvento(e); // Assert Assert.Equal(1, context.Evento.Count()); }
public async void InvalidPost() { // Arrange var options = new DbContextOptionsBuilder <AlpmysContext>() .UseInMemoryDatabase("FailToCreate") .Options; AlpmysContext context = new AlpmysContext(options); EventosController controller = new EventosController(context); controller.ModelState.AddModelError("error", "invalid model"); Evento e = new Evento(); e.Nome = null; // Act var result = await controller.PostEvento(null); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public async void GetSpecificEvent() { // Arrange var options = new DbContextOptionsBuilder <AlpmysContext>() .UseInMemoryDatabase("UpdateEvent") .Options; AlpmysContext context = new AlpmysContext(options); EventosController controller = new EventosController(context); Evento e = new Evento(); e.Id = 5; e.Nome = "Evento!"; await controller.PostEvento(e); // Act var result = await controller.GetEvento(5); // Assert Assert.IsType <OkObjectResult>(result); }
public async void FailDelete() { // Arrange var options = new DbContextOptionsBuilder <AlpmysContext>() .UseInMemoryDatabase("FailDeleteEvent") .Options; AlpmysContext context = new AlpmysContext(options); EventosController controller = new EventosController(context); Evento e = new Evento(); e.Nome = "Evento!"; // Act await controller.PostEvento(e); var result = await controller.DeleteEvento(10); // Assert Assert.IsType <NotFoundResult>(result); }