< Summary

Information
Class: AsiBackbone.AspNetCore.Handshakes.AsiBackboneAcknowledgmentChallenge
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Handshakes/AsiBackboneAcknowledgmentChallenge.cs
Line coverage
100%
Covered lines: 71
Uncovered lines: 0
Coverable lines: 71
Total lines: 158
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
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_HandshakeRequest()100%11100%
get_HandshakeId()100%11100%
get_OperationName()100%11100%
get_ReasonCode()100%11100%
get_ReasonMessage()100%11100%
get_RequiredAcknowledgmentCode()100%11100%
get_RequiredAcknowledgmentText()100%11100%
get_RiskLevel()100%11100%
get_RiskCategory()100%11100%
get_CorrelationId()100%11100%
get_TraceId()100%11100%
get_PolicyVersion()100%11100%
get_PolicyHash()100%11100%
get_Metadata()100%11100%
FromHandshakeRequest(...)100%1010100%
NormalizeOptional(...)100%22100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Handshakes/AsiBackboneAcknowledgmentChallenge.cs

#LineLine coverage
 1using AsiBackbone.Core.Handshakes;
 2
 3namespace AsiBackbone.AspNetCore.Handshakes;
 4
 5/// <summary>
 6/// Represents an ASP.NET Core-friendly acknowledgment challenge that a host can render using any UI or transport.
 7/// </summary>
 8public sealed class AsiBackboneAcknowledgmentChallenge
 9{
 2910    internal AsiBackboneAcknowledgmentChallenge(
 2911        LiabilityHandshakeRequest handshakeRequest,
 2912        string handshakeId,
 2913        string operationName,
 2914        string reasonCode,
 2915        string? reasonMessage,
 2916        string requiredAcknowledgmentCode,
 2917        string requiredAcknowledgmentText,
 2918        LiabilityHandshakeRiskLevel riskLevel,
 2919        string? riskCategory,
 2920        string? correlationId,
 2921        string? traceId,
 2922        string? policyVersion,
 2923        string? policyHash,
 2924        IReadOnlyDictionary<string, string> metadata)
 25    {
 26        // Defensive validation for internal construction invariants.
 27        // Public inputs are validated through FromHandshakeRequest and LiabilityHandshakeRequest.
 2928        ArgumentNullException.ThrowIfNull(handshakeRequest);
 2829        ArgumentException.ThrowIfNullOrWhiteSpace(handshakeId);
 2730        ArgumentException.ThrowIfNullOrWhiteSpace(operationName);
 2631        ArgumentException.ThrowIfNullOrWhiteSpace(reasonCode);
 2532        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentCode);
 2433        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentText);
 34
 2335        HandshakeRequest = handshakeRequest;
 2336        HandshakeId = handshakeId.Trim();
 2337        OperationName = operationName.Trim();
 2338        ReasonCode = reasonCode.Trim();
 2339        ReasonMessage = NormalizeOptional(reasonMessage);
 2340        RequiredAcknowledgmentCode = requiredAcknowledgmentCode.Trim();
 2341        RequiredAcknowledgmentText = requiredAcknowledgmentText.Trim();
 2342        RiskLevel = riskLevel;
 2343        RiskCategory = NormalizeOptional(riskCategory);
 2344        CorrelationId = NormalizeOptional(correlationId);
 2345        TraceId = NormalizeOptional(traceId);
 2346        PolicyVersion = NormalizeOptional(policyVersion);
 2347        PolicyHash = NormalizeOptional(policyHash);
 2348        Metadata = metadata;
 2349    }
 50
 51    /// <summary>
 52    /// Gets the framework-neutral Core handshake request used for round-tripping acknowledgment responses.
 53    /// </summary>
 954    public LiabilityHandshakeRequest HandshakeRequest { get; }
 55
 56    /// <summary>
 57    /// Gets the stable handshake identifier.
 58    /// </summary>
 2459    public string HandshakeId { get; }
 60
 61    /// <summary>
 62    /// Gets the operation name requiring acknowledgment.
 63    /// </summary>
 264    public string OperationName { get; }
 65
 66    /// <summary>
 67    /// Gets the machine-readable reason code for the challenge.
 68    /// </summary>
 369    public string ReasonCode { get; }
 70
 71    /// <summary>
 72    /// Gets the optional user-facing reason message for the challenge.
 73    /// </summary>
 574    public string? ReasonMessage { get; }
 75
 76    /// <summary>
 77    /// Gets the required acknowledgment code.
 78    /// </summary>
 1579    public string RequiredAcknowledgmentCode { get; }
 80
 81    /// <summary>
 82    /// Gets the required acknowledgment text.
 83    /// </summary>
 284    public string RequiredAcknowledgmentText { get; }
 85
 86    /// <summary>
 87    /// Gets the risk level associated with the challenge.
 88    /// </summary>
 289    public LiabilityHandshakeRiskLevel RiskLevel { get; }
 90
 91    /// <summary>
 92    /// Gets the optional host-defined risk category.
 93    /// </summary>
 294    public string? RiskCategory { get; }
 95
 96    /// <summary>
 97    /// Gets the correlation identifier associated with the challenge.
 98    /// </summary>
 499    public string? CorrelationId { get; }
 100
 101    /// <summary>
 102    /// Gets the optional trace identifier associated with the challenge.
 103    /// </summary>
 5104    public string? TraceId { get; }
 105
 106    /// <summary>
 107    /// Gets the optional policy version associated with the challenge.
 108    /// </summary>
 5109    public string? PolicyVersion { get; }
 110
 111    /// <summary>
 112    /// Gets the optional policy hash associated with the challenge.
 113    /// </summary>
 5114    public string? PolicyHash { get; }
 115
 116    /// <summary>
 117    /// Gets additional host-provided challenge metadata.
 118    /// </summary>
 7119    public IReadOnlyDictionary<string, string> Metadata { get; }
 120
 121    /// <summary>
 122    /// Creates a host-friendly challenge from a Core handshake request.
 123    /// </summary>
 124    /// <param name="request">The Core handshake request.</param>
 125    /// <param name="options">The challenge options.</param>
 126    /// <returns>A host-friendly acknowledgment challenge.</returns>
 127    public static AsiBackboneAcknowledgmentChallenge FromHandshakeRequest(
 128        LiabilityHandshakeRequest request,
 129        AsiBackboneAcknowledgmentChallengeOptions? options = null)
 130    {
 25131        ArgumentNullException.ThrowIfNull(request);
 24132        options ??= new AsiBackboneAcknowledgmentChallengeOptions();
 24133        options.Validate();
 134
 23135        return new AsiBackboneAcknowledgmentChallenge(
 23136            request,
 23137            request.HandshakeId,
 23138            request.OperationName,
 23139            request.ReasonCode,
 23140            options.IncludeReasonMessage ? request.Message : null,
 23141            request.RequiredAcknowledgmentCode,
 23142            request.RequiredAcknowledgmentText,
 23143            request.RiskLevel,
 23144            request.RiskCategory,
 23145            request.CorrelationId,
 23146            options.IncludeTraceId ? request.TraceId : null,
 23147            options.IncludePolicyMetadata ? request.PolicyVersion : null,
 23148            options.IncludePolicyMetadata ? request.PolicyHash : null,
 23149            request.Metadata);
 150    }
 151
 152    private static string? NormalizeOptional(string? value)
 153    {
 138154        return string.IsNullOrWhiteSpace(value)
 138155            ? null
 138156            : value.Trim();
 157    }
 158}