EF4 - Can I make fun of ObjectContext for unit testing?

Can this be done without using TypeMock Islolator? I found several suggestions on the Internet, such as passing only connection strings for metadata only, however, anything I came across besides TypeMock seems to really allow an ObjectContext layout that can be injected into services for unit testing. Am I laying in $$ for TypeMock, or are there alternatives? Couldn't create something comparable to TypeMock open source?

+7
entity-framework mocking objectcontext typemock
source share
4 answers

I am testing modular EF4 without laughing. What I did was create a repository interface using the code http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/ as the basis . Then I created an InMemoryRepository<T> class that used IRepository . Then I replaced IObjectSet<T> with List<T> inside the class and changed the search methods accordingly.

Thus, if you need to do unit testing, go to InMemoryRepository and not to DataRepository.

+4
source share

Put your Linq2Entity query behind the interface, unit test it is isolated from the real database.

Write tests for your business logic using mocks for your query interfaces. Do not let Linq enter your business logic!

Do not use RepositoryPattern!

+3
source share

Wrap an ObjectContext in a proxy class. Then enter this into your classes.

+1
source share

I don't think the repository template is the only answer to the question (it avoids the problem, of course)

I liked this answer - I find it more suitable for introducing tests into the existing code base Creating an interface for ObjectContext

0
source share

All Articles