Пример #1
0
        public async Task Succeed_ReturnGenre()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnGenre));

            using (var assertContext = new MoviesCatalogContext(options))
            {
                var sut = new GenreService(assertContext);

                var genre = await sut.CreateGenreAsync("drama");

                Assert.AreEqual(genre.Name, "drama");
            }
        }
        public async Task CreateGenreAsyncShouldAddGenreToDbIfInputIsValid()
        {
            var input = new CreateGenreInputModel
            {
                Name = "genre1"
            };

            var genreService = new GenreService(dbContext, mapper);

            var actualResult = await genreService.CreateGenreAsync(input);

            Assert.True(actualResult);
            Assert.True(dbContext.Genres.Count() == 1);
            Assert.True(dbContext.Genres.First().Name == "genre1");
        }
        public async Task CreateGenreAsyncShouldReturnFalseIfGenreWithSameNameExists()
        {
            await dbContext.Genres.AddAsync(new Genre { Name = "genre1" });

            await dbContext.SaveChangesAsync();

            var input = new CreateGenreInputModel
            {
                Name = "genre1"
            };

            var genreService = new GenreService(dbContext, mapper);

            var actualResult = await genreService.CreateGenreAsync(input);

            Assert.False(actualResult);
            Assert.True(dbContext.Genres.Count() == 1);
        }