.ConfigureWebJobs
has an overload which accepts delegate of configureAppConfiguration
public static IHostBuilder ConfigureWebJobs(this IHostBuilder builder, Action<HostBuilderContext, IWebJobsBuilder> configure, Action<JobHostOptions> configureOptions, Action<HostBuilderContext, IWebJobsConfigurationBuilder> configureAppConfiguration)
Using that as below in test, I could run startup test successfully which calls ConfigureAppConfiguration
. Below is just a simple example. You can configure as per your need. Setting up the proper parameters is bit tricky to match Function interfaces.
My startup.cs:
[assembly: Microsoft.Azure.Functions.Extensions.DependencyInjection.FunctionsStartup(typeof(FunctionApp1.Startup))]
namespace FunctionApp1
{
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddSingleton(typeof(IMyInterface<,>), typeof(MyClass<>));
}
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
base.ConfigureAppConfiguration(builder);
}
}
}
My startup test:
namespace XUnitTestProject1
{
using FunctionApp1;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Moq;
using Xunit;
public class UnitTest1
{
[Fact]
public void StartupTest()
{
var functionConfigurationBuilderMock = new Mock<IFunctionsConfigurationBuilder>();
var startup = new Startup();
var host = new HostBuilder()
.ConfigureWebJobs((c, b) => startup.Configure(b),
null,
(c, b) => {
functionConfigurationBuilderMock.SetupGet(m => m.ConfigurationBuilder).Returns(b.ConfigurationBuilder);
startup.ConfigureAppConfiguration(functionConfigurationBuilderMock.Object);
})
.Build();
// Assert blah blah
}
}
}