Effort unit testing Entity framework 6.1.3 DB-first

c# effort entity-framework unit-testing


I am experiencing problems when using Effort framework (version 1.1.4) to unit test my DB-layer.

I have a DB-layer using Entity framework 6.1.3 and the model is created using database-first approach so there is an *.edmx file describing the model.

I have created a partial class to expose an additional constructor used by the unit tests with effort like this:

public partial class Entities
    public Entities(DbConnection connection)
        : base(connection, true)

The simple unit-test looks like this:

    private Entities CreateContext()
        //var connectionString = ConfigurationManager.ConnectionStrings["Entities"].ConnectionString;
        //var connection = Effort.EntityConnectionFactory.CreateTransient(connectionString);
        //return new Entities(connection as DbConnection);

        var connection = Effort.EntityConnectionFactory.CreatePersistent("name=Entities");
        var context = new Entities(connection);
        return context;

    public void Testing_Effort_Integration()
        using (var context = CreateContext())
            var entity = context.TableEntity.FirstOrDefault(i=> i.Id);

When I run the unit test it throws an exception for the line:

var connection  = Effort.EntityConnectionFactory.CreatePersistent("name=Entities");

{"The provider did not return a ProviderManifest instance."} InnerException Message: {"Could not determine storage version; a valid storage connection or a version hint is required."}

Other posts I have found suggests to change the ProviderManifestToken attribute in the *.edmx file from "2012" to "2008". This seems to solve the problem but instead gives my another exception when trying to use the context for the first time here:

var entity = context.TableEntity.FirstOrDefault(i=> i.Id);

NotSupportedException Unable to determine the provider name for provider factory of type 'System.Data.EntityClient.EntityProviderFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.

Anyone know how to solve this issue so I can use Effort with entity framework 6.1.3 DB-first approach?

I have successfully been able to use Effort (version 1.1.4) to unit test DB-layers created in EF 4 and EF 5 with DB-first approach - this is why I think that the EF-version can be of interest...

7/18/2016 8:31:33 PM

Accepted Answer

A colleague of mine found the solution to my issue!

Apparently I was using the "Effort" nuget package instead of the "Effort.EF6" nuget package. After uninstalling and installing the other I also had to update my App.Config with the tags:

      <add name="Effort.Provider" invariant="Effort.Provider" description="Effort.Provider" type="Effort.Provider.EffortProviderFactory,Effort" />  

      <provider invariantName="Effort.Provider" type="Effort.Provider.EffortProviderServices, Effort" />

And I also included a call in the SetUp for my unit tests to register the effort provider:

    public void Setup()

This solved the issue for my. Hopefully it can provide some help to others!

1/12/2016 1:55:14 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow