Mar*_*tin 7 c# asp.net integration-testing asp.net-core
在我的集成测试中,我使用一个TestServer类来为我的集成测试工作一个测试服务器实例.在RC1中,我使用以下代码实例化它:
var server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>());
Run Code Online (Sandbox Code Playgroud)
在RC2上,TestServer.CreateBuilder()已被删除.因此,我尝试使用以下代码创建一个新的TestServer:
var server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
Run Code Online (Sandbox Code Playgroud)
我面临的问题是在RC2之后,运行时无法解析DI的依赖关系,因此它会在Startup类的Configure方法上抛出异常.但是,如果我启动实际服务器(而不是测试项目),系统会启动.抛出的异常如下:
System.Exception : Could not resolve a service of type 'ShikashiBot.IShikashiBotManager' for the parameter 'botManager' of method 'Configure' on type 'ShikashiBot.Startup'.
Run Code Online (Sandbox Code Playgroud)
我目前正在为测试主机使用以下软件包: Microsoft.AspNetCore.TestHost": "1.0.0-rc2-final
我需要进行一些更改才能让你的回购工作:
appsettings.sample.json来appsettings.json,我想这仅仅是因为它不是在源代码控制."buildOptions": { "copyToOutput": [ "appsettings.json" ] }到project.json该IntegrationTests项目.Verbose到Debug你appsettings.json.但在此之后,集成测试EndPointsRequiresAuthorization经过了依赖注入,而对我来说,在失败的异常ShikashiBotManager,我猜是因为我没有Postgre DB成立做.
对于你来说,它之前已经失败了,因为它无法解析IShikashiBotManager界面,对吧?
您是否可以尝试使用git clean -xfd(注意:您的未提交的本地更改将被删除)完成对本地存储库的清除,重建并重试?
| 归档时间: |
|
| 查看次数: |
878 次 |
| 最近记录: |