This white paper describes and demonstrates how to write testable code with the ADO.NET Entity Framework 4.0 and Visual Studio 2010. This paper does not try to focus on a specific testing methodology, like test-driven design (TDD) or behavior-driven design (BDD). Instead this paper will focus on how to write code that uses the ADO.NET Entity Framework yet remains easy to isolate and test in an automated fashion. We’ll look at common design patterns that facilitate testing in data access scenarios and see how to apply those patterns when using the framework. We’ll also look at specific features of the framework to see how those features can work in testable code.
Comments
BTW - Missed you at this year's Alt.Net Seattle - at least I didn't spot you.
I am having a problem with the "auto-inclusion" feature of EF4. That is, EF4 will detect that you have associated a new object via an existing objects properties: oldObject.Foo = new Foo() - this will get the new Foo to be added to the context.Foos during the SaveChanges. That makes my app run just fine but my tests do not see the new Foo when I try to confirm it was added (via the context.Foos collection). I have to also do a context.Foos.Add(theNewFoo) in my code.
Does that make any sense and what, if anything, should I be doing about it?
what did you can suggest in a modularity scenario about repository and UoW (dbContext) ? There could be some problem with entity separated in different modules.