< Summary

Information
Class: AsiBackbone.Core.Handshakes.LiabilityHandshakeAcknowledgment
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Handshakes/LiabilityHandshakeAcknowledgment.cs
Line coverage
100%
Covered lines: 79
Uncovered lines: 0
Coverable lines: 79
Total lines: 237
Line coverage: 100%
Branch coverage
100%
Covered branches: 20
Total branches: 20
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
get_AcknowledgmentId()100%11100%
get_SchemaVersion()100%11100%
get_HandshakeId()100%11100%
get_ActorId()100%11100%
get_ActorType()100%11100%
get_ActorDisplayName()100%11100%
get_AcknowledgmentCode()100%11100%
get_Acknowledged()100%11100%
get_Rejected()100%11100%
get_OccurredUtc()100%11100%
get_CorrelationId()100%11100%
get_TraceId()100%11100%
get_Metadata()100%11100%
get_HasMetadata()100%11100%
Create(...)100%22100%
Accept(...)100%11100%
Reject(...)100%11100%
NormalizeIdentifier(...)100%22100%
NormalizeOptional(...)100%22100%
NormalizeMetadata(...)100%1414100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Handshakes/LiabilityHandshakeAcknowledgment.cs

#LineLine coverage
 1using System.Collections.ObjectModel;
 2using AsiBackbone.Core.Actors;
 3using AsiBackbone.Core.Serialization;
 4
 5namespace AsiBackbone.Core.Handshakes;
 6
 7/// <summary>
 8/// Represents a framework-neutral acknowledgment response for a liability or responsibility handshake.
 9/// </summary>
 10public sealed class LiabilityHandshakeAcknowledgment
 11{
 312    private static readonly IReadOnlyDictionary<string, string> EmptyMetadata =
 313        new ReadOnlyDictionary<string, string>(
 314            new Dictionary<string, string>(StringComparer.Ordinal));
 15
 2616    private LiabilityHandshakeAcknowledgment(
 2617        string acknowledgmentId,
 2618        string? schemaVersion,
 2619        string handshakeId,
 2620        string actorId,
 2621        AsiBackboneActorType actorType,
 2622        string? actorDisplayName,
 2623        string acknowledgmentCode,
 2624        bool acknowledged,
 2625        DateTimeOffset occurredUtc,
 2626        string? correlationId,
 2627        string? traceId,
 2628        IReadOnlyDictionary<string, string> metadata)
 29    {
 2630        ArgumentException.ThrowIfNullOrWhiteSpace(acknowledgmentId);
 2631        ArgumentException.ThrowIfNullOrWhiteSpace(handshakeId);
 2632        ArgumentException.ThrowIfNullOrWhiteSpace(actorId);
 2633        ArgumentException.ThrowIfNullOrWhiteSpace(acknowledgmentCode);
 34
 2635        AcknowledgmentId = acknowledgmentId.Trim();
 2636        SchemaVersion = AsiBackboneSchemaVersions.Normalize(schemaVersion);
 2637        HandshakeId = handshakeId.Trim();
 2638        ActorId = actorId.Trim();
 2639        ActorType = actorType;
 2640        ActorDisplayName = NormalizeOptional(actorDisplayName);
 2641        AcknowledgmentCode = acknowledgmentCode.Trim();
 2642        Acknowledged = acknowledged;
 2643        OccurredUtc = occurredUtc.ToUniversalTime();
 2644        CorrelationId = NormalizeOptional(correlationId);
 2645        TraceId = NormalizeOptional(traceId);
 2646        Metadata = metadata;
 2647    }
 48
 49    /// <summary>
 50    /// Gets the stable acknowledgment identifier.
 51    /// </summary>
 752    public string AcknowledgmentId { get; }
 53
 54    /// <summary>
 55    /// Gets the schema version for the serialized handshake acknowledgment shape.
 56    /// </summary>
 457    public string SchemaVersion { get; }
 58
 59    /// <summary>
 60    /// Gets the handshake identifier associated with the acknowledgment.
 61    /// </summary>
 862    public string HandshakeId { get; }
 63
 64    /// <summary>
 65    /// Gets the stable actor identifier associated with the acknowledgment.
 66    /// </summary>
 667    public string ActorId { get; }
 68
 69    /// <summary>
 70    /// Gets the actor type associated with the acknowledgment.
 71    /// </summary>
 672    public AsiBackboneActorType ActorType { get; }
 73
 74    /// <summary>
 75    /// Gets the optional display name or label associated with the actor.
 76    /// </summary>
 777    public string? ActorDisplayName { get; }
 78
 79    /// <summary>
 80    /// Gets the acknowledgment code accepted or rejected by the actor.
 81    /// </summary>
 982    public string AcknowledgmentCode { get; }
 83
 84    /// <summary>
 85    /// Gets a value indicating whether the required acknowledgment was accepted.
 86    /// </summary>
 2487    public bool Acknowledged { get; }
 88
 89    /// <summary>
 90    /// Gets a value indicating whether the required acknowledgment was rejected.
 91    /// </summary>
 1392    public bool Rejected => !Acknowledged;
 93
 94    /// <summary>
 95    /// Gets the UTC timestamp when the acknowledgment response occurred.
 96    /// </summary>
 1197    public DateTimeOffset OccurredUtc { get; }
 98
 99    /// <summary>
 100    /// Gets the correlation identifier associated with the acknowledgment, when supplied by the host.
 101    /// </summary>
 9102    public string? CorrelationId { get; }
 103
 104    /// <summary>
 105    /// Gets the trace identifier associated with the acknowledgment, when supplied by the host.
 106    /// </summary>
 9107    public string? TraceId { get; }
 108
 109    /// <summary>
 110    /// Gets additional framework-neutral acknowledgment metadata supplied by the host.
 111    /// </summary>
 31112    public IReadOnlyDictionary<string, string> Metadata { get; }
 113
 114    /// <summary>
 115    /// Gets a value indicating whether this acknowledgment contains metadata.
 116    /// </summary>
 9117    public bool HasMetadata => Metadata.Count > 0;
 118
 119    /// <summary>
 120    /// Creates an acknowledgment response for a liability or responsibility handshake.
 121    /// </summary>
 122    /// <param name="request">The handshake request being acknowledged.</param>
 123    /// <param name="actor">The actor responding to the handshake.</param>
 124    /// <param name="acknowledged">Whether the actor accepted the required acknowledgment.</param>
 125    /// <param name="acknowledgmentId">Optional acknowledgment identifier. When omitted, a new identifier is generated.<
 126    /// <param name="occurredUtc">Optional response timestamp. When omitted, the current UTC timestamp is used.</param>
 127    /// <param name="metadata">Optional host-provided metadata.</param>
 128    /// <param name="schemaVersion">Optional schema version for serialized or persisted acknowledgment records.</param>
 129    /// <returns>A liability handshake acknowledgment response.</returns>
 130    public static LiabilityHandshakeAcknowledgment Create(
 131        LiabilityHandshakeRequest request,
 132        IAsiBackboneActorContext actor,
 133        bool acknowledged,
 134        string? acknowledgmentId = null,
 135        DateTimeOffset? occurredUtc = null,
 136        IReadOnlyDictionary<string, string>? metadata = null,
 137        string? schemaVersion = null)
 138    {
 28139        ArgumentNullException.ThrowIfNull(request);
 27140        ArgumentNullException.ThrowIfNull(actor);
 141
 26142        return new LiabilityHandshakeAcknowledgment(
 26143            NormalizeIdentifier(acknowledgmentId),
 26144            schemaVersion,
 26145            request.HandshakeId,
 26146            actor.ActorId,
 26147            actor.ActorType,
 26148            actor.DisplayName,
 26149            request.RequiredAcknowledgmentCode,
 26150            acknowledged,
 26151            occurredUtc ?? DateTimeOffset.UtcNow,
 26152            request.CorrelationId,
 26153            request.TraceId,
 26154            NormalizeMetadata(metadata));
 155    }
 156
 157    /// <summary>
 158    /// Creates an accepted acknowledgment response for a liability or responsibility handshake.
 159    /// </summary>
 160    /// <param name="request">The handshake request being acknowledged.</param>
 161    /// <param name="actor">The actor accepting the handshake.</param>
 162    /// <param name="acknowledgmentId">Optional acknowledgment identifier. When omitted, a new identifier is generated.<
 163    /// <param name="occurredUtc">Optional response timestamp. When omitted, the current UTC timestamp is used.</param>
 164    /// <param name="metadata">Optional host-provided metadata.</param>
 165    /// <param name="schemaVersion">Optional schema version for serialized or persisted acknowledgment records.</param>
 166    /// <returns>An accepted liability handshake acknowledgment response.</returns>
 167    public static LiabilityHandshakeAcknowledgment Accept(
 168        LiabilityHandshakeRequest request,
 169        IAsiBackboneActorContext actor,
 170        string? acknowledgmentId = null,
 171        DateTimeOffset? occurredUtc = null,
 172        IReadOnlyDictionary<string, string>? metadata = null,
 173        string? schemaVersion = null)
 174    {
 21175        return Create(request, actor, acknowledged: true, acknowledgmentId, occurredUtc, metadata, schemaVersion);
 176    }
 177
 178    /// <summary>
 179    /// Creates a rejected acknowledgment response for a liability or responsibility handshake.
 180    /// </summary>
 181    /// <param name="request">The handshake request being rejected.</param>
 182    /// <param name="actor">The actor rejecting the handshake.</param>
 183    /// <param name="acknowledgmentId">Optional acknowledgment identifier. When omitted, a new identifier is generated.<
 184    /// <param name="occurredUtc">Optional response timestamp. When omitted, the current UTC timestamp is used.</param>
 185    /// <param name="metadata">Optional host-provided metadata.</param>
 186    /// <param name="schemaVersion">Optional schema version for serialized or persisted acknowledgment records.</param>
 187    /// <returns>A rejected liability handshake acknowledgment response.</returns>
 188    public static LiabilityHandshakeAcknowledgment Reject(
 189        LiabilityHandshakeRequest request,
 190        IAsiBackboneActorContext actor,
 191        string? acknowledgmentId = null,
 192        DateTimeOffset? occurredUtc = null,
 193        IReadOnlyDictionary<string, string>? metadata = null,
 194        string? schemaVersion = null)
 195    {
 1196        return Create(request, actor, acknowledged: false, acknowledgmentId, occurredUtc, metadata, schemaVersion);
 197    }
 198
 199    private static string NormalizeIdentifier(string? identifier)
 200    {
 26201        return string.IsNullOrWhiteSpace(identifier)
 26202            ? Guid.NewGuid().ToString("N")
 26203            : identifier.Trim();
 204    }
 205
 206    private static string? NormalizeOptional(string? value)
 207    {
 78208        return string.IsNullOrWhiteSpace(value)
 78209            ? null
 78210            : value.Trim();
 211    }
 212
 213    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 214        IReadOnlyDictionary<string, string>? metadata)
 215    {
 26216        if (metadata is null || metadata.Count == 0)
 217        {
 16218            return EmptyMetadata;
 219        }
 220
 10221        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 222
 46223        foreach (KeyValuePair<string, string> item in metadata)
 224        {
 13225            if (string.IsNullOrWhiteSpace(item.Key))
 226            {
 227                continue;
 228            }
 229
 10230            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 231        }
 232
 10233        return normalizedMetadata.Count == 0
 10234            ? EmptyMetadata
 10235            : new ReadOnlyDictionary<string, string>(normalizedMetadata);
 236    }
 237}

Methods/Properties

.cctor()
.ctor(System.String,System.String,System.String,System.String,AsiBackbone.Core.Actors.AsiBackboneActorType,System.String,System.String,System.Boolean,System.DateTimeOffset,System.String,System.String,System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.String>)
get_AcknowledgmentId()
get_SchemaVersion()
get_HandshakeId()
get_ActorId()
get_ActorType()
get_ActorDisplayName()
get_AcknowledgmentCode()
get_Acknowledged()
get_Rejected()
get_OccurredUtc()
get_CorrelationId()
get_TraceId()
get_Metadata()
get_HasMetadata()
Create(AsiBackbone.Core.Handshakes.LiabilityHandshakeRequest,AsiBackbone.Core.Actors.IAsiBackboneActorContext,System.Boolean,System.String,System.Nullable`1<System.DateTimeOffset>,System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.String>,System.String)
Accept(AsiBackbone.Core.Handshakes.LiabilityHandshakeRequest,AsiBackbone.Core.Actors.IAsiBackboneActorContext,System.String,System.Nullable`1<System.DateTimeOffset>,System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.String>,System.String)
Reject(AsiBackbone.Core.Handshakes.LiabilityHandshakeRequest,AsiBackbone.Core.Actors.IAsiBackboneActorContext,System.String,System.Nullable`1<System.DateTimeOffset>,System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.String>,System.String)
NormalizeIdentifier(System.String)
NormalizeOptional(System.String)
NormalizeMetadata(System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.String>)