public async Task WishlistRepository_AddBookToUserWishlist() { // arrange //Constants to compare user and book with test results. const string username = "******"; const string bookName = "Test Book"; const string authorName = "The Author"; long isbn; const int userId = 1; const int bookId = 1; using var contextFactory = new TestLooseLeafContextFactory(); // Add in foreign key / required database data. Wishlist requires a user and a book type to exist in the database. using (LooseLeafContext arrangeContext = contextFactory.CreateContext()) { await contextFactory.CreateUser(arrangeContext, username); isbn = await contextFactory.CreateBook(arrangeContext, bookName, authorName); await arrangeContext.SaveChangesAsync(); } // act using (LooseLeafContext actContext = contextFactory.CreateContext()) { // Create Repository IWishlistRepository wishlistRepository = new WishlistRepository(actContext); // Test repository method await wishlistRepository.AddBookToUserWishlist(userId, bookId); await actContext.SaveChangesAsync(); } // assert // Create a new context to ensure that data was saved to database. using LooseLeafContext assertContext = contextFactory.CreateContext(); var wishlist = await assertContext.Wishlists.Include(w => w.User).Include(w => w.Book).SingleAsync(); // assert that the book and user are the same as one added to the wishlist. Assert.Equal(username, wishlist.User.Username); Assert.Equal(bookName, wishlist.Book.Title); Assert.Equal(authorName, wishlist.Book.Author); }