Entity Framework Fake ObjectContext Realization Tool

With Effort (Entity Framework Fake ObjectContext Realization Tool) I can create integration tests for the datalayer in my project. The tool has an Entity Framework provider that works on an in-memory database. This means I can call SaveChanges without mocking it or having a dependency on a real database. It can be run during build.

Installation is easy with the package manager from visual studio.

install-package effort.ef6

Data used in the tests can be loaded from all kinds of sources. I’m loading my testdata from CSV files. The proces is based on naming convention. So the name of the csv file is the name of the table the data is loaded into.

// Load CSV files
var directory = AppDomain.CurrentDomain.BaseDirectory;
var importer = new CsvDataLoader(directory);
// create connection to the in-memory database
return Effort.DbConnectionFactory.CreateTransient(importer);

Remember to deploy the csv files on build by setting “copy if newer” and adding the DeploymentItem attributes on the TestClass/TestMethod. This way I can store the files in a subfolder and deploy them to the BaseDirectory for easy loading.

[TestClass]
[DeploymentItem(@"initialData\table1.csv")]
public class MetaDataToolContextTest {
    // ... 
}

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s