【发布时间】:2017-01-21 09:47:24
【问题描述】:
我的 Visual Studio 2015 有一个 MVC 5 项目。 我已经使用 ADO 实体数据模型首先创建了我的域模型数据库,并且我有一个自定义身份(我不知道它是否重要),直到这里一切正常。问题是当我开始创建我的 UnitTest 类时。首先我用鼠标右键单击并选择创建单元测试,所以我做了类似的事情
[TestMethod()]
public void PermissionsTest()
{
GroupController controller = new GroupController();
var result = controller.Permissions("1") as ViewResult;
Assert.AreEqual("Details", result.ViewName);
}
我也将我的 MVC 项目引用放入我的测试项目中,并更新了我的 app.config,添加了我在 MVC 项目中使用的连接字符串。 但我收到异常:
Result Message:
Test method Controllers.Tests.GroupControllerTests.PermissionsTest threw exception:
System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors:
Models.Domain.Models.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
那么有人可以帮助我吗?
根据 Wikitor 的建议,我的 app.config 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=****.****.com;Initial Catalog=LDC;Integrated Security=False;User ID=****;Password=****;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" providerName="System.Data.SqlClient" />
<add name="LDCEntities" connectionString="metadata=res://*/Models.Domain.LdcModels.csdl|res://*/Models.Domain.LdcModels.ssdl|res://*/Models.Domain.LdcModels.msl;provider=System.Data.SqlClient;provider connection string="data source=****.***.***;initial catalog=LDC;persist security info=True;user id=****;password=*****;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
【问题讨论】:
标签: c# asp.net-mvc entity-framework unit-testing