title: Failing test while trying to mock Entity Framework with MOQ
body: <p>I am writing an ASP.NET console application to practice mocking Entity Framework with MOQ for testing. The app manages a book store and has a basic <code>EditPrice</code> method as shown below:</p>
  
  <pre><code>public class BookStore
  {
      private BookContext context;
  
      public BookStore(BookContext newContext)
      {
          context = newContext;
      }
  
      // Edit the price of a book in the store
      public Book EditPrice(int id, double newPrice)
      {
          Book book = context.Books.Single(b =&gt; b.Id == id);
          book.Price = newPrice;
          context.SaveChanges();
          return book;
      }
  }
  </code></pre>
  
  <p>This method is tested with the following test method:</p>
  
  <pre><code>    [TestMethod]
      public void Test_EditPrice()
      {
          // Arrange
          var mockSet = new Mock&lt;DbSet&lt;Book&gt;&gt;();
  
          var mockContext = new Mock&lt;BookContext&gt;();
          mockContext.Setup(m =&gt; m.Books).Returns(mockSet.Object);
  
          var service = new BookStore(mockContext.Object);
          service.AddBook(1, "Wuthering Heights", "Emily Brontë", "Classics", 7.99, 5);
  
          // Act
          service.EditPrice(1, 5.99);
  
          // Assert
          mockSet.Verify(m =&gt; m.Add(It.IsAny&lt;Book&gt;()), Times.Once());
          mockContext.Verify(m =&gt; m.SaveChanges(), Times.Exactly(2));
      }
  </code></pre>
  
  <p>This method fails throwing the following error:</p>
  
  <blockquote>
    <p>Message: Test method BookStoreNonCore.Tests.NonQueryTests.Test_EditPrice threw exception:<br>
    System.NotImplementedException: The member 'IQueryable.Provider' has not been implemented on type 'DbSet'1Proxy' which inherits from 'DbSet`1'. Test doubles for 'DbSet'1' must provide implementations of methods and properties that are used.</p>
  </blockquote>
  
  <p>Following along with the debugger, the test fails on the line in the main <code>EditPrice</code> method </p>
  
  <pre><code>Book book = context.Books.Single(b =&gt; b.Id == id);
  </code></pre>
  
  <p>I haven't quite got to grips with mock testing yet and am not sure why this is failing. Would anyone be able to explain and provide a solution?</p>