简体   繁体   English

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

[英]Integration tests broken after migrating to ASP.NET Core RC2

In my integration tests, I use a TestServer class to work towards a test server instance for my integration tests. 在我的集成测试中,我使用TestServer类来为我的集成测试工作一个测试服务器实例。 In RC1, I instanciated it using the following code: 在RC1中,我使用以下代码实例化它:

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

On RC2, TestServer.CreateBuilder() was removed. 在RC2上,TestServer.CreateBuilder()已被删除。 Therefore, I tried to create a new TestServer using the following code: 因此,我尝试使用以下代码创建一个新的TestServer:

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

The problem I'm facing is that after RC2, the runtime is unable to resolve dependencies for DI, so that it throws exceptions on the Configure method for the Startup class. 我面临的问题是在RC2之后,运行时无法解析DI的依赖关系,因此它会在Startup类的Configure方法上抛出异常。 The system does however start up if I start the actual server (not the test project). 但是,如果我启动实际服务器(而不是测试项目),系统会启动。 The exception thrown is as following: 抛出的异常如下:

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

I'm currently using the following package for the test host: Microsoft.AspNetCore.TestHost": "1.0.0-rc2-final 我目前正在为测试主机使用以下软件包: Microsoft.AspNetCore.TestHost": "1.0.0-rc2-final

I needed some changes to get your repo to work: 我需要进行一些更改才能让你的回购工作:

  1. I had to rename appsettings.sample.json to appsettings.json , I guess this is just because it's not in source control. 我不得不将appsettings.sample.json重命名为appsettings.json ,我想这只是因为它不在源代码控制中。
  2. I had to add "buildOptions": { "copyToOutput": [ "appsettings.json" ] } to the project.json of the IntegrationTests project. 我不得不将"buildOptions": { "copyToOutput": [ "appsettings.json" ] }到IntegrationTests项目的project.json中。
  3. Had to change the log level Verbose to Debug in your appsettings.json . 不得不在appsettings.json日志级别Verbose更改为Debug

But after this the integration test EndPointsRequiresAuthorization goes through the dependency injection, and for me it fails with an exception in ShikashiBotManager , I guess because I don't have the Postgre DB set up. 但在此之后,集成测试EndPointsRequiresAuthorization会通过依赖注入,对我而言,它在ShikashiBotManager出现异常,我猜是因为我没有设置Postgre数据库。
For you it already fails before this, because it cannot resolve the IShikashiBotManager interface, right? 对于你来说,它之前已经失败了,因为它无法解析IShikashiBotManager接口,对吧?

Can you try to do a complete purge of your local repository with git clean -xfd ( NOTE : your not commited local changes will be deleted), rebuild and try again? 您是否可以尝试使用git clean -xfd对本地存储库进行完全清除( 注意 :您的未提交的本地更改将被删除),重建git clean -xfd试?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM