title: Unit test to check if an action method called the service layer
body: <p>I have a controller called NewsController, the constructor of this controller receives an INewsService as parameter.</p>
  
  <p>I have a method in this controller called GetAllNews() that returns a JSON result that I use to populate a YUI datatable.  I want to write a unit test that checks if the news service's FindAll method was called to return all the news items.  How would I do this?  What I currently have is:</p>
  
  <pre><code>public JsonResult GetAllNews()
  {
     var items = newsService.FindAll();
     var jsonResult = Json(items);
  
     return jsonResult;
  }
  </code></pre>
  
  <p>My unit test for the controller looks like:</p>
  
  <pre><code>public NewsControllerTest()
  {
     newsServiceStub = MockRepository.GenerateStub&lt;INewsService&gt;();
     newsController = new NewsController(newsServiceStub);
  }
  
  [Test]
  public void GetAllNews_should_use_news_service()
  {
     // Arrange
     List&lt;News&gt; newsList = new List&lt;News&gt;();
     newsServiceStub.Stub(s =&gt; s.FindAll()).Return(newsList);
  
     // Act
     var actual = newsController.GetAllNews();
  
     // Assert
     newsServiceStub.VerifyAllExpectations();
  }
  </code></pre>
  
  <p>The test passes with the above code.  But if I were to change GetAllNews() to look like below then it also passes.  Shouldn't it fail?  What I am trying to test is if GetAllNews() uses the news service:</p>
  
  <pre><code>public JsonResult GetAllNews()
  {
     return null;
  }
  </code></pre>