title: Testing: Entity Framework by faking context
body: <p>I am eating myself up at this moment. It is like Entity Framework isn't testable. I've read alot of posts and threads where they use unit of work or moq or the repo pattern. </p>
  
  <p>I am in a phase that i can't change alot of my architechture of my application. The application fully works at this moment but to be sure I need to have a high code coverage, so testing it is. </p>
  
  <p>For testing, I am using the 'fake context' method where I can use the fake one for mocking and the real one for connection to the database.</p>
  
  <p>I used this as an example. 
  <a href="http://romiller.com/2010/09/07/ef-ctp4-tips-tricks-testing-with-fake-dbcontext/" rel="noreferrer">http://romiller.com/2010/09/07/ef-ctp4-tips-tricks-testing-with-fake-dbcontext/</a></p>
  
  <p>There, you can see that the context is splitted and used as an interface. Like:</p>
  
  <pre><code>    public interface IEmployeeContext
      {
          IDbSet Department Departments { get; }
          IDbSet Employee Employees { get; }
          int SaveChanges();
      }
  
      public class EmployeeContext : DbContext, IEmployeeContext
      {
          public IDbSet Department Departments { get; set; }
          public IDbSet Employee Employees { get; set; }
      }
  
      public class FakeEmployeeContext : IEmployeeContext
      {
          public FakeEmployeeContext()
          {
              this.Departments = new FakeDepartmentSet();
              this.Employees = new FakeEmployeeSet();
          }
  
          public IDbSet Department Departments { get; private set; }
  
          public IDbSet Employee Employees { get; private set; }
  
          public int SaveChanges()
          { 
           return 0; 
          }
      }
  
      }
  </code></pre>
  
  <p>So tesing and everything works. The only thing i can't seem to do, is test a controller with .State in it where i check whether it's changed Like:
  EntityState.Modified</p>
  
  <p>Because this uses an interface I need to add that into the interface context. And create a new one. Or am I missing something ? It is likely not the intention that I create the whole method in that context.. How can I manage to get this to work</p>