public void DeleteShouldRemoveAndReturnFilm() { var options = new DbContextOptionsBuilder <FilmeDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteShouldRemoveAndReturnFilm)) .EnableSensitiveDataLogging() .Options; using (var context = new FilmeDbContext(options)) { var filmService = new FilmService(context); var toAdd = filmService.Create(new Lab3.ViewModels.FilmPostModel { Title = "DeSters", Director = "dir1", DateAdded = new DateTime(), Duration = 100, Description = "asdvadfbdbsb", Genre = "Comedy", ReleaseYear = 2000, Rating = 3, Watched = 0 }, null); Assert.IsNotNull(toAdd); Assert.AreEqual(1, filmService.GetAll(new DateTime(), new DateTime(), 1).Entries.Count); var deletedFilm = filmService.Delete(1); Assert.IsNotNull(deletedFilm); Assert.AreEqual(0, filmService.GetAll(new DateTime(), new DateTime(), 1).Entries.Count); } }
public IActionResult Delete(string id) { var film = _service.GetById(id); if (film == null) { return(NotFound()); } _service.Delete(film); return(NoContent()); }
public ActionResult Delete(int id, Film film) { try { film = filmService.GetFilm(id); filmService.Delete(id); return(RedirectToAction("Index")); } catch (DataException) { ModelState.AddModelError("", "Không thể xóa phim"); } return(View(film)); }
public void DELETE_ShouldReturnOneFilmLess() { //Arrange int x = 2; int i = 3 - 1; // We got three(3) objects into the db, then we remove one(1) of them. var options = new DbContextOptionsBuilder <CinemaDbContext>() .UseInMemoryDatabase(databaseName: "DELETE_ShouldReturnOneFilmLess") .Options; var context = new CinemaDbContext(options); SeedFilms(context); var service = new FilmService(context); //Act var result = service.Delete(x); //Assert Assert.Equal(i, result.ToList().Count); }
public ActionResult Delete(int id) { fs.Delete(id); return(RedirectToAction("Film")); }