Either bug or I'm not using as intended.
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.
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.
Thanks for contacting us, @CzechsMix.
@javiercn. can you please look into this? Thanks!
@CzechsMix Thanks for reaching out.
ConfigureServices always gets called before Startup.ConfigureServices. I imagine that what you are doing is configuring some options type, for that. You can use ConfigureTestServices which will run after Startup.ConfigureServices.
Beware that there are some limitations on where ConfigureTestServices can be used, but as long as your Startup.ConfigureServices method has the following signature void ConfigureServices(IServiceCollection services)
you should be fine.
Let us know if this doesn't solve your issue.
Closing this issue as there's no more action to be taken here.
That appears to be exactly what I'm looking for, thank you!
Most helpful comment
@CzechsMix Thanks for reaching out.
ConfigureServices always gets called before Startup.ConfigureServices. I imagine that what you are doing is configuring some options type, for that. You can use ConfigureTestServices which will run after Startup.ConfigureServices.
Beware that there are some limitations on where ConfigureTestServices can be used, but as long as your Startup.ConfigureServices method has the following signature
void ConfigureServices(IServiceCollection services)
you should be fine.Let us know if this doesn't solve your issue.
Closing this issue as there's no more action to be taken here.