title: Moq - How to create a mock that implements multiple interfaces at the same time
body: <p>I have a method that expects an object implementing two interfaces:</p>
  <pre class="lang-cs prettyprint-override"><code>public class MyClass {
      public void Do&lt;T&gt;(T myObj) where T : IInterfaceA, IInterfaceB { ... }
  }
  </code></pre>
  <p>I am using Moq 4.10.1 to try to create a mock of this object. The <a href="https://github.com/Moq/moq4/wiki/Quickstart#advanced-features" rel="nofollow noreferrer">documentation</a> shows how to work with multiple interfaces:</p>
  <pre class="lang-cs prettyprint-override"><code>// implementing multiple interfaces in mock
  var mock = new Mock&lt;IFoo&gt;();
  var disposableFoo = mock.As&lt;IDisposable&gt;();
  // now the IFoo mock also implements IDisposable :)
  disposableFoo.Setup(disposable =&gt; disposable.Dispose());
  
  // implementing multiple interfaces in single mock
  var mock = new Mock&lt;IFoo&gt;();
  mock.Setup(foo =&gt; foo.Name).Returns(&quot;Fred&quot;);
  mock.As&lt;IDisposable&gt;().Setup(disposable =&gt; disposable.Dispose());
  </code></pre>
  <p>However, following these examples, I could only get a mock that implements one of the interfaces at a time, but not both:</p>
  <pre class="lang-cs prettyprint-override"><code>var mockA = new Mock&lt;IInterfaceA&gt;();
  var mockB = mockA.As&lt;IInterfaceB&gt;();
  instance.Do(mockB.Object); // Error: mock only implements IInterfaceB, but not IInterfaceA
  </code></pre>
  <p>Is there any way to create a mock implementing both interfaces at the same time?</p>
  <p>Edit: I don't want to create a third interface that combines the others only to allow testing.</p>
  <p>Thanks</p>