Effort unit testing Entity framework 6.1.3 DB-first

c# effort entity-framework unit-testing


I'm having issues unit testing my DB-layer using the Effort framework (version 1.1.4).

Due to the model's database-first construction and my use of Entity Framework 6.1.3, there is an*.edmx a model description file.

With the following effort, I have constructed a partial class to provide an additional constructor needed by the unit tests:

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

This is how a straightforward unit test looks:

    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);

The unit test throws an exception for the following line when I execute it:

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 articles I've read suggest changing theProviderManifestToken feature in the*.edmx from "2012" to "2008" in a file. When attempting to use the context for the first time here, this appears to address the issue but instead throws me another exception:

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.

Does anyone have any ideas on how to get around this so I can use Effort with the DB-first approach of entity framework 6.1.3?

I believe that the EF-version may be of interest because I have successfully used Effort (version 1.1.4) to unit test DB-layers created in EF 4 and EF 5 with DB-first method.

7/18/2016 8:31:33 PM

Accepted Answer

A coworker of mine discovered the answer to my problem!

It turns out that I was utilizing the "Effort" nuget package rather than the "Effort.EF6" nuget package. I had to update my app after removing it and installing the other. Setting up using 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" />

Additionally, I added a method to register the effort provider in the SetUp for my unit tests:

    public void Setup()

This provided me with a solution. Hope it can be of some assistance 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