示例#1
0
        public async Task Update_Book_Authors()
        {
            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.Authors.Count.Should().Be(2);

            var author1 = await AuthorHelpers.CreateValidAuthor();

            var author2 = await AuthorHelpers.CreateValidAuthor();

            var authors = new List <Author> {
                author1, author2
            };
            await BookHelpers.UpdateAuthors(sut.Id, authors);

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

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

            sut.Authors.Count.Should().Be(4);
            sut.Id.Should().Be(bookId);
        }