< 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
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 111
Line coverage: 100%
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%11100%
Allow(...)100%11100%
BlockWithDefaultFailure(...)100%11100%
Block(...)100%11100%
Challenge(...)100%11100%

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{
 2612    private AsiBackboneEndpointGovernanceResult(
 2613        bool canExecute,
 2614        GovernanceDecision? decision,
 2615        IResult? failureResult,
 2616        AsiBackboneAcknowledgmentChallenge? acknowledgmentChallenge)
 17    {
 2618        CanExecute = canExecute;
 2619        Decision = decision;
 2620        FailureResult = failureResult;
 2621        AcknowledgmentChallenge = acknowledgmentChallenge;
 2622    }
 23
 24    /// <summary>
 25    /// Gets a value indicating whether the ASP.NET Core endpoint may continue execution.
 26    /// </summary>
 2527    public bool CanExecute { get; }
 28
 29    /// <summary>
 30    /// Gets the governance decision associated with the endpoint evaluation, when one was produced.
 31    /// </summary>
 3532    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>
 2037    public IResult? FailureResult { get; }
 38
 39    /// <summary>
 40    /// Gets the acknowledgment challenge produced when a decision required acknowledgment.
 41    /// </summary>
 142    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    {
 651        return new AsiBackboneEndpointGovernanceResult(
 652            canExecute: true,
 653            decision,
 654            failureResult: null,
 655            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    {
 1265        return new AsiBackboneEndpointGovernanceResult(
 1266            canExecute: false,
 1267            decision,
 1268            failureResult: null,
 1269            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    {
 780        ArgumentNullException.ThrowIfNull(failureResult);
 81
 782        return new AsiBackboneEndpointGovernanceResult(
 783            canExecute: false,
 784            decision,
 785            failureResult,
 786            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    {
 1101        ArgumentNullException.ThrowIfNull(challenge);
 1102        ArgumentNullException.ThrowIfNull(failureResult);
 1103        ArgumentNullException.ThrowIfNull(decision);
 104
 1105        return new AsiBackboneEndpointGovernanceResult(
 1106            canExecute: false,
 1107            decision,
 1108            failureResult,
 1109            challenge);
 110    }
 111}