title: Mocking Autofac's "Resolve" extension method with TypeMock
body: <p>I'm trying to mock an Autofac resolve, such as</p>
  
  <pre><code>using System;
  using Autofac;
  using TypeMock.ArrangeActAssert;
  
  class Program
  {
      static void Main(string[] args)
      {
          var inst = Isolate.Fake.Instance&lt;IContainer&gt;();
          Isolate.Fake.StaticMethods(typeof(ResolutionExtensions), Members.ReturnNulls);
          Isolate.WhenCalled(() =&gt; inst.Resolve&lt;IRubber&gt;()).WillReturn(new BubbleGum());
          Console.Out.WriteLine(inst.Resolve&lt;IRubber&gt;());
      }
  }
  
  public interface IRubber
  {}
  
  public class BubbleGum : IRubber
  {}
  </code></pre>
  
  <p>Coming from Moq, the syntax and exceptions from TypeMock confuse me a great deal. Having initially run this in a TestMethod, I kept getting an exception resembling "WhenCalled cannot be run without a complementing behavior". I tried defining behaviors for everyone and their mothers, but to no avail.</p>
  
  <p>Then I debug stepped through the test run, and saw that an actual exception was fired from Autofac: IRubber has not been registered.</p>
  
  <p>So it's obvious that the static Resolve function isn't being faked, and I can't get it to be faked, no matter how I go about hooking it up.</p>
  
  <pre><code>Isolate.WhenCalled(() =&gt; ResolutionExtensions.Resolve&lt;IRubber&gt;(null)).WillReturn(new BubbleGum());
  </code></pre>
  
  <p>... throws an exception from Autofac complaining that the IComponentContext cannot be null. Feeding it the presumably faked IContainer (or faking an IComponentContext instead) gets me back to the "IRubber not registered" error.</p>