< Summary

Information
Class: AsiBackbone.AspNetCore.Acknowledgments.AcknowledgmentChallenge
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Acknowledgments/AcknowledgmentChallenge.cs
Line coverage
100%
Covered lines: 57
Uncovered lines: 0
Coverable lines: 57
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%
FromAcknowledgmentRequest(...)100%1010100%
NormalizeOptional(...)100%22100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Acknowledgments/AcknowledgmentChallenge.cs

#LineLine coverage
 1using AsiBackbone.Core.Acknowledgments;
 2
 3namespace AsiBackbone.AspNetCore.Acknowledgments;
 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 AcknowledgmentChallenge
 9{
 3910    internal AcknowledgmentChallenge(
 3911        AcknowledgmentRequest handshakeRequest,
 3912        string handshakeId,
 3913        string operationName,
 3914        string reasonCode,
 3915        string? reasonMessage,
 3916        string requiredAcknowledgmentCode,
 3917        string requiredAcknowledgmentText,
 3918        AcknowledgmentRiskLevel riskLevel,
 3919        string? riskCategory,
 3920        string? correlationId,
 3921        string? traceId,
 3922        string? policyVersion,
 3923        string? policyHash,
 3924        IReadOnlyDictionary<string, string> metadata)
 25    {
 26        // Defensive validation for internal construction invariants.
 27        // Public inputs are validated through FromAcknowledgmentRequest and AcknowledgmentRequest.
 3928        ArgumentNullException.ThrowIfNull(handshakeRequest);
 3829        ArgumentException.ThrowIfNullOrWhiteSpace(handshakeId);
 3730        ArgumentException.ThrowIfNullOrWhiteSpace(operationName);
 3631        ArgumentException.ThrowIfNullOrWhiteSpace(reasonCode);
 3532        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentCode);
 3433        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentText);
 34
 3335        AcknowledgmentRequest = handshakeRequest;
 3336        HandshakeId = handshakeId.Trim();
 3337        OperationName = operationName.Trim();
 3338        ReasonCode = reasonCode.Trim();
 3339        ReasonMessage = NormalizeOptional(reasonMessage);
 3340        RequiredAcknowledgmentCode = requiredAcknowledgmentCode.Trim();
 3341        RequiredAcknowledgmentText = requiredAcknowledgmentText.Trim();
 3342        RiskLevel = riskLevel;
 3343        RiskCategory = NormalizeOptional(riskCategory);
 3344        CorrelationId = NormalizeOptional(correlationId);
 3345        TraceId = NormalizeOptional(traceId);
 3346        PolicyVersion = NormalizeOptional(policyVersion);
 3347        PolicyHash = NormalizeOptional(policyHash);
 3348        Metadata = metadata;
 3349    }
 50
 51    /// <summary>
 52    /// Gets the framework-neutral Core handshake request used for round-tripping acknowledgment responses.
 53    /// </summary>
 54    public AcknowledgmentRequest AcknowledgmentRequest { get; }
 55
 56    /// <summary>
 57    /// Gets the stable handshake identifier.
 58    /// </summary>
 59    public string HandshakeId { get; }
 60
 61    /// <summary>
 62    /// Gets the operation name requiring acknowledgment.
 63    /// </summary>
 64    public string OperationName { get; }
 65
 66    /// <summary>
 67    /// Gets the machine-readable reason code for the challenge.
 68    /// </summary>
 69    public string ReasonCode { get; }
 70
 71    /// <summary>
 72    /// Gets the optional user-facing reason message for the challenge.
 73    /// </summary>
 74    public string? ReasonMessage { get; }
 75
 76    /// <summary>
 77    /// Gets the required acknowledgment code.
 78    /// </summary>
 79    public string RequiredAcknowledgmentCode { get; }
 80
 81    /// <summary>
 82    /// Gets the required acknowledgment text.
 83    /// </summary>
 84    public string RequiredAcknowledgmentText { get; }
 85
 86    /// <summary>
 87    /// Gets the risk level associated with the challenge.
 88    /// </summary>
 89    public AcknowledgmentRiskLevel RiskLevel { get; }
 90
 91    /// <summary>
 92    /// Gets the optional host-defined risk category.
 93    /// </summary>
 94    public string? RiskCategory { get; }
 95
 96    /// <summary>
 97    /// Gets the correlation identifier associated with the challenge.
 98    /// </summary>
 99    public string? CorrelationId { get; }
 100
 101    /// <summary>
 102    /// Gets the optional trace identifier associated with the challenge.
 103    /// </summary>
 104    public string? TraceId { get; }
 105
 106    /// <summary>
 107    /// Gets the optional policy version associated with the challenge.
 108    /// </summary>
 109    public string? PolicyVersion { get; }
 110
 111    /// <summary>
 112    /// Gets the optional policy hash associated with the challenge.
 113    /// </summary>
 114    public string? PolicyHash { get; }
 115
 116    /// <summary>
 117    /// Gets additional host-provided challenge metadata.
 118    /// </summary>
 119    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 AcknowledgmentChallenge FromAcknowledgmentRequest(
 128        AcknowledgmentRequest request,
 129        AcknowledgmentChallengeOptions? options = null)
 130    {
 35131        ArgumentNullException.ThrowIfNull(request);
 34132        options ??= new AcknowledgmentChallengeOptions();
 34133        options.Validate();
 134
 33135        return new AcknowledgmentChallenge(
 33136            request,
 33137            request.HandshakeId,
 33138            request.OperationName,
 33139            request.ReasonCode,
 33140            options.IncludeReasonMessage ? request.Message : null,
 33141            request.RequiredAcknowledgmentCode,
 33142            request.RequiredAcknowledgmentText,
 33143            request.RiskLevel,
 33144            request.RiskCategory,
 33145            request.CorrelationId,
 33146            options.IncludeTraceId ? request.TraceId : null,
 33147            options.IncludePolicyMetadata ? request.PolicyVersion : null,
 33148            options.IncludePolicyMetadata ? request.PolicyHash : null,
 33149            request.Metadata);
 150    }
 151
 152    private static string? NormalizeOptional(string? value)
 153    {
 198154        return string.IsNullOrWhiteSpace(value)
 198155            ? null
 198156            : value.Trim();
 157    }
 158}