< Summary

Information
Class: Common.Hosting.GetEnvironmentCommand
Assembly: Common
File(s): /__w/production-ready-pipelines/production-ready-pipelines/Common/Hosting/GetEnvironmentCommand.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 35
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
Execute()100%2100%
GetEnvironmentKey()100%1100%
GetEnvironmentKeys()100%1100%
GetEnvironmentName()100%2100%
IsEnvironmentKey(...)100%1100%

File(s)

/__w/production-ready-pipelines/production-ready-pipelines/Common/Hosting/GetEnvironmentCommand.cs

#LineLine coverage
 1namespace Common.Hosting;
 2
 3public class GetEnvironmentCommand
 4{
 5    private static string _environmentName;
 6
 7    public virtual string Execute()
 18    {
 19        _environmentName ??= GetEnvironmentName();
 110        return _environmentName;
 111    }
 12
 13    protected virtual string GetEnvironmentKey()
 114    {
 115        string key = Environment.GetEnvironmentVariables().Keys.Cast<string>().FirstOrDefault(IsEnvironmentKey);
 116        return key;
 117    }
 18
 19    protected virtual List<string> GetEnvironmentKeys()
 5920    {
 5921        return new List<string> { "DOTNET_ENVIRONMENT", "ASPNETCORE_ENVIRONMENT" };
 5922    }
 23
 24    protected virtual string GetEnvironmentName()
 225    {
 226        string key = GetEnvironmentKey();
 227        return key == null ? string.Empty : Environment.GetEnvironmentVariable(key);
 228    }
 29
 30    protected virtual bool IsEnvironmentKey(string key)
 5931    {
 5932        List<string> keys = GetEnvironmentKeys();
 17633        return keys.Exists(x => string.Equals(x, key, StringComparison.OrdinalIgnoreCase));
 5934    }
 35}