title: Rhino Mocks - MethodInvocation.ReturnValue vs IMethodOptions.Return
body: <p>Playing around with Rhino Mocks, i just stumbled upon a strange behaviour, which I cannot understand.</p>
  
  <p>Setting up my Stub the following way works as expected - 42 is returned</p>
  
  <pre><code>var generator = MockRepository.GenerateStub&lt;INumberGenerator&gt;();
  generator.Stub(x =&gt; x.GetNumber()).Return(42);
  </code></pre>
  
  <p>Then I tried using the <code>WhenCalled(Action&lt;MethodInvocation&gt; action)</code> extension, which I used so far only for void functions:</p>
  
  <pre><code>generator.Stub(x =&gt; x.GetNumber()).WhenCalled(mi =&gt; mi.ReturnValue = 42);
  </code></pre>
  
  <p>This code throws me an exception <code>Method 'INumberGenerator.GetNumber();' requires a return value or an exception to throw.</code>. Ok, I've added <code>.Return(55)</code> - and now things start to get weird:</p>
  
  <pre><code>generator.Stub(x =&gt; x.GetNumber()).WhenCalled(mi =&gt; mi.ReturnValue = 42).Return(55);
  </code></pre>
  
  <p>Which now returns <strong>42</strong>, instead of <strong>55</strong>. Note that the <code>MethodInvocation.ReturnValue</code> <em>only</em> works when adding the <code>.Return(..)</code> statement which then has absolutely no effect on the returnvalue - which confuses me a lot. Can anybody explain this behaviour?</p>