✅ Overriding IConfigurationManager.GetSection for integration tests in .NET 8 Minimal API
Hi all,
In my application, I am optionally configuring Azure App Configuration. This is achieved by checking whether or not an endpoint has been provided in the configuration via
So far in my integration tests, I'm using
The problem that I'm encountering is that the value for the options are populated in
In my application, I am optionally configuring Azure App Configuration. This is achieved by checking whether or not an endpoint has been provided in the configuration via
IConfigurationManager (see code below).So far in my integration tests, I'm using
WebApplicationFactory to modify the services to external services.The problem that I'm encountering is that the value for the options are populated in
appsettings.Development.json. Ideally, I'd like to remove it from configuration prior to attempting to see if the endpoint is present. However, the approached that I've tried so far haven't yielded results;- If I create a custom
WebApplicationFactoryand overrideConfigureWebHostto specifyAppConfig:Endpointto null, it stops attempting to connect to Azure App Configuration, but then it fails validation of the option. - The configuration occurs before
WebApplicationFactory.ConfigureTestServicesis called, so any manipulation of the option there would fail.