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 { // ... }