< Summary

Information
Class: ArturRios.Util.Test.Attributes.CustomTheoryAttribute
Assembly: ArturRios.Util.Test
File(s): /home/runner/work/dotnet-test-util/dotnet-test-util/src/Attributes/CustomTheoryAttribute.cs
Line coverage
90%
Covered lines: 9
Uncovered lines: 1
Coverable lines: 10
Total lines: 44
Line coverage: 90%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
75%
Covered methods: 3
Fully covered methods: 3
Total methods: 4
Method coverage: 75%
Full method coverage: 75%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_TestType()100%11100%
get_Environments()100%210%
GetTraits()100%11100%

File(s)

/home/runner/work/dotnet-test-util/dotnet-test-util/src/Attributes/CustomTheoryAttribute.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using ArturRios.Configuration.Enums;
 3using Xunit;
 4using Xunit.v3;
 5
 6namespace ArturRios.Util.Test.Attributes;
 7
 8/// <summary>
 9/// Base <see cref="TheoryAttribute"/> that can skip a test based on the active <c>ASPNETCORE_ENVIRONMENT</c>
 10/// or an explicit condition, and stamps its <see cref="TestType"/> as the <c>Category</c> trait.
 11/// Derive from it to create environment-aware theory attributes filterable by test type.
 12/// </summary>
 13public class CustomTheoryAttribute : TheoryAttribute, ITraitAttribute
 14{
 15    /// <summary>Creates the attribute and applies the skip reason, if any.</summary>
 16    /// <param name="testType">The kind of test this attribute marks, published as the <c>Category</c> trait.</param>
 17    /// <param name="environments">Environments in which the test must not run. <c>null</c> imposes no restriction.</par
 18    /// <param name="skipCondition">When <c>true</c>, the test is skipped regardless of the environment.</param>
 19    /// <param name="sourceFilePath">Supplied by the compiler; xUnit reports it as the test's source location.</param>
 20    /// <param name="sourceLineNumber">Supplied by the compiler; xUnit reports it as the test's source location.</param>
 21    protected CustomTheoryAttribute(TestType testType, EnvironmentType[]? environments = null, bool skipCondition = fals
 22        [CallerFilePath] string? sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = -1)
 623        : base(sourceFilePath, sourceLineNumber)
 24    {
 625        TestType = testType;
 626        Environments = environments;
 27
 628        var reason = EnvironmentSkip.GetReason(environments, skipCondition);
 29
 630        if (reason is not null)
 31        {
 132            Skip = reason;
 33        }
 634    }
 35
 36    /// <summary>The kind of test this attribute marks, published as the <c>Category</c> trait.</summary>
 437    public TestType TestType { get; }
 38
 39    /// <summary>The environments in which the test must not run, or <c>null</c> when unrestricted.</summary>
 040    public EnvironmentType[]? Environments { get; }
 41
 42    /// <summary>Publishes <see cref="TestType"/> as the <c>Category</c> trait.</summary>
 243    public IReadOnlyCollection<KeyValuePair<string, string>> GetTraits() => TestTypeTrait.For(TestType);
 44}