2

Is it possible to mock an EF model so that I can test code which uses the model classes without getting rid of LINQ to Entities code strewn throughout my project? Or will it be necessary to set up a test database for the model to hit instead?

1
  • See my answer for the question Mock Entity Framework database. A mock object context can be created from your entity model using a T4 template. This is the way the regular POCO classes are created, and it can be extended pretty easily to create a mock object context and interface to make it swappable with your concrete object context. Commented Jan 18, 2013 at 19:57

1 Answer 1

2

You could wrap your LINQ code in Data Access Objects. The DAOs would have separate interface and implementation code. Your test code would mock the DAOs.

If you don't want to do that, you'll need a test DB.

Sign up to request clarification or add additional context in comments.

3 Comments

Since I'm not a hardcore TDD type, this sounds overly complicated just to test some systems I'm currently working on. Shame EF wasn't designed to be easily testable!
EF v2 will not suffer from these complications. We'll be able to do unit testing against POCO objects and lose less hair.
Even when creating another layer, how would you perform save operation - as EF uses mMamDbEntities.SaveChanges(); after Entity reference has been chnaged

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.