예제 #1
0
        public async Task DeleteAuthorAsync_Test()
        {
            using (var context = new LibraryContext(Utilities.TestDbContextOptions()))
                using (ILibraryRepository repository = new LibraryRepository(context))
                {
                    // Arrange
                    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 author = await repository.GetAuthorAsync(Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"));

                    Assert.NotNull(author);

                    // Act
                    await repository.DeleteAuthorAsync(author);

                    await repository.SaveChangesAsync();

                    // Assert
                    var NonAuthor = await repository.GetAuthorAsync(Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"));

                    Assert.Null(NonAuthor);
                }
        }