集成测试迁移到ASP.NET核心RC2后破 [英] Integration tests broken after migrating to ASP.NET Core RC2

查看:214
本文介绍了集成测试迁移到ASP.NET核心RC2后破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的集成测试,我使用了一个 TESTSERVER 类朝我的集成测试的测试服务器实例工作。在RC1,我实例化它使用下面的代码:

In my integration tests, I use a TestServer class to work towards a test server instance for my integration tests. In RC1, I instanciated it using the following code:

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

在RC2,TestServer.CreateBuilder()被删除。所以,我尝试使用下面的代码来创建一个新的TESTSERVER:

On RC2, TestServer.CreateBuilder() was removed. Therefore, I tried to create a new TestServer using the following code:

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



我现在面临的问题是,RC2后,运行时无法解析依赖关系DI,所以它抛出的配置方法,启动类例外。如果我开始实际的服务器(而不是测试项目)系统却没有启动。引发的异常是如下:

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. 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'.



我目前使用下面的包测试主机:微软。 AspNetCore.TestHost:1.0.0-RC2决赛

推荐答案

我需要一些改变让你的回购工作:

I needed some changes to get your repo to work:


  1. 我不得不重新命名 appsettings.sample.json appsettings.json ,我想这仅仅是因为它不是在源代码控制。

  2. 我不得不添加buildOptions:{copyToOutput:[appsettings.json]} project.json

  3. 不得不改变你的<$ C $日志级别详细调试 C> appsettings.json

  1. I had to rename appsettings.sample.json to appsettings.json, I guess this is just because it's not in source control.
  2. I had to add "buildOptions": { "copyToOutput": [ "appsettings.json" ] } to the project.json of the IntegrationTests project.
  3. Had to change the log level Verbose to Debug in your appsettings.json.

但毕竟这集成测试 EndPointsRequiresAuthorization 穿过依赖注入,对我来说失败,并在 ShikashiBotManager ,我猜是因为我没有Postgre数据库建立做。结果
对你来说这之前就已经失败了,因为它无法解析 IShikashiBotManager 接口,对吧?

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.
For you it already fails before this, because it cannot resolve the IShikashiBotManager interface, right?

您可以尝试做你的本地仓库的一个完整的清洗与 git的清洁-xfd 注意:您不是本地COMMITED变化将删除),重建并再试一次?

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?

这篇关于集成测试迁移到ASP.NET核心RC2后破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆