尝试在Visual Studio 2017中运行测试时,所有编译都没有问题, 但是,当我尝试创建服务器和客户端进行测试时:
this.Server = new TestServer(
new WebHostBuilder()
.UseStartup<Startup>()
.UseContentRoot(di.FullName));
this.Client = this.Server.CreateClient();
TestServer
抱怨错误的依赖关系(它试图加载版本1.0.0),即使TestHost
包是:
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.1" />
测试失败也是例外:
Cannot find method: 'System.Net.Http.HttpClient Microsoft.AspNetCore.TestHost.TestServer.CreateClient()'..
答案 0 :(得分:12)
与VS 2017中的错误测试模板有关
手动添加到顶部<PropertyGroup>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
csproj
文件中的修复了问题