public override async Task <bool> ArtistDeleteByIDAsync(int artistID) { // Delete artist from database int recordsChanged; try { recordsChanged = await repository.ArtistDeleteByIDAsync(artistID); } catch { recordsChanged = 0; } return(recordsChanged > 0); }
public async Task ArtistDeleteByIDAsync_DeletesItem() { Mock <DbSet <Artist> > mockArtists = GetMockArtists(); Mock <MusicDemoDbContext> mockContext = new Mock <MusicDemoDbContext>(); mockContext.Setup(m => m.Artists).Returns(mockArtists.Object); MusicDemoRepository repo = new MusicDemoRepository(mockContext.Object); await repo.ArtistDeleteByIDAsync(1); mockArtists.Verify(m => m.Remove(It.Is <Artist>(a => a.ArtistID == 1)), Times.Once()); mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }