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

Working in a DevOps team is the best thing that happened to me. 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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.