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):
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):