Is it possible to accomplish that without TypeMock Isolator? There are a few alternatives I've read online, including using a connection string that simply contains metadata, but none of them, apart from TypeMock, appear to allow for the injection of a mock ObjectContext into services for unit testing. Do I spend the money on TypeMock, or are there other options? Has someone succeeded in developing an open source alternative to TypeMock?
I can test EF4's units without the need for mimicking. Making use of the code from http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/ as a starting point, I constructed a repository interface.
a class using the
interface. Then I changed the
and adjusted the retrieval techniques inside the lesson.
Therefore, pass in the InMemoryRepository rather than the DataRepository if you need to do unit testing.
Put your Linq2Entity query behind an interface and do isolation-only unit testing on it using a live database.
Mock up your query interfaces and write tests for your business logic. Keep Linq out of your business logic!
Use of RepositoryPattern is prohibited.