public void AddBook_SavesBook_ViaContextTest() { //--Arrange var mockSet = new Mock <DbSet <BookModel> >(); var mockContext = new Mock <BookContext>(); var library = new BookLibraryDb(mockContext.Object); //--Act mockContext.Setup(m => m.Books).Returns(mockSet.Object); library.AddBook(new BookModel() { BookId = 10000, Title = "The Final Empire, Mistborn", Author = "Brandon Sanderson", Description = "In a world where ash falls from the sky, and mist dominates the night, an evil cloaks the land and stifles all life. " + "The future of the empire rests on the shoulders of a troublemaker and his young apprentice. " + "Together, can they fill the world with color once more?", ImageUrl = "https://images.gr-assets.com/books/1480717416l/68428.jpg", IsRead = false }); //--Assert mockSet.Verify(m => m.Add(It.IsAny <BookModel>()), Times.Once); mockContext.Verify(m => m.SaveChanges(), Times.Once); }