Repository and Unit of Work for Entity Framework (EF4) for Unit Testing
If you are not familiar with the Unit of Work pattern you should firt look at Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application (9 of 10). It's a great article that demonstrates what the Unit of Work pattern can do.
Unfortunately, that article uses a different version of Entity Framework. I am using the default tools that come with Visual Studio and didn't want to modify the project too greatly so for me, the code wasn't usable. I also wanted to expose the IQueryable interface which as a side effect also simplified my Repository design.
By using a Repository Pattern you'll find unit testing is now possible and quite easy to write. This illustration (taken from asp.net) shows the differences between No Repository and the Repository Pattern. Notice how there are no Unit Tests in the No Repository section also note the "Alternative Persistence Medium" node (this is where our MemoryRepository comes in).