views:

544

answers:

1

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?

+2  A: 

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.

sblundy
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!
Chris Charabaruk
EF v2 will not suffer from these complications. We'll be able to do unit testing against POCO objects and lose less hair.
Dave Swersky