title: How to fake DbContext.Entry method in Entity Framework with repository pattern
body: <p>Because I want to unit test my code I have implemented the repository pattern in my MVC4 application. I managed to make a Context Interface, a fake Context and use a fake implementation of a <a href="http://msdn.microsoft.com/en-us/library/system.data.entity.dbset%28v=vs.113%29.aspx" rel="noreferrer"><code>System.Data.Entity.DbSet</code></a> by following <a href="https://gist.github.com/rally25rs/1492134" rel="noreferrer">this</a> code.</p>
  
  <p>Unfortunately, just like two posters before me (<a href="https://stackoverflow.com/questions/16038566/mocking-dbentityentry">here</a> and <a href="https://stackoverflow.com/questions/7106977/fake-dbcontext-of-entity-framework-4-1-to-test-my-repositories">here</a>), I do not manage to mock the <a href="http://msdn.microsoft.com/en-us/library/gg696238%28v=vs.113%29.aspx" rel="noreferrer"><code>DbContext.Entry method</code></a>. I use this method for updating database entries in my code as follows:</p>
  
  <pre><code>DbContext.Entry(order).State = EntityState.Modified;
  </code></pre>
  
  <p>I have not found a solution to this problem, only people who say things like: </p>
  
  <blockquote>
    <p>"and what is the point of unit testing this code? You fake the Find
    method, then you fake DbEntityEntry and there will be no real logic to
    test."</p>
  </blockquote>
  
  <p>or to</p>
  
  <blockquote>
    <p>read <a href="https://stackoverflow.com/questions/6904139/fake-dbcontext-of-entity-framework-4-1-to-test/6904479#6904479">this</a> and all linked questions before you continue. (...)  If you want to test your repositories create integration tests talking to the real database.</p>
  </blockquote>
  
  <p>That is all good and well but still no answer to the question. I read the critique and I still do want this Entry method so I will be able to use a fake context and use mock objects in my unit test. Of course I will use integration tests as well but they are not nearly as fast as some quick unit tests. </p>
  
  <p>The error I receive when I try some implementations is that <code>Error  2   'Project.Models.Order' does not contain a definition for 'State' and no extension method 'State' accepting a first argument of type '[whatever return type I use]' could be found (are you missing a using directive or an assembly reference?)</code></p>
  
  <p>I hope someone can help me make a fake DbContext.Entry method.</p>