C# NUnit:Effort.Exceptions.EffortException:Effort库无法自动注册其提供程序,因此需要手动注册

C# NUnit:Effort.Exceptions.EffortException:Effort库无法自动注册其提供程序,因此需要手动注册,c#,asp.net-web-api,nunit,effort,C#,Asp.net Web Api,Nunit,Effort,我正在开发Web API,在使用NUnit进行单元测试时,我遇到了以下错误: Tests.DemoTest.SessionLogOnBreakdownTest: SetUp : Effort.Exceptions.EffortException : The Effort library failed to register its provider automatically, so manual registration is required. a) Call the Effort.Pro

我正在开发Web API,在使用NUnit进行单元测试时,我遇到了以下错误:

Tests.DemoTest.SessionLogOnBreakdownTest:
SetUp : Effort.Exceptions.EffortException : The Effort library failed to register its provider automatically, so manual registration is required.

a) Call the Effort.Provider.EffortProviderConfiguration.RegisterProvider() method at entry point of the application

or

b) Add the following configuration to the App.config file:
   <system.data>
      <DbProviderFactories>
         <add name="Effort.Provider"
              invariant="Effort.Provider"
              description="Effort.Provider"
              type="Effort.Provider.EffortProviderFactory, Effort" />
      </DbProviderFactories>
   </system.data>
  ----> System.Configuration.ConfigurationErrorsException : Failed to find or load the registered .Net Framework Data Provider.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
\u dbConnection=Effort.DbConnectionFactory.CreateTransient()处引发错误

我遵循了例外情况提出的两项建议。但都不管用

我尝试过的事情:

  • 异常帮助器中的这两个建议
  • 更新包-重新安装工作

在使用EF6(6.4.0-6.4.4)和efforce.EF6 2.2.10的.Net 4.6.1应用程序中,我也看到了这种情况。我尝试过几种不同的版本组合,但通过VS中的测试浏览器可以看到它是随机发生的,而通过dotnet测试几乎是一致的。注意:我已经尝试了错误消息中建议的A、B和A&B解决方案。

除非重新编译NUnit,否则您不能尝试建议(A),这是本例中的“应用程序”。建议(B)是您的最佳选择。您必须更改测试的配置,而不是应用程序的App.config。您的测试配置类似于my.test.assembly.config。
[TestFixture]
public class DemoTest : TestBase
{
    private TestContext _context;
    private DbConnection _dbConnection;

    [SetUp]
    public void Initialization()
    {
        //Effort.Provider.EffortProviderConfiguration.RegisterProvider();
        _dbConnection = Effort.DbConnectionFactory.CreateTransient();
        _context = new TestContext(_dbConnection);
    }

    [Test]
    public void SessionLogOnBreakdownTest()
    {
         //code which uses _context
    }
}