title: How should I unit test a repository method implemented with Entity Framework?
body: <p>I have a method like this in my repository layer:</p>
  
  <pre><code>public IEnumerable&lt;User&gt; GetActiveUsers()
  {
      return dbContext.Users
             .Where(u =&gt; u.IsActive)
             .OrderBy(u =&gt; u.Name)
             .ToList();
  }
  </code></pre>
  
  <p>Should I unit test this method by mocking the <code>DbContext</code> or should I test it with an actual database? </p>
  
  <p>I know it stops being a "unit" test when I use an actual database, but I don't see the value in mocking the <code>DbContext</code> to test my repository methods which are thin in logic and usually just calls EF's method directly.</p>
  
  <p>And if I have to use an actual database, is there any standard strategy to populate test data in the database so tests run independently and do not alter any state in the database?</p>