title: Mocking dbset<T> where method returns notSupportedException
body: <p>I'm trying to Mock the where clause of the dbset of my generic repository, and no idea why I'm getting a System.NotSupported Exception.
  I'm quite new into mocking, so I have no clue why this is happening.</p>
  
  <pre><code>private List&lt;StubEntity&gt; _data;
  private Repository&lt;StubEntity&gt; _repository;
  
  [TestInitialize]
  public void TestInitialize()
  {
      _data = new List&lt;StubEntity&gt;
      {
          new StubEntity {Id = 1, Name = "Entity 1"},
          ...
      };
      var queryableData = _data.AsQueryable();
  
      var mockDbSet = new Mock&lt;DbSet&lt;StubEntity&gt;&gt;();
      mockDbSet
          .Setup(m =&gt; m.Where(It.IsAny&lt;Expression&lt;Func&lt;StubEntity, bool&gt;&gt;&gt;()))
          .Returns&lt;Expression&lt;Func&lt;StubEntity, bool&gt;&gt;&gt;(p =&gt; queryableData.Where(p));
  
      var context = new Mock&lt;StubContext&gt;();
      context.Setup(x =&gt; x.DbEntities).Returns(mockDbSet.Object);
      context.Setup(x =&gt; x.Set&lt;StubEntity&gt;()).Returns(mockDbSet.Object);
  
      _repository = new Repository&lt;StubEntity&gt;(context.Object);
  }
  </code></pre>
  
  <p>I'm only testing the where clause into a test</p>
  
  <pre><code>[TestMethod]
  public void Find_ReturnsProperEntity()
  {
      var entity = _repository.Find(s =&gt; s.Id == 1);
      ....
  }
  </code></pre>
  
  <p>where the Find method just call the where clause of the context.</p>
  
  <pre><code>public IEnumerable&lt;TEntity&gt; Find(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate)
  {
      return Context.Set&lt;TEntity&gt;().Where(predicate);
  }
  </code></pre>