Thursday, June 27, 2013

Effort - Entity Framework Unit Testing Tool

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.

image

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

3 comments:

Cindy Dy said...

You are an awesome blogger. This is one of the best blog I had visited so far. Hope to read more post from you in the future. Keep it up. God bless.

Bubble
www.gofastek.com

Silvia Jacinto said...

Reading your article is such a privilege. It does inspire me, I hope that you can share more positive thoughts. Visit my site too. The link is posted below.

n8fan.net

www.n8fan.net

pravin k said...

Am not seeing the data loaded from the csv files, can you share the sample project.