Once your module checks the logic with the IQueryable provided by EF, you simply cannot test it with unit tests, taunting EF. This will always result in a switch from linq-to-entity to linq-to-objects. In the case of something simplified, the right way to handle this in unit test is fake, not layout. A fake will mimic a dependency behavior. In this case, writing a fake means writing an EF provider that works with the collection in memory, just like a real provider works with a database. Writing such a provider is probably the project itself.
Because of this, as soon as your logic contains linq-to-entities queries, you should always test it with integration tests or reorganize the code so that the query itself is in a separate method (verified by integration tests), and the old logic now has a dependency on a class containing this method instead of EF itself - this leads to a repository template where IQueryalbe not displayed, but the repository provides a method for each required query that runs on an entity. I personally do not like such repositories. Here is a recent discussion about various repository implementations.
If you decide to use integration tests that modify the database in memory, then with EFv4.1 and the code, you can first change the code for connecting to SQL Compact 4, and it will work (if you do not use any special direct SQL calls or requires some special SQL types when matching). In the case of EF with an EDMX file, this will not work because the EDMX file is closely related to the exact version of the database. Having a special EDMX for unit testing only is not an option because you will be testing another code again.
Related questions are asked here to discuss problems with unit testing EF code and repositories.
Ladislav Mrnka
source share