< Summary

Information
Class: AsiBackbone.AspNetCore.Endpoints.AsiBackboneEndpointGovernanceResult
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/AsiBackboneEndpointGovernanceResult.cs
Line coverage
76%
Covered lines: 29
Uncovered lines: 9
Coverable lines: 38
Total lines: 111
Line coverage: 76.3%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_CanExecute()100%11100%
get_Decision()100%11100%
get_FailureResult()100%11100%
get_AcknowledgmentChallenge()100%210%
Allow(...)100%11100%
BlockWithDefaultFailure(...)100%11100%
Block(...)100%11100%
Challenge(...)100%210%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/AsiBackboneEndpointGovernanceResult.cs

#LineLine coverage
 1using AsiBackbone.AspNetCore.Handshakes;
 2using AsiBackbone.Core.Decisions;
 3using Microsoft.AspNetCore.Http;
 4
 5namespace AsiBackbone.AspNetCore.Endpoints;
 6
 7/// <summary>
 8/// Represents the outcome of ASP.NET Core endpoint governance evaluation before endpoint execution.
 9/// </summary>
 10public sealed class AsiBackboneEndpointGovernanceResult
 11{
 2312    private AsiBackboneEndpointGovernanceResult(
 2313        bool canExecute,
 2314        GovernanceDecision? decision,
 2315        IResult? failureResult,
 2316        AsiBackboneAcknowledgmentChallenge? acknowledgmentChallenge)
 17    {
 2318        CanExecute = canExecute;
 2319        Decision = decision;
 2320        FailureResult = failureResult;
 2321        AcknowledgmentChallenge = acknowledgmentChallenge;
 2322    }
 23
 24    /// <summary>
 25    /// Gets a value indicating whether the ASP.NET Core endpoint may continue execution.
 26    /// </summary>
 2327    public bool CanExecute { get; }
 28
 29    /// <summary>
 30    /// Gets the governance decision associated with the endpoint evaluation, when one was produced.
 31    /// </summary>
 2032    public GovernanceDecision? Decision { get; }
 33
 34    /// <summary>
 35    /// Gets the HTTP result that should be returned instead of executing the endpoint, when execution is blocked.
 36    /// </summary>
 2237    public IResult? FailureResult { get; }
 38
 39    /// <summary>
 40    /// Gets the acknowledgment challenge produced when a decision required acknowledgment.
 41    /// </summary>
 042    public AsiBackboneAcknowledgmentChallenge? AcknowledgmentChallenge { get; }
 43
 44    /// <summary>
 45    /// Creates a result that allows endpoint execution to continue.
 46    /// </summary>
 47    /// <param name="decision">The governance decision that allowed execution.</param>
 48    /// <returns>An allow result.</returns>
 49    public static AsiBackboneEndpointGovernanceResult Allow(GovernanceDecision? decision = null)
 50    {
 151        return new AsiBackboneEndpointGovernanceResult(
 152            canExecute: true,
 153            decision,
 154            failureResult: null,
 155            acknowledgmentChallenge: null);
 56    }
 57
 58    /// <summary>
 59    /// Creates a result that blocks endpoint execution and lets middleware write the configured generic failure respons
 60    /// </summary>
 61    /// <param name="decision">The governance decision that blocked execution.</param>
 62    /// <returns>A blocked result without a custom failure response.</returns>
 63    public static AsiBackboneEndpointGovernanceResult BlockWithDefaultFailure(GovernanceDecision? decision = null)
 64    {
 1465        return new AsiBackboneEndpointGovernanceResult(
 1466            canExecute: false,
 1467            decision,
 1468            failureResult: null,
 1469            acknowledgmentChallenge: null);
 70    }
 71
 72    /// <summary>
 73    /// Creates a result that blocks endpoint execution and returns a host-safe failure result.
 74    /// </summary>
 75    /// <param name="failureResult">The HTTP result to execute.</param>
 76    /// <param name="decision">The governance decision that blocked execution.</param>
 77    /// <returns>A blocked result.</returns>
 78    public static AsiBackboneEndpointGovernanceResult Block(IResult failureResult, GovernanceDecision? decision = null)
 79    {
 880        ArgumentNullException.ThrowIfNull(failureResult);
 81
 882        return new AsiBackboneEndpointGovernanceResult(
 883            canExecute: false,
 884            decision,
 885            failureResult,
 886            acknowledgmentChallenge: null);
 87    }
 88
 89    /// <summary>
 90    /// Creates a result that blocks execution with an acknowledgment challenge.
 91    /// </summary>
 92    /// <param name="challenge">The acknowledgment challenge.</param>
 93    /// <param name="failureResult">The HTTP result to execute.</param>
 94    /// <param name="decision">The governance decision that required acknowledgment.</param>
 95    /// <returns>An acknowledgment challenge result.</returns>
 96    public static AsiBackboneEndpointGovernanceResult Challenge(
 97        AsiBackboneAcknowledgmentChallenge challenge,
 98        IResult failureResult,
 99        GovernanceDecision decision)
 100    {
 0101        ArgumentNullException.ThrowIfNull(challenge);
 0102        ArgumentNullException.ThrowIfNull(failureResult);
 0103        ArgumentNullException.ThrowIfNull(decision);
 104
 0105        return new AsiBackboneEndpointGovernanceResult(
 0106            canExecute: false,
 0107            decision,
 0108            failureResult,
 0109            challenge);
 110    }
 111}