MetallixBrother
✅ 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
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 WebApplicationFactory
and override ConfigureWebHost
to specify AppConfig:Endpoint
to null, it stops attempting to connect to Azure App Configuration, but then it fails validation of the option.
- The configuration occurs before WebApplicationFactory.ConfigureTestServices
is called, so any manipulation of the option there would fail.78 replies