title: Rhino Mocks - Stub .Expect vs .AssertWasCalled
body: <p>OK, I know there has been a lot of confusion over the new AAA syntax in Rhino Mocks, but I have to be honest, from what I have seen so far, I like. It reads better, and saves on some keystrokes.</p>
  
  <p>Basically, I am testing a <code>ListController</code> which is going to basically be in charge of some lists of things :) I have created an interface which will eventually become the DAL, and this is of course being stubbed for now.</p>
  
  <p>I had the following code:</p>
  
  <p>(<code>manager</code> is the system under test, <code>data</code> is the stubbed data interface)</p>
  
  <pre class="lang-cs prettyprint-override"><code>    [Fact]
      public void list_count_queries_data()
      {
          data.Expect(x =&gt; x.ListCount(1));
          manager.ListCount();
          data.VerifyAllExpectations();
      }
  </code></pre>
  
  <p>The main aim of this test is to just ensure that the manager is actually querying the DAL. Note that the DAL is not actually even there, so there is no "real" value coming back..</p>
  
  <p>However, this is failing since I need to change the expectation to have a return value, like:</p>
  
  <pre class="lang-cs prettyprint-override"><code>        data.Expect(x =&gt; x.ListCount(1)).Return(1);
  </code></pre>
  
  <p>This will then run fine, and the test will pass, <strong>however</strong> - what is confusing me is that at this point in time, the return value means <strong>nothing</strong>. I can change it to 100, 50, 42, whatever and the test will always pass?</p>
  
  <p>This makes me nervous, because a test should be explicit and should totally fail if the expected conditions are not met right?</p>
  
  <p>If I change the test to (the "1" is the expected ID the count is linked to):</p>
  
  <pre class="lang-cs prettyprint-override"><code>    [Fact]
      public void list_count_queries_data()
      {
          manager.ListCount();
          data.AssertWasCalled(x =&gt; x.ListCount(1));
      }
  </code></pre>
  
  <p>It all passes fine, and if I switch the test on it's head to <code>AssertWasNotCalled</code>, it fails as expected.. I also think it reads a lot better, is clearer about what is being tested and most importantly PASSES and FAILS as expected!</p>
  
  <p>So, <strong>am I missing something in the first code example?</strong> What are your thoughts on making assertions on stubs? (there was some interesting discussion <a href="http://ayende.com/Blog/archive/2008/06/29/Rhino-Mocks-3.5-Design-Decisions-The-role-of-Stub-vs.aspx" rel="nofollow noreferrer">here</a>, I personally liked <a href="http://ayende.com/Blog/archive/2008/06/29/Rhino-Mocks-3.5-Design-Decisions-The-role-of-Stub-vs.aspx#23872" rel="nofollow noreferrer">this response</a>.</p>