title: Using Moq setting up all methods of a mock equally
body: <p>Let's assume I have the interface</p>
  
  <pre><code>public interface A {
    int Foo1();
  
    int Foo2();
  
    int Foo3();
  }
  </code></pre>
  
  <p>and a testing method with a mock (using <strong><a href="https://code.google.com/p/moq/">Moq</a></strong>) like</p>
  
  <pre><code>Mock&lt;A&gt; mock = new Mock&lt;A&gt;();
  </code></pre>
  
  <p>Now there are basically two testing scenarios:</p>
  
  <p><strong>Scenario 1</strong></p>
  
  <p>I want to test what my system-under-test does if the interface implementation throws a specific exception on any method. So I want to setup all methods to throw the same exception like</p>
  
  <pre><code>mock.Setup(x =&gt; x.Foo1()).Throws(new Exception());
  mock.Setup(x =&gt; x.Foo2()).Throws(new Exception());
  mock.Setup(x =&gt; x.Foo3()).Throws(new Exception());
  </code></pre>
  
  <p><strong>Scenario 2</strong></p>
  
  <p>I want to test what my system-under-test does if the methods return any number. So I could think of setup the mock like</p>
  
  <pre><code>mock.Setup(x =&gt; x.Foo1()).Returns(1);
  mock.Setup(x =&gt; x.Foo2()).Returns(1);
  mock.Setup(x =&gt; x.Foo3()).Returns(1);
  </code></pre>
  
  <p><strong>Reason:</strong>
  I have many different unit tests for the system-under-test. Some of them are tests for business logic where it makes a difference e.g. <em>what</em> values are returned. But some are just small tests for general behavior, e.g. if the system-under-test throws an exception if one of the used components throws one. Or the opposite, that the system-under-test throws no exception if all components behave as expected. And for these small tests I'm using code like above right now. </p>
  
  <p><strong>Question:</strong>
  Is there a smarter way to initialize all (matching) methods of a Mock the same way? Something like</p>
  
  <pre><code>mock.SetupAll().Throws(new Exception());
  </code></pre>
  
  <p>or</p>
  
  <pre><code>mock.SetupAll&lt;int&gt;().Returns(1);
  </code></pre>
  
  <p>(which means: setup those methods which have a return type of <code>int</code>)?</p>