< 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{
 4310    internal AcknowledgmentChallenge(
 4311        AcknowledgmentRequest handshakeRequest,
 4312        string handshakeId,
 4313        string operationName,
 4314        string reasonCode,
 4315        string? reasonMessage,
 4316        string requiredAcknowledgmentCode,
 4317        string requiredAcknowledgmentText,
 4318        AcknowledgmentRiskLevel riskLevel,
 4319        string? riskCategory,
 4320        string? correlationId,
 4321        string? traceId,
 4322        string? policyVersion,
 4323        string? policyHash,
 4324        IReadOnlyDictionary<string, string> metadata)
 25    {
 26        // Defensive validation for internal construction invariants.
 27        // Public inputs are validated through FromAcknowledgmentRequest and AcknowledgmentRequest.
 4328        ArgumentNullException.ThrowIfNull(handshakeRequest);
 4229        ArgumentException.ThrowIfNullOrWhiteSpace(handshakeId);
 4130        ArgumentException.ThrowIfNullOrWhiteSpace(operationName);
 4031        ArgumentException.ThrowIfNullOrWhiteSpace(reasonCode);
 3932        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentCode);
 3833        ArgumentException.ThrowIfNullOrWhiteSpace(requiredAcknowledgmentText);
 34
 3735        AcknowledgmentRequest = handshakeRequest;
 3736        HandshakeId = handshakeId.Trim();
 3737        OperationName = operationName.Trim();
 3738        ReasonCode = reasonCode.Trim();
 3739        ReasonMessage = NormalizeOptional(reasonMessage);
 3740        RequiredAcknowledgmentCode = requiredAcknowledgmentCode.Trim();
 3741        RequiredAcknowledgmentText = requiredAcknowledgmentText.Trim();
 3742        RiskLevel = riskLevel;
 3743        RiskCategory = NormalizeOptional(riskCategory);
 3744        CorrelationId = NormalizeOptional(correlationId);
 3745        TraceId = NormalizeOptional(traceId);
 3746        PolicyVersion = NormalizeOptional(policyVersion);
 3747        PolicyHash = NormalizeOptional(policyHash);
 3748        Metadata = metadata;
 3749    }
 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    {
 39131        ArgumentNullException.ThrowIfNull(request);
 38132        options ??= new AcknowledgmentChallengeOptions();
 38133        options.Validate();
 134
 37135        return new AcknowledgmentChallenge(
 37136            request,
 37137            request.HandshakeId,
 37138            request.OperationName,
 37139            request.ReasonCode,
 37140            options.IncludeReasonMessage ? request.Message : null,
 37141            request.RequiredAcknowledgmentCode,
 37142            request.RequiredAcknowledgmentText,
 37143            request.RiskLevel,
 37144            request.RiskCategory,
 37145            request.CorrelationId,
 37146            options.IncludeTraceId ? request.TraceId : null,
 37147            options.IncludePolicyMetadata ? request.PolicyVersion : null,
 37148            options.IncludePolicyMetadata ? request.PolicyHash : null,
 37149            request.Metadata);
 150    }
 151
 152    private static string? NormalizeOptional(string? value)
 153    {
 222154        return string.IsNullOrWhiteSpace(value)
 222155            ? null
 222156            : value.Trim();
 157    }
 158}