/// <summary> /// Creates an <see cref="IWebHostBuilder"/> as if the environment variables are set as per <paramref name="environment"/>. /// The actual system environment variables are ignored. Command line arguments are not supported, as (by design) everything /// that can be specified on the command line can also be specified via environment variables. /// This method is primarily used for writing integration tests where a high degree of control is required, /// for example to simulate the difference between running in a container or not. /// </summary> /// <param name="environment">The fake environment variables to use when constructing the host builder.</param> /// <param name="functionAssembly">The assembly containing the target function. May be null, in which case the calling assembly /// is used.</param> /// <returns>A host builder that can be used for integration testing.</returns> public static IHostBuilder CreateHostBuilder(IReadOnlyDictionary <string, string> environment, Assembly?functionAssembly = null) { var variables = ConfigurationVariableProvider.FromDictionary(environment); var functionEnvironment = FunctionEnvironment.Create(functionAssembly ?? Assembly.GetCallingAssembly(), new string[0], variables); return(functionEnvironment.CreateHostBuilder()); }
internal static ConfigurationVariableProvider Combine(ConfigurationVariableProvider primary, ConfigurationVariableProvider secondary) => new CombinedVariableProvider(primary, secondary);
internal CombinedVariableProvider(ConfigurationVariableProvider primary, ConfigurationVariableProvider secondary) => (_primary, _secondary) = (primary, secondary);