Unit Testing Entity Framework 6 DbContext

The Entity Framework version 6 has good unit testing possibilities and the documentation provided by MSDN provides a good starting point...



The main thing to remember is that you need to create a TestDbSet for each context property that is going to be used:

Then you can add data to your Entities as per usual when setting up the in memory datastore:

The MSDN documentation provides a TestDbSet class which provides a fake collection for the context properties (reproduced here for completeness):

Popular posts from this blog

A Simple 3 Layer Architecture

Parsing Visual Studio Files with Powershell