public void DeleteShouldRemoveGenreFromDb() { var options = new DbContextOptionsBuilder <BookStoreDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; // var dbContext = new BookStoreDbContext(options); var genreServices = new GenreService(dbContext); var history = new Genre { Name = "History" }; dbContext.Genres.Add(history); var music = new Genre { Name = "Music" }; dbContext.Genres.Add(music); dbContext.SaveChanges(); var genreRemove1 = genreServices.Delete(history.Id); var genreRemove2 = genreServices.Delete(music.Id); Assert.True(genreRemove1); Assert.True(genreRemove2); }
public void DeleteGenre_NotExistedGenreName_ExeptionEntityNotFound() { var notExistGenreId = Guid.NewGuid(); _uow.Setup(uow => uow.Genres.GetById(notExistGenreId)).Returns(null as Genre); _uow.Setup(uow => uow.Genres.Delete(notExistGenreId)); Assert.Throws <EntityNotFound>(() => _sut.Delete(notExistGenreId)); }
public void DeleteTest() { // Arrange var expected = new GenreDTO() { Id = "1", Name = "Fantasy" }; var repository = new Mock <IRepository <Genre> >(); repository.Setup(r => r.Get(expected.Id)).Returns(new Genre { Id = "1", Name = "Fantasy" }); var mapper = new Mock <IMapper>(); mapper.Setup(m => m.Map <Genre, GenreDTO>(It.IsAny <Genre>())).Returns(expected); var svc = new GenreService(repository.Object, mapper.Object); // Act svc.Delete(expected.Id); // Assert repository.Verify(r => r.Delete(It.IsAny <string>()), Times.Once()); repository.Verify(r => r.Save(), Times.Once()); }
public IHttpActionResult Delete(int?id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id == null || id <= 0) { return(NotFound()); } var genre = genreService.GetByID((int)id); if (genre != null) { genreService.Delete(genre); genreService.Save(); return(Content(HttpStatusCode.NoContent, genre)); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> DeleteConfirmed(int id) { var genre = await _genreService.Get(id); await _genreService.Delete(genre); return(RedirectToAction(nameof(Index))); }
public void Delete_GoodArgument_Success() { _mockGenreRepository.Setup(w => w.GetById(It.IsAny <string>())).ReturnsAsync(_genre); using var genreService = new GenreService(_mockGenreRepository.Object, _mapper); var delete = genreService.Delete("123"); _mockGenreRepository.Verify(w => w.Delete(It.IsAny <Genre>()), Times.Once); }
public IActionResult Delete([FromRoute] int id) { if (genreService.Delete(id)) { return(NoContent()); } return(BadRequest()); }
public ActionResult Delete(int id, FormCollection collection) { var Genre = new Genre(); Genre.Id = id; var genre = genreService.Delete(Genre); return(RedirectToAction("Index")); }
public async Task <ActionResult> Delete(Genre genre) { var result = await _genreService.Delete(genre); if (result) { return(Ok()); } return(BadRequest()); }
public ActionResult <Genre> Delete(int id) { try { return(Ok(_service.Delete(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void SetDeleteMark_ShouldCallUpdateGenreOnceWhenGenreName() { // Arrange _genreRepository.Setup(g => g.FirstOrDefault(It.IsAny <Expression <Func <Genre, bool> > >())).Returns(_genre); // Act _genreService.Delete(_genre.Name); // Assert _genreRepository.Verify(a => a.Update(It.IsAny <Genre>()), Times.Once); }
public static void DeleteGenre(byte[] frame) { IGenreDataAccess genreDataAccess = new GenreDataAccess(); IGenreService genreService = new GenreService(genreDataAccess); IParser parser = new Parser(); var data = parser.GetDataObject(frame); var name = data[0]; var genreToDelete = genreService.GetGenre(name); genreService.Delete(genreToDelete); }
public JsonResult DeleteGenre(int genreId) { if (genreId > 0) { genreService.Delete(genreId); return(Json(new { MessageType = 1, MessageContent = "成功删除音乐流派" })); } else { return(Json(new { MessageType = 0, MessageContent = "删除音乐流派失败" })); } }
public ActionResult Delete(Genre genre) { if (genre.Id.HasValue) { var wasDeleted = _genreService.Delete(genre.Id.Value); if (!wasDeleted) { return(View("Message", model: $"Genre: {genre.Name} can not be deleted due to active relations.")); } } return(RedirectToAction("Index")); }
public ActionResult Delete(int?id, GenreViewModel genreViewModel) { try { var genre = genreService.GetByID((int)id); genreService.Delete(genre); genreService.Save(); return(RedirectToAction("Index")); } catch { ModelState.AddModelError("", "Database error!"); return(View(genreViewModel)); } }
public async Task <IActionResult> DeleteGenre([FromRoute] long id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var genre = await _genreService.Delete(id); if (genre == null) { return(NotFound()); } else { return(Ok()); } }
public bool Delete(PLGenre item) { if (PLValidation.IsItemNull(item)) { Console.WriteLine("Cant delete null"); } bool deleteResult = _curGenrelWorkerService.Delete(new BLLGenre { Id = item.Id, GenreName = item.GenreName, Description = item.Description }); if (deleteResult) { Console.WriteLine($"Item with Id={item.Id} was deleted"); } else { Console.WriteLine($"Item delete error"); } return(deleteResult); }
public string Delete(int genreId) { bool isDeleted = genreService.Delete(genreId); return(isDeleted ? "Genre deleted successfully." : "Failed to delete the genre."); }
public void Delete_NullArgument_Exception() { using var genreService = new GenreService(_mockGenreRepository.Object, _mapper); Assert.ThrowsAsync <CustomException>(() => genreService.Delete(null)); }
public void Delete_BadArgument_ReturnNull_Exception() { _mockGenreRepository.Setup(w => w.GetById(It.IsAny <string>())).ReturnsAsync(() => null); using var genreService = new GenreService(_mockGenreRepository.Object, _mapper); Assert.ThrowsAsync <CustomException>(() => genreService.Delete("132")); }
public void Delete(int id) { _genreService.Delete(id); }
public RedirectToActionResult Delete(int ID) { _genderService.Delete(ID); return(RedirectToAction("Index")); }
public async Task DeleteTest() { var genre = new Genre(1, "Moq"); await genreService.Delete(genre); }