title: Moq - Create inline fake for simple factory created DTO interface
body: <p>I have a simple abstract factory that returns a simple type. Basically, it just populates the type with data and returns it, similar to a DTO.</p>
  
  <pre><code>public interface IPagingInstructionFactory
  {
      IPagingInstruction Create(int skip, int take, IProvider provider);
  }
  
  public interface IPagingInstruction
  {
      int Skip { get; }
      int Take { get; }
      IProvider Provider { get; }
  }
  </code></pre>
  
  <p>I now want to create a mock factory that basically does the same thing as the real one - which passes the parameters from the Create() method and returns them from the IPagingInstruction instance's properties.</p>
  
  <p>Here is an example that works:</p>
  
  <pre><code>var pagingInstructionFactory = new Mock&lt;IPagingInstructionFactory&gt;();
  pagingInstructionFactory
      .Setup(x =&gt; x.Create(It.IsAny&lt;int&gt;(), It.IsAny&lt;int&gt;(), It.IsAny&lt;IProvider&gt;()))
      .Returns((int skip, int take, IProvider provider) =&gt; 
          new FakePagingInstruction(skip, take, provider));
  
  
  public class FakePagingInstruction
      : IPagingInstruction
  {
      public FakePagingInstruction(
          int skip,
          int take,
          IProvider provider
          )
      {
          if (provider == null)
              throw new ArgumentNullException("provider");
  
          this.skip = skip;
          this.take = take;
          this.provider = provider;
      }
      private readonly int skip;
      private readonly int take;
      private readonly IProvider provider;
  
      public int Skip
      {
          get { return this.skip; }
      }
  
      public int Take
      {
          get { return this.take; }
      }
  
      public IProvider Provider
      {
          get { return this.provider; }
      }
  }   
  </code></pre>
  
  <p>It seems to me that Moq should be able to create a fake object that can return all 3 properties instead of using a hand-coded fake. However, I can't seem to figure out how to make it return the values that are passed as parameters into the fake factory.</p>
  
  <p>Can this be done, or do I need to use a hand-coded fake every time I need to do this?</p>