title: Testing a interface repository
body: <p>I was wondering what I should test and how I should test an IRepository. </p>
  
  <p>At the moment I created a MemoryRepository in my domain and I am testing that with fake data. I am not sure if this is correct though. Feels a little weird to first create some data and then test to see if the repository returns it correctly.</p>
  
  <p>This is what my MemoryRepository looks like:</p>
  
  <pre><code>public class MemoryRepositoryUser : IRepositoryUser
  {
      List&lt;User&gt; fakeUsers;       
  
      public MemoryRepositoryUser(List&lt;User&gt; fakeUsers)
      {
          this.fakeUsers = fakeUsers;
      }
  
      public IEnumerable&lt;User&gt; GetAll()
      {
          return fakeUsers;
      }
  
      public User GetById(string id)
      {
          return GetAll().Where(u =&gt; u.Username == id).Single();
      }
  }
  </code></pre>
  
  <p>These are some tests I wrote:</p>
  
  <pre><code>[TestFixture]
  class TestMemoryRepositoryUser
  {
      private MemoryRepositoryUser repository;
  
      public TestMemoryRepositoryUser(){
          repository = new MemoryRepositoryUser(FakeData.GetFakeUsers());
      }
  
      [Test]
      public void Get_All_Users()
      {
          var Users = repository.GetAll();
          Assert.IsNotNull(Users);
          Assert.IsInstanceOf(typeof(IEnumerable&lt;User&gt;), Users);
          Assert.AreEqual(3, Users.Count());
      }
  
      [Test]
      public void Get_User_By_ID()
      {
          var Username = "Bob";
          var User = repository.GetById(Username);
          Assert.IsNotNull(User);
          Assert.AreEqual(Username, User.Username);
      }
  }
  </code></pre>
  
  <p>I am pretty new to testing code and I mostly have problems with what I should test. I guess testing a MemoryRepository helps me to create all the features I need in the interface without having to talk to a database?</p>