public IAvailabilityTestInternalConfiguration Resolve(IAvailabilityTestConfiguration testConfig, string functionName) { // Test Display Name: string testDisplayName = testConfig?.TestDisplayName; if (String.IsNullOrWhiteSpace(testDisplayName)) { testDisplayName = functionName; } if (String.IsNullOrWhiteSpace(testDisplayName)) { throw new ArgumentException("The Availability Test Display Name must be set, but it was not." + " To set that value, explicitly set the property \"{nameof(AvailabilityTestResultAttribute.TestDisplayName)}\"" + $" Otherwise the name of the Azure Function will be used as a fallback."); } // Location Display Name: string locationDisplayName = TryFillValueFromEnvironment(null, EnvironmentVariableNames.LocationDisplayName1); locationDisplayName = TryFillValueFromEnvironment(locationDisplayName, EnvironmentVariableNames.LocationDisplayName2); if (String.IsNullOrWhiteSpace(locationDisplayName)) { throw new ArgumentException("The Location Display Name of the Availability Test must be set, but it was not." + " Check that one of the following environment variables are set:" + $" (a) \"{EnvironmentVariableNames.LocationDisplayName1}\";" + $" (b) \"{EnvironmentVariableNames.LocationDisplayName2}\"."); } // We did our best to get the config. var resolvedConfig = new AvailabilityTestScopeSettingsResolver.AvailabilityTestConfiguration(testDisplayName, locationDisplayName); return(resolvedConfig); }
public IAvailabilityTestConfiguration Resolve(IAvailabilityTestConfiguration testConfig, string functionName) { // Whenever a setting is missing, attempt to fill it from the config ir the environment: // Test Display Name: string testDisplayName = testConfig?.TestDisplayName; testDisplayName = TryFillValueFromConfig( testDisplayName, ConfigurationKeys.SectionNames.AvailabilityTestResults, ConfigurationKeys.KeyNames.TestDisplayName); testDisplayName = TryFillValueFromEnvironment( testDisplayName, ConfigurationKeys.EnvironmentVariableNames.TestDisplayName); if (String.IsNullOrWhiteSpace(testDisplayName)) { testDisplayName = functionName; } if (String.IsNullOrWhiteSpace(testDisplayName)) { throw new ArgumentException("The Availability Test Display Name must be set, but it was not." + " To set that value, use one of the following (in order of precedence):" + $" (a) Explicitly set the property \"{nameof(AvailabilityTestResultAttribute.TestDisplayName)}\"" + $" on the '{AvailabilityTestResultAttribute.BindingTypeName}'-binding" + " (via the attribute or via function.json) (%%-tags are supported);" + $" (b) Use the App Setting \"{ConfigurationKeys.KeyNames.TestDisplayName}\" in" + $" configuration section \"{ConfigurationKeys.SectionNames.AvailabilityTestResults}\";" + $" (c) Use an environment variable \"{ConfigurationKeys.EnvironmentVariableNames.TestDisplayName}\";" + " (d) The name of the Azure Function will be used as a fallback."); } // Location Display Name: string locationDisplayName = testConfig?.LocationDisplayName; locationDisplayName = TryFillValueFromConfig( locationDisplayName, ConfigurationKeys.SectionNames.AvailabilityTestResults, ConfigurationKeys.KeyNames.LocationDisplayName); locationDisplayName = TryFillValueFromEnvironment( locationDisplayName, ConfigurationKeys.EnvironmentVariableNames.LocationDisplayName); locationDisplayName = TryFillValueFromEnvironment( locationDisplayName, ConfigurationKeys.EnvironmentVariableNames.LocationDisplayName_Fallback1); locationDisplayName = TryFillValueFromEnvironment( locationDisplayName, ConfigurationKeys.EnvironmentVariableNames.LocationDisplayName_Fallback2); if (String.IsNullOrWhiteSpace(locationDisplayName)) { throw new ArgumentException("The Location Display Name of the Availability Test must be set, but it was not." + " To set that value, use one of the following (in order of precedence):" + $" (a) Explicitly set the property \"{nameof(AvailabilityTestResultAttribute.LocationDisplayName)}\"" + $" on the '{AvailabilityTestResultAttribute.BindingTypeName}'-binding" + " (via the attribute or via function.json) (%%-tags are supported);" + $" (b) Use the App Setting \"{ConfigurationKeys.KeyNames.LocationDisplayName}\" in" + $" configuration section \"{ConfigurationKeys.SectionNames.AvailabilityTestResults}\";" + $" (c) Use the environment variable \"{ConfigurationKeys.EnvironmentVariableNames.LocationDisplayName}\";" + $" (d) Use the environment variable \"{ConfigurationKeys.EnvironmentVariableNames.LocationDisplayName_Fallback1}\";" + $" (e) Use the environment variable \"{ConfigurationKeys.EnvironmentVariableNames.LocationDisplayName_Fallback2}\"."); } // Location Id: string locationId = testConfig?.LocationId; locationId = TryFillValueFromConfig( locationId, ConfigurationKeys.SectionNames.AvailabilityTestResults, ConfigurationKeys.KeyNames.LocationId); locationId = TryFillValueFromEnvironment( locationId, ConfigurationKeys.EnvironmentVariableNames.LocationId); if (locationId == null) { locationId = Format.AvailabilityTest.LocationNameAsId(locationDisplayName); } if (String.IsNullOrWhiteSpace(locationId)) { throw new ArgumentException($"The Location Id of the Availability Test must be set, but it was not." + $" To set that value, use one of the following (in order of precedence):" + $" (a) Explicitly set the property \"{nameof(AvailabilityTestResultAttribute.LocationId)}\"" + $" on the '{AvailabilityTestResultAttribute.BindingTypeName}'-binding" + " (via the attribute or via function.json) (%%-tags are supported);" + $" (b) Use the App Setting \"{ConfigurationKeys.KeyNames.LocationId}\" in" + $" configuration section \"{ConfigurationKeys.SectionNames.AvailabilityTestResults}\";" + $" (c) Use the environment variable \"{ConfigurationKeys.EnvironmentVariableNames.LocationId}\";" + $" (d) As a fallback, a Location Id will be derived from the Location Display Name (only if that is set)."); } // We did our best to get the config. var resolvedConfig = new AvailabilityTestScopeSettingsResolver.AvailabilityTestConfiguration(testDisplayName, locationDisplayName, locationId); return(resolvedConfig); }