public static AzureFunctionTestContext CreateFunctionTestContext <TFunction>(FunctionsStartup functionStartupInstance) where TFunction : class { //BBernard - this concept for Unit Testing the Pipeline + Dependencies for Azure Functions was inspired by the // blog article here: https://saebamini.com/integration-testing-in-azure-functions-with-dependency-injection/ var host = new HostBuilder() .ConfigureWebJobs(builder => { functionStartupInstance.Configure(builder); //Add the Function Type for easy Resolving of dependencies! builder.Services.AddScoped <TFunction>(); }) .Build(); return(new AzureFunctionTestContext(host)); }
/// <summary> /// Adds the given startup class into the service collection. This method can be called multiple times, and all startup /// classes will be used. /// Startup classes can contribute to logging, configuration sources, services, and application configuration. /// </summary> /// <param name="webHostBuilder">The web host builder to configure.</param> /// <param name="startup">The startup class to use.</param> /// <returns>The original builder, for method chaining.</returns> public static IWebHostBuilder UseFunctionsStartup( this IWebHostBuilder webHostBuilder, FunctionsStartup startup) => HostingInternals.AddStartup(webHostBuilder, startup);