当我在单元测试中创建我的 TLPContext 时,我在此页面底部收到一个异常。
我在单元测试中这样做了:
DbContext context = new TLPContext();
context.Database.CreateIfNotExists();
这不是正确的方法吗?
我的连接字符串/提供程序有什么问题?
我遵循了这个:http ://www.thereforesystems.com/turn-on-msdtc-windows-7/
但重新启动后它没有帮助。
这就是我的单元测试项目中的 app.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<connectionStrings>
<add name="TLPContext" providerName="System.Data.SqlClient" connectionString="Data Source=LISA\SQLEXPRESS;Initial Catalog=TLPTEST;Integrated Security=True;Pooling=False;"/>
</connectionStrings>
</configuration>
那是我的 DbContext,它应该足以创建数据库而不是表......
public class TLPContext : DbContext
{
}
那是我得到的例外:
当我在单元测试 SetUp 中创建 TLPContext 实例时:
Test 'TLP.DataAccess.UnitTests.GenericRepositoryTests.Test' failed: System.Data.ProviderIncompatibleException : An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
---- System.Data.ProviderIncompatibleException : Der Anbieter hat keine ProviderManifestToken-Zeichenfolge zurückgegeben.
-------- System.Data.SqlClient.SqlException : MSDTC on server 'LISA\SQLEXPRESS' is unavailable.
at System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
at System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)