title: What is the purpose of unit testing an interface repository
body: <p>I am unit testing an <code>ICustomerRepository</code> interface used for retrieving objects of type <code>Customer</code>.</p>
  
  <ul>
  <li>As a unit test what value am I gaining by testing the <code>ICustomerRepository</code> in this manner?</li>
  <li>Under what conditions would the below test fail?</li>
  <li>For tests of this nature is it advisable to do tests that I know should fail? i.e. look for id <code>4</code> when I know I've only placed <code>5</code> in the repository</li>
  </ul>
  
  <p>I am probably missing something obvious but it seems the integration tests of the class that implements <code>ICustomerRepository</code> will be of more value.</p>
  
  <pre><code>[TestClass]
  public class CustomerTests : TestClassBase
  {
      private Customer SetUpCustomerForRepository()
      {
          return new Customer()
          {
              CustId = 5,
              DifId = "55",
              CustLookupName = "The Dude",
              LoginList = new[]
              {
                  new Login { LoginCustId = 5, LoginName = "tdude" },
                  new Login { LoginCustId = 5, LoginName = "tdude2" }
              }
          };
      }
  
      [TestMethod]
      public void CanGetCustomerById()
      {
          // arrange
          var customer = SetUpCustomerForRepository();
          var repository = Stub&lt;ICustomerRepository&gt;();
  
          // act
          repository.Stub(rep =&gt; rep.GetById(5)).Return(customer);
  
          // assert
          Assert.AreEqual(customer, repository.GetById(5));
      }
  }
  </code></pre>
  
  <p>Test Base Class</p>
  
  <pre><code>public class TestClassBase
  {
      protected T Stub&lt;T&gt;() where T : class
      {
          return MockRepository.GenerateStub&lt;T&gt;();
      }
  }
  </code></pre>
  
  <p>ICustomerRepository and IRepository</p>
  
  <pre><code>public interface ICustomerRepository : IRepository&lt;Customer&gt;
  {
      IList&lt;Customer&gt; FindCustomers(string q);
      Customer GetCustomerByDifID(string difId);
      Customer GetCustomerByLogin(string loginName);
  }
  
  public interface IRepository&lt;T&gt;
  {
      void Save(T entity);
      void Save(List&lt;T&gt; entity);
      bool Save(T entity, out string message);
      void Delete(T entity);
      T GetById(int id);
      ICollection&lt;T&gt; FindAll();
  }
  </code></pre>