title: MOQ - how to mock an interface that needs to be cast to another interface?
body: <p>what I want to do is construct a moq for I1 - which is fine ... however in the course of the method that I am testing that uses this mock I need to cast it to I2 in order to access some properties that are not on I1</p>
  
  <pre><code>Interface I1 
  { int AProperty{get;set;}}
  
  Interface I2
  {int AnotherProperty{get;set;}}
  </code></pre>
  
  <p>I then have some objects</p>
  
  <pre><code>Class O1 : I1 {}
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Class O2 : O1 , I2 {}
  </code></pre>
  
  <p>the problem is that when i have an instance of a I2 implementing object I can cast it to I1 in order to access the methods that are implmented through that interface. In code this is not a problem and everythign works as expected.</p>
  
  <p>The only problem comes when writing a unit test on that class.</p>
  
  <p>The interfaces also expose a method called GetNewInstance which returns an initialised instance of the the implementing object cast into the IGetNewInstance interface ... i can usually mock this fine and make it return itself (and so I keep working with the mock object).</p>
  
  <p>however when you try to cast this returned object of type I2 into I1 a null reference results - this makes sense as the mock object that implements I2 does not inherit from anything that inherits I1.</p>
  
  <p>the question is how can i force the mock object to inherit from both I1 ansd I2 at the same time?</p>