I'm trying to stub a call to db. The basic idea is for a line of code like this:
Person person = (from p in this.Entities.FindPerson("Smith") select p).FirstOrDefault();
to return an object the way I want it without going of to db. FindPerson(string) represents a stored proc (just in case).
I tried to overwrite FindPerson but I need to return ObjectResult. It's a sealed class with no public constructors. All my attempts to create it ended with a call to db.
I was looking for an answer for the same question. Following forum thread cleared it out for me: msdn forum
Basically they are saying to not make calls to EF directly, but to make your code testable by abstracting your data layer from your business layer.
You can do this by Repository pattern or something similar and then use Dependency Injection to inject a mock.
Quote from Peli (Microsoft employee, involved in the "Pex" program):
HTH
Cheers