title: Create a fake DbContext
body: <p>I am creating an MVC application with EF and currently have used the generic repository pattern, like this one: <a href="http://www.tugberkugurlu.com/archive/generic-repository-pattern-entity-framework-asp-net-mvc-and-unit-testing-triangle" rel="nofollow">Generic Repository Pattern</a>. Everything worked great except for the fact that for each repository a new context was created and working with two or more repositories is needed in my application. As I am using StructureMap I added </p>
  
  <pre><code>x.For&lt;IDbContext&gt;().HttpContextScoped().Use(context =&gt; new MyContext());
  </code></pre>
  
  <p>where IDbContext has the respective methods and is no longer generic but is passed through the constructor.</p>
  
  <p>The problem comes when I have to test things - I want to create an in memory storage (faster than db, custom, easy to control data), something like a HashTable or HashSet for example. What I cannot figure out is how to make a fake implementation of IDbContext that retreives the data from that HashTable. For reference IDbContext looks like this (only the methods used by the DbContext in the generic repository):</p>
  
  <pre><code>    public interface IDbContext : IDisposable
      {
          IDbSet&lt;TEntity&gt; Set&lt;TEntity&gt;() where TEntity : class;
          DbEntityEntry&lt;TEntity&gt; Entry&lt;TEntity&gt;(TEntity entity) where TEntity : class;
          int SaveChanges();
      }
  </code></pre>
  
  <p>In the current situation I suppose I have made a major mistake as creating a fake context does not seem to be a regular routine. Any advices on how to improve the architecture of my application and make it more testable are appreciated.</p>