title: Mock DbContext.set<T>.Add() EF6
body: <p>I have the following classes (where PilsnerContext is a DbContext class):</p>
  
  <pre><code>public abstract class ServiceBase&lt;T&gt; : IService&lt;T&gt; where T: class, IEntity
  {
      protected readonly PilsnerContext Context;
  
      protected ServiceBase(PilsnerContext context)
      {
          Context = context;
      }
  
      public virtual T Add(T entity)
      {
          var newEntity = Context.Set&lt;T&gt;().Add(entity);
          Context.SaveChanges();
          return newEntity;
      }
  }
  
  public class ProspectsService : ServiceBase&lt;Prospect&gt;
  {
      public ProspectsService(PilsnerContext context) : base(context){}
  
  }
  </code></pre>
  
  <p>And i'm trying to make a unit test of the Add method mocking the context like:</p>
  
  <pre><code>[TestClass]
  public class ProspectTest
  {
      [TestMethod]
      public void AddProspect()
      {
          var mockProspect = new Mock&lt;DbSet&lt;Prospect&gt;&gt;();
          var mockContext = new Mock&lt;PilsnerContext&gt;();
  
          mockContext.Setup(m =&gt; m.Prospects).Returns(mockProspect.Object);
  
          var prospectService = new ProspectsService(mockContext.Object);
  
          var newProspect = new Prospect()
          {
              CreatedOn = DateTimeOffset.Now,
              Browser = "IE",
              Number = "1234567890",
              Visits = 0,
              LastVisitedOn = DateTimeOffset.Now
          };
  
          prospectService.Add(newProspect);
  
          mockProspect.Verify(m=&gt;m.Add(It.IsAny&lt;Prospect&gt;()), Times.Once);
          mockContext.Verify(m=&gt;m.SaveChanges(), Times.Once);
      }
  }
  </code></pre>
  
  <p>But the assert:</p>
  
  <pre><code>mockProspect.Verify(m=&gt;m.Add(It.IsAny&lt;Prospect&gt;()), Times.Once);
  </code></pre>
  
  <p>Is failing, I assume is because I'm using Context.set().Add() instead of Context.Prospects.Add() in the Add method but how is the correct way to pass this test?</p>
  
  <p>The exception is:</p>
  
  <pre><code>Expected invocation on the mock once, but was 0 times: m =&gt; m.Add(It.IsAny&lt;Prospect&gt;()) No setups configured. No invocations performed.
  </code></pre>
  
  <p>Thanks in advance.</p>