小编dam*_*pee的帖子

无法加载实体框架提供程序类型?

我正在尝试在我的机器上安装的TeamCity上运行我的测试.

System.InvalidOperationException:

实体框架提供程序类型" 为" 'ADO.NET提供程序无法加载.确保提供程序程序集可用于正在运行的应用程序.System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServerVersion=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'System.Data.SqlClient

有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882.

我没有参考System.Data.Entity任何我在codeplex上建议升级到EF6的项目.

所以,我不知道为什么我会得到这个例外.当我从VS运行测试时,我没有得到任何这样的异常.

我确实尝试将CopyLocal设置为false然后再次设置为true ..但这似乎也不起作用.

更新

我的app.config有以下内容.这会导致一些我不理解的行为吗?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我在teamcity中得到以下stacktrace.

[MSTest] IntegrationTests.CrudTest+QuestionTest.Create
[03:59:11][IntegrationTests.CrudTest+QuestionTest.Create] Initialization method IntegrationTests.CrudTest+QuestionTest.Initialize threw exception. System.InvalidOperationException: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' …
Run Code Online (Sandbox Code Playgroud)

c# mstest entity-framework teamcity-7.1 entity-framework-6

406
推荐指数
11
解决办法
26万
查看次数

如何在AutoMock(Moq)中使用Lazy <>

我们正在使用Autofac.Extras.Moq.AutoMock.现在我使用Lazy <>有一个构造函数依赖

public MyService(Lazy<IDependency> myLazyDependency) {...}
Run Code Online (Sandbox Code Playgroud)

测试MyService我们需要嘲笑Lazy<Dependency>.

我正在尝试这个

[ClassInitialize]
public static void Init(TestContext context)
{
    autoMock = AutoMock.GetLoose();
}

[TestInitialize]
public void MyTestInitialize()
{
     var myDepMock = autoMock.Mock<Lazy<IDependency>>();  // <-- throws exception
}
Run Code Online (Sandbox Code Playgroud)

这是测试运行器返回的异常:

初始化方法Tests.MyServiceTests.MyTestInitialize引发异常.System.InvalidCastException:System.InvalidCastException:无法转换类型为'System.Lazy 1[IDependency]' to type 'Moq.IMocked1 [System.Lazy`1 [IDependency]]'的对象..

那么,我如何使用automock传递一个Lazy <>模拟对象.

c# mstest moq autofac automocking

4
推荐指数
1
解决办法
1213
查看次数

使用 autofac 在 SeriLog 丰富器中注入依赖项

我想创建一个Serilog Enricher,从依赖项注入一些数据。autofac 如何将我的依赖项注入到增强器中?

这是我的容器设置:

builder.Register((c, p) =>
{
  return new LoggerConfiguration()
   .Enrich.FromLogContext()
   .Enrich.With<MyEnricherWhichCanAddMoreDataFromADependency>()
   // ...
  .CreateLogger();
}).As<ILogger>();
Run Code Online (Sandbox Code Playgroud)

虽然浓缩器看起来像

public class MyEnricherWhichCanAddMoreDataFromADependency : ILogEventEnricher
{
    public MyEnricherWhichCanAddMoreDataFromADependency(IDependency d) 
    { ... do stuff with the dependency ... }
}
Run Code Online (Sandbox Code Playgroud)

构造函数注入似乎不起作用。还是我做错了什么?

autofac serilog

4
推荐指数
1
解决办法
1400
查看次数

如何在AutoFac上使用内部构造函数解析公共类

我有一个要在单元测试中实例化的类:

public class Customer
{
    internal Customer(Guid id) {
        // initialize property
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我用一个new Customer()作品从另一个(单元测试)程序集中实例化测试类,因为我添加了[assembly: InternalsVisibleTo("MyProject.Tests")]

var sut = new Customer(Guid.NewGuid()); // works
Run Code Online (Sandbox Code Playgroud)

但是当我在另一个(unittest)程序集中设置一个autofac容器时

var builder = new ContainerBuilder();
builder.RegisterType<Customer>().AsSelf();
var container = builder.Build();
Run Code Online (Sandbox Code Playgroud)

我用autofac无法解决。

var theParam = new NamedParameter("id", Guid.NewGuid());
_sut = container.Resolve<Customer>(theParam); // throws exception
Run Code Online (Sandbox Code Playgroud)

我最好的猜测是内部构造函数不可用。但是,添加[assembly: InternalsVisibleTo("Autofac")]到另一个旁边并没有帮助。

Autofac抛出的异常是

Autofac.Core.DependencyResolutionException: 
An error occurred during the activation of a particular registration. See the inner exception for details. 
Registration: Activator = Customer (ReflectionActivator), 
Services = …
Run Code Online (Sandbox Code Playgroud)

autofac

4
推荐指数
1
解决办法
389
查看次数

访问从linq到SQL的DataContext

我有一个linq2sql datacontext被处理掉了.但是当我检查null时,我总是有一个错误的条件.

DataClasses1DataContext dc = new DataClasses1DataContext();
dc.Dispose();
Run Code Online (Sandbox Code Playgroud)

其他一些代码

if (dc == null) {
    // ALWAYS FALSE
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能知道datacontext是否已被处理?

更新:让我澄清一下自己.我得到一个datacontext但有时外部代码传递一个对象(它不是null,但已经被处理掉了).我需要检查对象是否存在.我想的是别的东西,而不是试一试.

.net c# linq-to-sql

3
推荐指数
1
解决办法
1715
查看次数

如何从Rebus检查错误队列

我有一个运行良好的输入队列。有时,一条消息进入错误队列。现在,我希望能够检查这些消息,并且如果我知道此特定消息将通过,则可能再次将它们转发到输入队列。

我如何开始检查错误队列?有没有最佳做法?我不能只是做一个,.CreateBus().Start()因为这将从常规处理程序中触发处理程序。

rebus

3
推荐指数
1
解决办法
1073
查看次数