< Summary

Information
Class: AsiBackbone.AspNetCore.Endpoints.EndpointGovernanceResult
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/EndpointGovernanceResult.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
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%
Allow(...)100%11100%
BlockWithDefaultFailure(...)100%11100%
Block(...)100%11100%
Challenge(...)100%11100%

File(s)

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

#LineLine coverage
 1using AsiBackbone.AspNetCore.Acknowledgments;
 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 EndpointGovernanceResult
 11{
 2812    private EndpointGovernanceResult(
 2813        bool canExecute,
 2814        GovernanceDecision? decision,
 2815        IResult? failureResult,
 2816        AcknowledgmentChallenge? acknowledgmentChallenge)
 17    {
 2818        CanExecute = canExecute;
 2819        Decision = decision;
 2820        FailureResult = failureResult;
 2821        AcknowledgmentChallenge = acknowledgmentChallenge;
 2822    }
 23
 24    /// <summary>
 25    /// Gets a value indicating whether the ASP.NET Core endpoint may continue execution.
 26    /// </summary>
 27    public bool CanExecute { get; }
 28
 29    /// <summary>
 30    /// Gets the governance decision associated with the endpoint evaluation, when one was produced.
 31    /// </summary>
 32    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>
 37    public IResult? FailureResult { get; }
 38
 39    /// <summary>
 40    /// Gets the acknowledgment challenge produced when a decision required acknowledgment.
 41    /// </summary>
 42    public AcknowledgmentChallenge? 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 EndpointGovernanceResult Allow(GovernanceDecision? decision = null)
 50    {
 951        return new EndpointGovernanceResult(
 952            canExecute: true,
 953            decision,
 954            failureResult: null,
 955            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 EndpointGovernanceResult BlockWithDefaultFailure(GovernanceDecision? decision = null)
 64    {
 1065        return new EndpointGovernanceResult(
 1066            canExecute: false,
 1067            decision,
 1068            failureResult: null,
 1069            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 EndpointGovernanceResult Block(IResult failureResult, GovernanceDecision? decision = null)
 79    {
 880        ArgumentNullException.ThrowIfNull(failureResult);
 81
 882        return new EndpointGovernanceResult(
 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 EndpointGovernanceResult Challenge(
 97        AcknowledgmentChallenge challenge,
 98        IResult failureResult,
 99        GovernanceDecision decision)
 100    {
 1101        ArgumentNullException.ThrowIfNull(challenge);
 1102        ArgumentNullException.ThrowIfNull(failureResult);
 1103        ArgumentNullException.ThrowIfNull(decision);
 104
 1105        return new EndpointGovernanceResult(
 1106            canExecute: false,
 1107            decision,
 1108            failureResult,
 1109            challenge);
 110    }
 111}