示例#1
0
        public async Task Update_Book_Genres()
        {
            var book = await BookHelpers.CreateValidBookWithAllProperties();

            var repository = new BookRepository(_fixture.Context);

            (await repository.ExistsAsync(book.Id)).Should().BeTrue();

            var sut = await repository.LoadAsync(book.Id);

            var bookId = sut.Id;

            sut.Should().NotBeNull();
            sut.Genres.Count.Should().Be(2);

            var genre1 = await GenreHelpers.CreateValidGenre();

            var genre2 = await GenreHelpers.CreateValidGenre();

            var genres = new List <Genre> {
                genre1, genre2
            };
            await BookHelpers.UpdateGenres(sut.Id, genres);

            sut = await repository.LoadAsync(book.Id);

            await _fixture.Context.Entry(sut).ReloadAsync();

            sut.Genres.Count.Should().Be(4);
            sut.Id.Should().Be(bookId);
        }
        public async Task Genre_inserted_to_database()
        {
            var genre = await GenreHelpers.CreateValidGenre();

            var repository = new GenreRepository(_fixture.Context);

            (await repository.ExistsAsync(genre.Id)).Should().BeTrue();
        }
        public async Task Update_Genre()
        {
            var genre = await GenreHelpers.CreateValidGenre();

            genre.Name.Should().Be("sci-fi");

            var sut = Genre.Create(genre.Id, "fantasy");

            await GenreHelpers.UpdateGenre(sut);

            await _fixture.Context.Entry(genre).ReloadAsync();

            genre.Name.Should().Be("fantasy");
        }
        public async Task Remove_Genre()
        {
            var genre = await GenreHelpers.CreateValidGenre();

            var repository = new GenreRepository(_fixture.Context);

            (await repository.ExistsAsync(genre.Id)).Should().BeTrue();

            await GenreHelpers.RemoveGenre(genre.Id);

            var sut = await repository.GetAsync(genre.Id);

            await _fixture.Context.Entry(sut).ReloadAsync();

            (await repository.ExistsAsync(genre.Id)).Should().BeFalse();
        }