Repository pattern in C# – Different Implementations for real and test classes

I'm looking at an explanation of this pattern here.

The writer is showing the implementation of two versions of a class (in the first part before talking about generics):

class CustomerRepository:ICustomerRepository class TestCustomerRepository:ICustomerRepository 

In the implementation, for example in the method

public Customer SelectByID(string id) 

he shows two different possibilities:

return db.Customers.Find(id); return data.Find(m => m.CustomerID == id); 

My question is, if I use the second one for unit testing, how will I be sure that the non-test version will work? Even if I step through in debug mode, with all the changes that happen the logic can get out of sync.

Is my concern legitimate? Is this a bad example?

Thanks,

by 0xZV2Rkm via /r/csharp

Leave a Reply