コード例 #1
0
        public async Task AddBookForAuthorAsync_WithoutGuidBook_Test()
        {
            using (var context = new LibraryContext(Utilities.TestDbContextOptions()))
                using (ILibraryRepository repository = new LibraryRepository(context))
                {
                    context.Authors.Add(new Author()
                    {
                        Id          = new Guid("a1da1d8e-1988-4634-b538-a01709477b77"),
                        FirstName   = "Jens",
                        LastName    = "Lapidus",
                        Genre       = "Thriller",
                        DateOfBirth = new DateTimeOffset(new DateTime(1974, 5, 24))
                    });
                    context.SaveChanges();

                    await repository.AddBookForAuthorAsync(
                        authorId : Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"),
                        book : new Book
                    {
                        Title       = "Easy Money",
                        Description = "Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus."
                    });

                    await repository.SaveChangesAsync();

                    var books = await repository.GetBooksForAuthorAsync(Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"));

                    Assert.Collection(books, bookItem => {
                        Assert.Equal("Easy Money", bookItem.Title);
                        Assert.Equal("Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus.", bookItem.Description);
                    });
                }
        }