title: How are people unit testing with Entity Framework 6, should you bother?
body: <p>I am just starting out with Unit testings and TDD in general. I have dabbled before but now I am determined to add it to my workflow and write better software.</p>
  
  <p>I asked a question yesterday that kind of included this, but it seems to be a question on its own.  I have sat down to start implementing a service class that I will use to abstract away the business logic from the controllers and map to specific models and data interactions using EF6.</p>
  
  <p>The issue is I have roadblocked myself already because I didn't want to abstract EF away in a repository (it will still be available outside the services for specific queries, etc) and would like to test my services (EF Context will be used).</p>
  
  <p>Here I guess is the question, is there a point to doing this? If so, how are people doing it in the wild in light of the leaky abstractions caused by IQueryable and the many great posts by <a href="https://stackoverflow.com/users/413501/ladislav-mrnka">Ladislav Mrnka</a> on the subject of unit testing not being straightforward because of the differences in Linq providers when working with an in memory implementation as apposed to a specific database.</p>
  
  <p>The code I want to test seems pretty simple. (this is just dummy code to try and understand what i am doing, I want to drive the creation using TDD)</p>
  
  <p><strong>Context</strong></p>
  
  <pre><code>public interface IContext
  {
      IDbSet&lt;Product&gt; Products { get; set; }
      IDbSet&lt;Category&gt; Categories { get; set; }
      int SaveChanges();
  }
  
  public class DataContext : DbContext, IContext
  {
      public IDbSet&lt;Product&gt; Products { get; set; }
      public IDbSet&lt;Category&gt; Categories { get; set; }
  
      public DataContext(string connectionString)
                  : base(connectionString)
      {
  
      }
  }
  </code></pre>
  
  <p><strong>Service</strong></p>
  
  <pre><code>public class ProductService : IProductService
  {
      private IContext _context;
  
      public ProductService(IContext dbContext)
      {
          _context = dbContext;
      }
  
      public IEnumerable&lt;Product&gt; GetAll()
      {
          var query = from p in _context.Products
                      select p;
  
          return query;
      }
  }
  </code></pre>
  
  <p>Currently I am in the mindset of doing a few things:</p>
  
  <ol>
  <li>Mocking EF Context with something like this approach- <a href="http://www.asp.net/web-api/overview/testing-and-debugging/mocking-entity-framework-when-unit-testing-aspnet-web-api-2" rel="noreferrer">Mocking EF When Unit Testing</a> or directly using a mocking framework on the interface like moq - taking the pain that the unit tests may pass but not necessarily work end to end and back them up with Integration tests?</li>
  <li>Maybe using something like <a href="https://entityframework-effort.net/" rel="noreferrer">Effort</a> to mock EF - I have never used it and not sure if anyone else is using it in the wild?</li>
  <li>Not bother testing anything that simply calls back to EF - so essentially service methods that call EF directly (getAll etc) are not unit tested but just integration tested?</li>
  </ol>
  
  <p>Anyone out there actually doing this out there without a Repo and having success?</p>