迁移到 ASP.NET Core RC2 后集成测试中断

Integration tests broken after migrating to ASP.NET Core RC2

在我的集成测试中,我使用 TestServer class 来为我的集成测试创建一个测试服务器实例。在 RC1 中,我使用以下代码实例化了它:

var server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>());

在 RC2 上,TestServer.CreateBuilder() 已被删除。因此,我尝试使用以下代码创建一个新的 TestServer:

var server = new TestServer(new WebHostBuilder().UseStartup<Startup>());

我面临的问题是,在 RC2 之后,运行时无法解析 DI 的依赖关系,因此它会在 Startup class 的 Configure 方法上抛出异常。但是,如果我启动实际服务器(而不是测试项目),系统会启动。抛出的异常如下:

  System.Exception : Could not resolve a service of type 'ShikashiBot.IShikashiBotManager' for the parameter 'botManager' of method 'Configure' on type 'ShikashiBot.Startup'.

我目前正在为测试主机使用以下软件包:Microsoft.AspNetCore.TestHost": "1.0.0-rc2-final

我需要一些更改才能使您的存储库正常工作:

  1. 我不得不将 appsettings.sample.json 重命名为 appsettings.json,我想这只是因为它不在源代码管理中。
  2. 我必须将 "buildOptions": { "copyToOutput": [ "appsettings.json" ] } 添加到 IntegrationTests 项目的 project.json
  3. 必须将 appsettings.json 中的日志级别 Verbose 更改为 Debug

但在这之后集成测试 EndPointsRequiresAuthorization 通过依赖注入,对我来说它失败了 ShikashiBotManager,我猜是因为我没有设置 Postgre DB .
对你来说,在此之前它已经失败了,因为它无法解析 IShikashiBotManager 接口,对吗?

您可以尝试使用 git clean -xfd 完全清除您的本地存储库吗(注意:您未提交的本地更改将被删除),重建并重试?