/// <summary> /// Creates a book written by two authors and inserts it into the context. /// </summary> /// <param name="context">The context.</param> private static void GivenBookByTwoAuthors(BookDepositoryContext context) { var book = new Book { Title = "Daughter of the Empire" }; var author1 = new Author { Name = "Janny Wurts" }; var author2 = new Author { Name = "Raymond E. Feist" }; book.BookAuthors = new List <BookAuthor> { new BookAuthor { Book = book, Author = author1 }, new BookAuthor { Book = book, Author = author2 } }; context.Books.Add(book); context.SaveChanges(); }
protected BookDepositoryContext Context() { var options = Options(); var context = new BookDepositoryContext(options); context.Database.EnsureCreated(); return(context); }