简体   繁体   中英

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. In RC1, I instanciated it using the following code:

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

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>());

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

I'm currently using the following package for the test host: 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.
  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 .

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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