title: Unit Testing functions within repository interfaces - ASP.net MVC3 & Moq
body: <p>I'm getting into writing unit testing and have implemented a nice repository pattern/moq to allow me to test my functions without using "real" data. So far so good.. However..</p>
  
  <p>In my repository interface for "Posts" <code>IPostRepository</code> I have a function:
  <code>Post getPostByID(int id);</code>
  I want to be able to test this from my Test class but cannot work out how.</p>
  
  <p>So far I am using this pattern for my tests:</p>
  
  <pre><code>[SetUp]
  public void Setup()
  {
      mock = new Mock&lt;IPostRepository&gt;();
  }
  
  [Test]
  public void someTest()
  {
      populate(10);  //This populates the mock with 10 fake entries
  
      //do test here
  }
  </code></pre>
  
  <p>In my function "someTest" I want to be able to call/test the function <code>GetPostById</code>. I can find the function with <code>mock.object.getpostbyid</code> but the "object" is null.</p>
  
  <p>Any help would be appreciated :)</p>
  
  <p>iPostRepository:</p>
  
  <pre><code>public interface IPostRepository
  {
      IQueryable&lt;Post&gt; Posts {get;}
  
      void SavePost(Post post);
      Post getPostByID(int id);
  }
  </code></pre>