title: How do I use Moq to mock an extension method?
body: <p>I am writing a test that depends on the results of an extension method but I don't want a future failure of that extension method to ever break this test. Mocking that result seemed the obvious choice but <strong>Moq doesn't seem to offer a way to override a static method</strong> (a requirement for an extension method). There is a similar idea with Moq.Protected and Moq.Stub, but they don't seem to offer anything for this scenario. Am I missing something or should I be going about this a different way?</p>
  
  <p>Here is a trivial example that fails with the usual <strong><em>"Invalid expectation on a non-overridable member"</em></strong>. This is a bad example of needing to mock an extension method, but it should do.</p>
  
  <pre><code>public class SomeType {
      int Id { get; set; }
  }
  
  var ListMock = new Mock&lt;List&lt;SomeType&gt;&gt;();
  ListMock.Expect(l =&gt; l.FirstOrDefault(st =&gt; st.Id == 5))
          .Returns(new SomeType { Id = 5 });
  </code></pre>
  
  <p>As for any TypeMock junkies that might suggest I use Isolator instead: I appreciate the effort since it looks like TypeMock could do the job blindfolded and inebriated, but our budget isn't increasing any time soon.</p>