Integration Testing Azure Functions with Reqnroll and C#, Part 4 - Controlling your functions with additional configuration
TL;DR - This series of posts shows how you can integration test Azure Functions projects using the open-source Corvus.Testing.AzureFunctions.ReqnRoll library and walks through the different ways you can use it in your Reqnroll projects to start and stop function app instances for your scenarios and features.
In the previous posts in this series, we introduced the Corvus.Testing.AzureFunctions.ReqnRoll project and showed how you can use the bindings and classes it provides to start functions apps as part of your scenarios and features. Here, we look at how you can vary the behaviour of those functions apps by providing or overriding configuration values.
When the FunctionsController is used to start a new function, it will check the ScenarioContext (if available) and FeatureContext for an instance of the FunctionConfiguration class. Any configuration provided here will be made available to the functions app when it starts.
If you're using step bindings to start your function, you can do this by writing an additional step binding to provide configuration from wherever you need to retrieve it. Note that this step must come before the one that starts the function. You can see an example in ScenariosUsingStepBindings.feature:
If you're using a BeforeScenario or BeforeFeature hook, you can add the configuration at the same time - as shown in ScenariosUsingPerScenarioHookWithAdditionalConfiguration.feature (and the corresponding hook method in DemoFunctionPerScenario, StartFunctionWithAdditionalConfigurationAsync), as well as the per-feature equivalents.
If you need to use different configuration at different times, you can create separate hook methods for setting up configuration - just ensure you use the Order parameter on the hook attributes to ensure the configuration is set prior to the functions being started.