public static void LogMissingVariables() { var missingVariables = Enum.GetValues(typeof(ExternalVariable)).Cast <ExternalVariable>() .Select(prop => EnvironmentVariableAttribute.Get(prop)) .Where(attr => Environment.GetEnvironmentVariable(attr.Name) == null) .ToList(); if (!missingVariables.Any()) { return; } Log.Warn($"The following environment variables could not be found: " + $"\n{string.Join("\n", missingVariables.Select(var => $" - {var.Name}\t\tSource: {var.LastPassName}"))}" + $"\n\nTests that rely on these variables are likely to fail."); }
public static string Get(ExternalVariable property) { var attr = EnvironmentVariableAttribute.Get(property); if (attr == null) { throw new Exception($"`{property}` does not include a {nameof(EnvironmentVariableAttribute)}."); } var valueFromEnv = Environment.GetEnvironmentVariable(attr.Name); if (valueFromEnv == null) { throw new Exception($"Environment Variable `{attr.Name}` could not be found. The value can be found in the password store under `{attr.LastPassName}`"); } return(valueFromEnv); }