コード例 #1
0
        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"));
        }
コード例 #2
0
        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);
        }