We have recently added Azure App Configuration into our Azure Functions, and we now want the Startup code for the App Configuration to be triggered via the tests.
Our function startup code looks like this -
public override void Configure(IFunctionsHostBuilder builder)
{
config = Utils.LoadConfig();
StartupHelper.AddCommonIoCDependencies(builder);
}
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
//How do we trigger this method when testing???
StartupHelper.AddAzureAppConfiguration(builder);
}
The initial configure method is triggered when running tests by using the following -
private MyFunction_sut;
[SetUp]
public void Setup()
{
var funcStartup = new Startup();
var host = new HostBuilder()
.ConfigureWebJobs(funcStartup.Configure)
.Build();
_sut = new MyFunction(...);
}
This works for triggering the Congfigure method. And despite the HostBuilder having options for ConfigureAppConfiguration, I can't figure out how to get this working. I feel there should be a quick and easy way with what I've put below.
var host = new HostBuilder()
.ConfigureWebJobs(funcStartup.Configure)
.ConfigureAppConfiguration(x => {
//What do I put here to call trigger the ConfigureAppConfiguration method at startup?
//Or is it possible to call my helper "AddAzureAppConfiguration" method that is in a static class?
})
.Build();
If there's a different way to test Azure Functions to add in Azure App Configuration that doesn't involve HosatBuilder then I'd love to hear other people's approaches. I really can't see much for this when googling online, so I feel like I'm missing something.
Any advice is appreciated!