示例#1
0
        public async Task AuthorExistsAsync_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. It has been a success in term of sales, and the paperback was the fourth best seller of Swedish novels in 2007."
                            }
                        }
                    });
                    context.SaveChanges();

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

                    var nonExist = await repository.AuthorExistsAsync(Guid.Parse("f74d6899-9ed2-4137-9876-66b070553f8f"));

                    Assert.True(exist);
                    Assert.False(nonExist);
                }
        }