Effort offers a solution for the hard to (unit)test Data Access Logic in your application. Effort is basically an ADO.NET provider that executes all the data operations on a lightweight in-process main memory database instead of a traditional external database.
From the Codeplex site:
What is Effort?
Effort is an easy-to-use tool that enables a robust way of testability for applications that rely on Entity Framework.Where does the name come from?
Effort is an acronym of Entity Framework Fake ObjectContext Realization Tool. Obviously it is also able to work with DbContext objects.How does it work?
It emulates the relational database server with a completely .NET based lightweight in-memory database. All the data operations are redirected to it, so the tests can run completely in-process.
Getting started
- Create an Entity Framework DbContext like you’re used to(Model First, Code First,… it doesn’t matter):
- Add a second constructor to the DbContext class that allows you to specify a connection string:
- Include the Effort library to your project using NuGet.
- A fake database also requires fake data. Effort allows you to populate the database using CSV files. The first line contains the name of the table fields; each remaining line represents a data row. Each table requires its own CSV file named as {table name}.csv (e.g. in this case: Products.csv).
- Let’s now write our test and add some initialization logic to create the fake context and load the CSV data:
- And as a last step let’s write the test of course: