public void DeleteGenreAsyncThrowsArgumentExceptionWhenGivenInvalidId() { var genres = new List <Genre>(); var mockGenreRepo = new Mock <IGenresRepository>(); mockGenreRepo.Setup(x => x.All()).Returns(genres.AsQueryable()); var service = new GenresService(mockGenreRepo.Object); Assert.ThrowsAsync <ArgumentException>(() => service.DeleteGenre("ivan")); }
public async Task DeleteGenreAsyncWorksCorrectly() { var genres = new List <Genre>(); var mockGenreRepo = new Mock <IGenresRepository>(); mockGenreRepo.Setup(x => x.All()).Returns(genres.AsQueryable()); mockGenreRepo.Setup(x => x.Delete(It.IsAny <Genre>())).Callback((Genre genre) => genres.Remove(genre)); genres.Add(new Genre() { Id = "test123", Name = "ivan" }); var service = new GenresService(mockGenreRepo.Object); await service.DeleteGenre("test123"); Assert.Empty(genres); }