< Summary

Information
Class: ArturRios.Configuration.Providers.EnvironmentProvider
Assembly: ArturRios.Configuration
File(s): D:\Repositories\dotnet-configuration\src\Providers\EnvironmentProvider.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 57
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 4
Fully covered methods: 1
Total methods: 4
Method coverage: 100%
Full method coverage: 25%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetBool(...)100%11100%
GetInt(...)100%11100%
GetString(...)100%11100%
GetObject(...)100%11100%

File(s)

D:\Repositories\dotnet-configuration\src\Providers\EnvironmentProvider.cs

#LineLine coverage
 1using ArturRios.Configuration.Providers.Interfaces;
 2using ArturRios.Extensions;
 3
 4namespace ArturRios.Configuration.Providers;
 5
 6/// <summary>
 7/// Provides configuration values by reading environment variables from the current process.
 8/// </summary>
 9/// <remarks>
 10/// Values are retrieved via <see cref="Environment.GetEnvironmentVariable(string)"/> and parsed using helper extension 
 11/// </remarks>
 12public class EnvironmentProvider : IConfigurationProvider
 13{
 14    /// <summary>
 15    /// Gets a boolean value for the given environment variable key.
 16    /// </summary>
 17    /// <param name="key">The environment variable key.</param>
 18    /// <returns>The parsed boolean value, or <c>null</c> if not found or unparseable.</returns>
 19    public bool? GetBool(string key)
 420    {
 421        var value = Environment.GetEnvironmentVariable(key);
 22
 423        return value.ParseToBoolOrDefault();
 424    }
 25
 26    /// <summary>
 27    /// Gets an integer value for the given environment variable key.
 28    /// </summary>
 29    /// <param name="key">The environment variable key.</param>
 30    /// <returns>The parsed integer value, or <c>null</c> if not found or unparseable.</returns>
 31    public int? GetInt(string key)
 332    {
 333        var value = Environment.GetEnvironmentVariable(key);
 34
 335        return value.ParseToIntOrDefault();
 336    }
 37
 38    /// <summary>
 39    /// Gets the raw string value for the given environment variable key.
 40    /// </summary>
 41    /// <param name="key">The environment variable key.</param>
 42    /// <returns>The string value, or <c>null</c> if not found.</returns>
 243    public string? GetString(string key) => Environment.GetEnvironmentVariable(key);
 44
 45    /// <summary>
 46    /// Gets a deserialized object of type <typeparamref name="T"/> for the given environment variable key.
 47    /// </summary>
 48    /// <typeparam name="T">The target type to deserialize to.</typeparam>
 49    /// <param name="key">The environment variable key.</param>
 50    /// <returns>The deserialized object instance, or <c>null</c> if not found or unparseable.</returns>
 51    public T? GetObject<T>(string key) where T : class
 352    {
 353        var value = Environment.GetEnvironmentVariable(key);
 54
 355        return value.ParseToObjectOrDefault<T>();
 356    }
 57}