< Summary

Information
Class: ArturRios.Util.Test.Attributes.EnvironmentSkip
Assembly: ArturRios.Util.Test
File(s): D:\Repositories\dotnet-test-util\src\Attributes\EnvironmentSkip.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 38
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage
100%
Covered methods: 1
Fully covered methods: 0
Total methods: 1
Method coverage: 100%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetReason(...)100%88100%

File(s)

D:\Repositories\dotnet-test-util\src\Attributes\EnvironmentSkip.cs

#LineLine coverage
 1using ArturRios.Configuration.Enums;
 2
 3namespace ArturRios.Util.Test.Attributes;
 4
 5/// <summary>
 6/// Shared logic that decides whether a custom test attribute should skip the current test,
 7/// based on the active <c>ASPNETCORE_ENVIRONMENT</c> and an optional manual condition.
 8/// </summary>
 9internal static class EnvironmentSkip
 10{
 11    /// <summary>
 12    /// Computes the skip reason for a test.
 13    /// </summary>
 14    /// <param name="environments">
 15    /// Environments in which the test must <b>not</b> run. When the current environment is one of these,
 16    /// the test is skipped. <c>null</c> means the test is not restricted by environment.
 17    /// </param>
 18    /// <param name="skipCondition">When <c>true</c>, the test is skipped regardless of the environment.</param>
 19    /// <returns>The skip reason, or <c>null</c> when the test should run.</returns>
 20    public static string? GetReason(EnvironmentType[]? environments, bool skipCondition)
 1821    {
 1822        if (skipCondition)
 223        {
 224            return "Condition to skip matched";
 25        }
 26
 1627        if (environments is null || environments.Length == 0)
 1128        {
 1129            return null;
 30        }
 31
 532        var currentEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
 33
 1034        var blocked = environments.Any(x => x.ToString().Equals(currentEnvironment, StringComparison.OrdinalIgnoreCase))
 35
 536        return blocked ? $"Test can't run on {currentEnvironment}" : null;
 1837    }
 38}