단위 테스트에서 TLPContext를 만들면이 페이지의 아래 부분에 예외가 발생합니다.단위 테스트에서 내 DbContext를 만들 수 없습니다.
I는 단위 테스트에서 이런 짓을 :
DbContext context = new TLPContext();
context.Database.CreateIfNotExists();
이 올바른 접근 방식 아닌가?
연결 문자열/공급자에 어떤 문제가 있습니까?
난이 따랐다 : http://www.thereforesystems.com/turn-on-msdtc-windows-7/
하지만 재부팅 후 도움이되지 않았다.
내 단위 테스트 프로젝트에서 내 app.config 파일을 한게 ... 내 DbContext입니다
이<?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>
, DB가 아닌 테이블을 생성하기에 충분합니다
public class TLPContext : DbContext
{
}
그것은 예외입니다 :
내 단위 테스트에서 TLPContext 인스턴스를 만들 때 SetUp :
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)
argh ... TLPContext() : base ("DefaultConnection") 전에 app.config에있는 connectionstring의 name 속성 값이기도합니다. 흠 ... 지금은 이상하게 작동합니다. 아마도 SaveChanges가 처음으로 호출 될 때 DB가 실제로 생성되기 때문에 context.Database.CreateIfNotExists 메서드를 사용하지 않을 수도 있습니다. 어쨌든 이제는 작동합니다. 감사합니다! – Elisabeth