title: Using Autofac and Moqs with Delegate Factories
body: <p>I am trying to unit test a class that uses factory injection.  I have a class that instantiates two copies of the same object (with different config) to control hardware.  I'm trying to test the behaviour of the classes while simulating the hardware calls.</p>
  
  <p>I've injected a set of factory delegates into the constructors so that the class can instantiate the hardware classes as required.  However I just can't work out how to control or create factory methods within the Autofac.Extras.Moq package. It seems that this functionality isn't supported in the package.</p>
  
  <p>I'm looking for an equivalent call to :</p>
  
  <pre><code>mock.Provide&lt;IHWController&gt;(//created by factory delegate)
  </code></pre>
  
  <p>I want to create a specific mock object with behaviour, based on the parameters used to instantiate the HWcontroller.  Is what I'm trying to do even possible?</p>
  
  <pre><code>class SystemUnderTest
  {
      SystemUnderTest(Ia a, Ib b, Ic c, 
           /** 15 other things **/ 
           Func&lt;Func&lt;Uri, IHwController&gt;, HwType, IHwManager&gt; HwManagerFactory, 
           Func&lt;Uri, IHwController&gt; HwControllerFactory)
      {
      }
  
  }
  
  class HwManager()
  {
      public Func&lt;HwType, Func&lt;Uri, HwController&gt;, HwManager&gt; Factory; 
  
      public HwManager(HwType type, Func&lt;Uri, HwController&gt; ControlFactory)
      {  
          //Constructor
      }
  }
  </code></pre>
  
  <p>The code I'm unit testing creates Managers of controllers.  The controller is the hardware layer, but I'm testing complex (coupled) behaviour inside the manager.  Therefore, I'm trying to work out how to mock the <code>Func&lt;Uri, HwController&gt; ControlFactory</code> so that it returns my setup mock objects so that I can probe the behaviour of the manager. </p>
  
  <p>My system under test creates a concrete instantiation of the HWManager. I realise in a perfect scenario I would test the HwManager and SUT separately, but I'm specifically testing the integration of the two components.</p>
  
  <p>I'd like to configure the autofac to control the delegate factory.  If this isn't possible, then I can manually setup the SUT, but then I don't get any value from the autofac helper.</p>