I’m using Entity Framework 4, Ninject, and Moq throughout my projects. When I get to meat of my service classes where EF4 is used, I instantiate a data context – this is bad.
I want to inject the data context into my services so my unit tests can work against a mock data context. I’ve done this before with nHibernate but I can’t figure it out with EF4 and I can’t find a solid example online.
Can anyone point me to a working solution and examples? Thanks much!
The recommended approach is to use an in memory database to test against (using SQLite), similar to the technique for testing NHibernate as described in the NHibernate 3.0 cookbook.
You can also have a look here for a description of creating a fake DbContext.