Example #1
0
        public async Task DeleteBookAsync_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)),
                        Books       = new List <Book>()
                        {
                            new Book()
                            {
                                Id          = new Guid("1325360c-8253-473a-a20f-55c269c20407"),
                                Title       = "Easy Money",
                                Description = "Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus."
                            }
                        }
                    });
                    context.SaveChanges();

                    var book = await repository.GetBookForAuthorAsync(
                        authorId : Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"),
                        bookId : Guid.Parse("1325360c-8253-473a-a20f-55c269c20407"));

                    await repository.DeleteBookAsync(book);

                    await repository.SaveChangesAsync();

                    var book1 = await repository.GetBookForAuthorAsync(
                        authorId : Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"),
                        bookId : Guid.Parse("1325360c-8253-473a-a20f-55c269c20407"));

                    Assert.Null(book1);
                }
        }