title: Mocking a return type from another Mocked type using Moq
body: <p>So I'm trying to return a mocked type from another Mocked type, I've made some progress but I'm stuck here (interface names have been simplified)</p>
  
  <p>Consider the interface IFoo and IFooItem. Calling Add on an IFoo type, passing in an IBar returns an IFooItem</p>
  
  <pre><code>interface IFoo
  {
     IFooItem Add(IBar bar);
  }
  
  interface IFooItem
  {
     int fooItemId {get; set;}
  }
  </code></pre>
  
  <p>Also I have a IFooRepository, which I'm trying to use Moq to mock so I can mock adding an item.</p>
  
  <p>So,</p>
  
  <pre><code>var mockFooRepository = new Mock&lt;IFooRepository&gt;();
  mockFooRepository.Setup(m=&gt; m.Add(It.IsAny&lt;IBar&gt;()))
    .Returns(
       // What is the correct way to mock properties of a new IFooItem from 
       // mocked properties of IBar
       // essentially a new mocked type of IFooItem that can read from IBar
       // so IFooItem.Property = somevalue, IFooItem.Property2 = IBar.SomeProp
       );
  </code></pre>