title: How could I Mock the FromSql() method?
body: <p>I was wondering is there any way other than building a wrapper for mocking the <code>FromSql</code>? I know this method is static, but since they added things like <code>AddEntityFrameworkInMemoryDatabase</code> to entity framework core, I thought there might be a solution for this too, I use EF Core 1.0.1 in my project.</p>
  
  <p>My end goal is to test this method:</p>
  
  <pre><code>public List&lt;Models.ClosestLocation&gt; Handle(ClosestLocationsQuery message)
  {
      return _context.ClosestLocations.FromSql(
          "EXEC GetClosestLocations {0}, {1}, {2}, {3}",
          message.LocationQuery.Latitude,
          message.LocationQuery.Longitude,
          message.LocationQuery.MaxRecordsToReturn ?? 10,
          message.LocationQuery.Distance ?? 10
      ).ToList();
  }
  </code></pre>
  
  <p>I want to ensure that my query is handled with the same object that I passed into it, based on <a href="https://stackoverflow.com/a/26017936/1650277">this answer</a> in entity framework 6 I could do something like this:</p>
  
  <pre><code>[Fact]
  public void HandleInvokesGetClosestLocationsWithCorrectData()
  {
      var message = new ClosestLocationsQuery
      {
          LocationQuery =
              new LocationQuery {Distance = 1, Latitude = 1.165, Longitude = 1.546, MaxRecordsToReturn = 1}
      };
  
      var dbSetMock = new Mock&lt;DbSet&lt;Models.ClosestLocation&gt;&gt;();
  
      dbSetMock.Setup(m =&gt; m.FromSql(It.IsAny&lt;string&gt;(), message))
          .Returns(It.IsAny&lt;IQueryable&lt;Models.ClosestLocation&gt;&gt;());
  
      var contextMock = new Mock&lt;AllReadyContext&gt;();
  
      contextMock.Setup(c =&gt; c.Set&lt;Models.ClosestLocation&gt;()).Returns(dbSetMock.Object);
  
      var sut = new ClosestLocationsQueryHandler(contextMock.Object);
      var results = sut.Handle(message);
  
      contextMock.Verify(x =&gt; x.ClosestLocations.FromSql(It.IsAny&lt;string&gt;(), It.Is&lt;ClosestLocationsQuery&gt;(y =&gt;
          y.LocationQuery.Distance == message.LocationQuery.Distance &amp;&amp;
          y.LocationQuery.Latitude == message.LocationQuery.Latitude &amp;&amp;
          y.LocationQuery.Longitude == message.LocationQuery.Longitude &amp;&amp;
          y.LocationQuery.MaxRecordsToReturn == message.LocationQuery.MaxRecordsToReturn)));
  }
  </code></pre>
  
  <p>But unlike <code>SqlQuery&lt;T&gt;</code> in EF 6, the <code>FromSql&lt;T&gt;</code> in EF Core is static extension method, I'm asking this question because I think I might approach this problem from the wrong angle or there might be a better alternative than a wrapper, I'd appreciate any thought on this.</p>