我们最近在 Azure Functions 中添加了 Azure 应用配置,现在我们希望通过测试触发应用配置的启动代码。
我们的函数启动代码如下所示——
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);
}
使用以下命令运行测试时触发初始配置方法 -
private MyFunction_sut;
[SetUp]
public void Setup()
{
var funcStartup = new Startup();
var host = new HostBuilder()
.ConfigureWebJobs(funcStartup.Configure)
.Build();
_sut = new MyFunction(...);
}
这适用于触发配置方法。尽管 HostBuilder 有 ConfigureAppConfiguration 选项,但我不知道如何让它工作。我觉得我在下面放的东西应该有一种快速简便的方法。
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();
如果有另一种方法来测试 Azure Functions 以添加到不涉及 HosatBuilder 的 Azure 应用程序配置中,那么我很想听听其他人的方法。在网上搜索时,我真的看不到太多,所以我觉得我错过了一些东西。
任何建议表示赞赏!