< Summary

Information
Class: AsiBackbone.Core.CapabilityGrants.CapabilityGrantUseResult
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/CapabilityGrants/CapabilityGrantUseResult.cs
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 107
Line coverage: 95%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)75%4490%
get_IsAccepted()100%11100%
Accepted(...)100%11100%
UseLimitExceeded(...)100%11100%
RetentionElapsed(...)100%11100%
Stopped(...)100%11100%
Cancelled(...)100%11100%
Unavailable(...)100%11100%
NormalizeOptional(...)100%22100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/CapabilityGrants/CapabilityGrantUseResult.cs

#LineLine coverage
 1namespace AsiBackbone.Core.CapabilityGrants;
 2
 3/// <summary>
 4/// Represents the outcome returned by a capability grant use-control store.
 5/// </summary>
 6public sealed class CapabilityGrantUseResult
 7{
 788    private CapabilityGrantUseResult(GrantUseState state, int useCount, string? failureCode, string? failureMessage)
 9    {
 7810        if (!Enum.IsDefined(state))
 11        {
 012            throw new ArgumentOutOfRangeException(nameof(state), state, "Use state must be defined.");
 13        }
 14
 7815        State = state;
 7816        UseCount = useCount < 0
 7817            ? throw new ArgumentOutOfRangeException(nameof(useCount), useCount, "Use count must be greater than or equal
 7818            : useCount;
 7619        FailureCode = NormalizeOptional(failureCode);
 7620        FailureMessage = NormalizeOptional(failureMessage);
 7621    }
 22
 23    /// <summary>
 24    /// Gets the use-control state.
 25    /// </summary>
 26    public GrantUseState State { get; }
 27
 28    /// <summary>
 29    /// Gets the observed use count after the store checked or consumed the grant.
 30    /// </summary>
 31    public int UseCount { get; }
 32
 33    /// <summary>
 34    /// Gets the provider-neutral failure code when the use-control check did not accept the grant.
 35    /// </summary>
 36    public string? FailureCode { get; }
 37
 38    /// <summary>
 39    /// Gets the provider-neutral failure message when the use-control check did not accept the grant.
 40    /// </summary>
 41    public string? FailureMessage { get; }
 42
 43    /// <summary>
 44    /// Gets a value indicating whether the grant was accepted for use.
 45    /// </summary>
 546    public bool IsAccepted => State is GrantUseState.Accepted;
 47
 48    /// <summary>
 49    /// Creates an accepted use result.
 50    /// </summary>
 51    public static CapabilityGrantUseResult Accepted(int useCount)
 52    {
 2553        return new CapabilityGrantUseResult(GrantUseState.Accepted, useCount, null, null);
 54    }
 55
 56    /// <summary>
 57    /// Creates a result indicating the configured use limit was exceeded.
 58    /// </summary>
 59    public static CapabilityGrantUseResult UseLimitExceeded(int useCount, string? failureMessage = null)
 60    {
 3761        return new CapabilityGrantUseResult(GrantUseState.UseLimitExceeded, useCount, "capability.use-limit-exceeded", f
 62    }
 63
 64    /// <summary>
 65    /// Creates a result indicating the store can no longer prove the grant is within its use limit, because the grant i
 66    /// past the store's use-record retention horizon and its record may already have been evicted.
 67    /// </summary>
 68    /// <remarks>
 69    /// The state is <see cref="GrantUseState.UseLimitExceeded" />, so validation denies. Accepting the use instead woul
 70    /// start a fresh count for a grant whose earlier uses the store has discarded, which is a replay.
 71    /// </remarks>
 72    public static CapabilityGrantUseResult RetentionElapsed(string? failureMessage = null)
 73    {
 374        return new CapabilityGrantUseResult(GrantUseState.UseLimitExceeded, 0, "capability.use-retention-elapsed", failu
 75    }
 76
 77    /// <summary>
 78    /// Creates a result indicating the grant was administratively stopped.
 79    /// </summary>
 80    public static CapabilityGrantUseResult Stopped(string? failureMessage = null)
 81    {
 682        return new CapabilityGrantUseResult(GrantUseState.Stopped, 0, "capability.grant-stopped", failureMessage);
 83    }
 84
 85    /// <summary>
 86    /// Creates a result indicating the grant was cancelled.
 87    /// </summary>
 88    public static CapabilityGrantUseResult Cancelled(string? failureMessage = null)
 89    {
 590        return new CapabilityGrantUseResult(GrantUseState.Cancelled, 0, "capability.grant-cancelled", failureMessage);
 91    }
 92
 93    /// <summary>
 94    /// Creates a result indicating the use-control store was unavailable.
 95    /// </summary>
 96    public static CapabilityGrantUseResult Unavailable(string? failureMessage = null)
 97    {
 298        return new CapabilityGrantUseResult(GrantUseState.Unavailable, 0, "capability.use-store-unavailable", failureMes
 99    }
 100
 101    private static string? NormalizeOptional(string? value)
 102    {
 152103        return string.IsNullOrWhiteSpace(value)
 152104            ? null
 152105            : value.Trim();
 106    }
 107}