< 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{
 5610    internal AsiBackboneAcknowledgmentChallenge(
 5611        LiabilityHandshakeRequest handshakeRequest,
 5612        string handshakeId,
 5613        string operationName,
 5614        string reasonCode,
 5615        string? reasonMessage,
 5616        string requiredAcknowledgmentCode,
 5617        string requiredAcknowledgmentText,
 5618        LiabilityHandshakeRiskLevel riskLevel,
 5619        string? riskCategory,
 5620        string? correlationId,
 5621        string? traceId,
 5622        string? policyVersion,
 5623        string? policyHash,
 5624        IReadOnlyDictionary<string, string> metadata)
 25    {
 26        // Defensive validation for internal construction invariants.
 27        // Public inputs are validated through FromHandshakeRequest and LiabilityHandshakeRequest.
 5628        ArgumentNullException.ThrowIfNull(handshakeRequest);
 5429        ArgumentException.ThrowIfNullOrWhiteSpace(handshakeId);
 5230        ArgumentException.ThrowIfNullOrWhiteSpace(operationName);
 5031        ArgumentException.ThrowIfNullOrWhiteSpace(reasonCode);
 4832        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentCode);
 4633        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentText);
 34
 4435        HandshakeRequest = handshakeRequest;
 4436        HandshakeId = handshakeId.Trim();
 4437        OperationName = operationName.Trim();
 4438        ReasonCode = reasonCode.Trim();
 4439        ReasonMessage = NormalizeOptional(reasonMessage);
 4440        RequiredAcknowledgmentCode = requiredAcknowledgmentCode.Trim();
 4441        RequiredAcknowledgmentText = requiredAcknowledgmentText.Trim();
 4442        RiskLevel = riskLevel;
 4443        RiskCategory = NormalizeOptional(riskCategory);
 4444        CorrelationId = NormalizeOptional(correlationId);
 4445        TraceId = NormalizeOptional(traceId);
 4446        PolicyVersion = NormalizeOptional(policyVersion);
 4447        PolicyHash = NormalizeOptional(policyHash);
 4448        Metadata = metadata;
 4449    }
 50
 51    /// <summary>
 52    /// Gets the framework-neutral Core handshake request used for round-tripping acknowledgment responses.
 53    /// </summary>
 1654    public LiabilityHandshakeRequest HandshakeRequest { get; }
 55
 56    /// <summary>
 57    /// Gets the stable handshake identifier.
 58    /// </summary>
 4659    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>
 469    public string ReasonCode { get; }
 70
 71    /// <summary>
 72    /// Gets the optional user-facing reason message for the challenge.
 73    /// </summary>
 874    public string? ReasonMessage { get; }
 75
 76    /// <summary>
 77    /// Gets the required acknowledgment code.
 78    /// </summary>
 2879    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>
 699    public string? CorrelationId { get; }
 100
 101    /// <summary>
 102    /// Gets the optional trace identifier associated with the challenge.
 103    /// </summary>
 8104    public string? TraceId { get; }
 105
 106    /// <summary>
 107    /// Gets the optional policy version associated with the challenge.
 108    /// </summary>
 8109    public string? PolicyVersion { get; }
 110
 111    /// <summary>
 112    /// Gets the optional policy hash associated with the challenge.
 113    /// </summary>
 8114    public string? PolicyHash { get; }
 115
 116    /// <summary>
 117    /// Gets additional host-provided challenge metadata.
 118    /// </summary>
 12119    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    {
 48131        ArgumentNullException.ThrowIfNull(request);
 46132        options ??= new AsiBackboneAcknowledgmentChallengeOptions();
 46133        options.Validate();
 134
 44135        return new AsiBackboneAcknowledgmentChallenge(
 44136            request,
 44137            request.HandshakeId,
 44138            request.OperationName,
 44139            request.ReasonCode,
 44140            options.IncludeReasonMessage ? request.Message : null,
 44141            request.RequiredAcknowledgmentCode,
 44142            request.RequiredAcknowledgmentText,
 44143            request.RiskLevel,
 44144            request.RiskCategory,
 44145            request.CorrelationId,
 44146            options.IncludeTraceId ? request.TraceId : null,
 44147            options.IncludePolicyMetadata ? request.PolicyVersion : null,
 44148            options.IncludePolicyMetadata ? request.PolicyHash : null,
 44149            request.Metadata);
 150    }
 151
 152    private static string? NormalizeOptional(string? value)
 153    {
 264154        return string.IsNullOrWhiteSpace(value)
 264155            ? null
 264156            : value.Trim();
 157    }
 158}