Getting started with TDD and the repository pattern, I'm wondering if it makes any sense testing this...
Using the repository pattern, I have this interface:
public interface ICustomerRepository
{
IList<Customer> List();
Customer Get(int id);
}
I have like 50 different entities, so 50 different repository interfaces/implementations.
My question is if it's correct to test each repository, by mocking up the interface, like:
[TestMethod]
public void List_Should_Return_Two_Customers()
{
// Arrange
var customerr = new List<Customer>();
customer.Add(new Customer());
customer.Add(new Customer());
var repository = new Mock<ICustomerRepository>();
repository.Setup(r => r.List()).Returns(customer);
// Assert
Assert.AreEqual(2, repository.Object.List().Count);
}
[TestMethod]
public void Get_Should_Return_One_Customer()
{
// Arrange
var customer = new List<Customer>();
customerr.Add(new Customer() { Id = 1 });
customerr.Add(new Customer() { Id = 2 });
var repository = new Mock<ICustomerRepository>();
repository.Setup(r => r.Get(1)).Returns(customer.Where(w => w.Id == 1).First());
// Assert
Assert.IsTrue(repository.Object.Get(1).Id == 1);
}
Does it make any sense testing a fake implementation of these interfaces? To me it does not.