Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

WebApplicationFactory calls Startup.ConfigureServices after ConfigureWebHost blowing away testing configuration. #8262

@CzechsMix

Description

@CzechsMix

Is this a Bug or Feature request?:

Either bug or I'm not using as intended.

Steps to reproduce (preferably a link to a GitHub repo with a repro project):

  1. Create subclass of WebApplicationFactory
  2. Override WebApplicationFactory.ConfigureWebHost and configure testing specific services
  3. Debug tests with breakpoints in TStartup.ConfigureServices

Description of the problem:

I'm using a custom subclass of WebApplicationFactory in order to wire up testing services (namely, a allow any authentication scheme and custom user service) however, after the testing services are configured the base startup classes configure method is called, effectively blowing away my test services
and using real authentication and a real user service.

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All:

Microsoft.AspNetCore.App 2.1.2

It seems intuitive to me that the startup classes configuration should be executed first, and the custom web application's factory then has the option to override the applications production configuration, but if I'm using this incorrectly, then I'd like some guidance on how to do this.

I tried using an testing specific startup class, but then Mvc couldn't find my controllers and all routes returned 404.

right now I have an ugly hack where the integration test sets the environment to "Testing" and the startup class ConfigureServices method returns immediately if environment is "Testing"

Would really like to avoid adding any testing code to my main application project.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions