< 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
 4316    private LiabilityHandshakeAcknowledgment(
 4317        string acknowledgmentId,
 4318        string? schemaVersion,
 4319        string handshakeId,
 4320        string actorId,
 4321        AsiBackboneActorType actorType,
 4322        string? actorDisplayName,
 4323        string acknowledgmentCode,
 4324        bool acknowledged,
 4325        DateTimeOffset occurredUtc,
 4326        string? correlationId,
 4327        string? traceId,
 4328        IReadOnlyDictionary<string, string> metadata)
 29    {
 4330        ArgumentException.ThrowIfNullOrWhiteSpace(acknowledgmentId);
 4331        ArgumentException.ThrowIfNullOrWhiteSpace(handshakeId);
 4332        ArgumentException.ThrowIfNullOrWhiteSpace(actorId);
 4333        ArgumentException.ThrowIfNullOrWhiteSpace(acknowledgmentCode);
 34
 4335        AcknowledgmentId = acknowledgmentId.Trim();
 4336        SchemaVersion = AsiBackboneSchemaVersions.Normalize(schemaVersion);
 4337        HandshakeId = handshakeId.Trim();
 4338        ActorId = actorId.Trim();
 4339        ActorType = actorType;
 4340        ActorDisplayName = NormalizeOptional(actorDisplayName);
 4341        AcknowledgmentCode = acknowledgmentCode.Trim();
 4342        Acknowledged = acknowledged;
 4343        OccurredUtc = occurredUtc.ToUniversalTime();
 4344        CorrelationId = NormalizeOptional(correlationId);
 4345        TraceId = NormalizeOptional(traceId);
 4346        Metadata = metadata;
 4347    }
 48
 49    /// <summary>
 50    /// Gets the stable acknowledgment identifier.
 51    /// </summary>
 1452    public string AcknowledgmentId { get; }
 53
 54    /// <summary>
 55    /// Gets the schema version for the serialized handshake acknowledgment shape.
 56    /// </summary>
 857    public string SchemaVersion { get; }
 58
 59    /// <summary>
 60    /// Gets the handshake identifier associated with the acknowledgment.
 61    /// </summary>
 1062    public string HandshakeId { get; }
 63
 64    /// <summary>
 65    /// Gets the stable actor identifier associated with the acknowledgment.
 66    /// </summary>
 967    public string ActorId { get; }
 68
 69    /// <summary>
 70    /// Gets the actor type associated with the acknowledgment.
 71    /// </summary>
 972    public AsiBackboneActorType ActorType { get; }
 73
 74    /// <summary>
 75    /// Gets the optional display name or label associated with the actor.
 76    /// </summary>
 1177    public string? ActorDisplayName { get; }
 78
 79    /// <summary>
 80    /// Gets the acknowledgment code accepted or rejected by the actor.
 81    /// </summary>
 1282    public string AcknowledgmentCode { get; }
 83
 84    /// <summary>
 85    /// Gets a value indicating whether the required acknowledgment was accepted.
 86    /// </summary>
 2787    public bool Acknowledged { get; }
 88
 89    /// <summary>
 90    /// Gets a value indicating whether the required acknowledgment was rejected.
 91    /// </summary>
 1492    public bool Rejected => !Acknowledged;
 93
 94    /// <summary>
 95    /// Gets the UTC timestamp when the acknowledgment response occurred.
 96    /// </summary>
 1697    public DateTimeOffset OccurredUtc { get; }
 98
 99    /// <summary>
 100    /// Gets the correlation identifier associated with the acknowledgment, when supplied by the host.
 101    /// </summary>
 12102    public string? CorrelationId { get; }
 103
 104    /// <summary>
 105    /// Gets the trace identifier associated with the acknowledgment, when supplied by the host.
 106    /// </summary>
 12107    public string? TraceId { get; }
 108
 109    /// <summary>
 110    /// Gets additional framework-neutral acknowledgment metadata supplied by the host.
 111    /// </summary>
 56112    public IReadOnlyDictionary<string, string> Metadata { get; }
 113
 114    /// <summary>
 115    /// Gets a value indicating whether this acknowledgment contains metadata.
 116    /// </summary>
 18117    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    {
 47139        ArgumentNullException.ThrowIfNull(request);
 45140        ArgumentNullException.ThrowIfNull(actor);
 141
 43142        return new LiabilityHandshakeAcknowledgment(
 43143            NormalizeIdentifier(acknowledgmentId),
 43144            schemaVersion,
 43145            request.HandshakeId,
 43146            actor.ActorId,
 43147            actor.ActorType,
 43148            actor.DisplayName,
 43149            request.RequiredAcknowledgmentCode,
 43150            acknowledged,
 43151            occurredUtc ?? DateTimeOffset.UtcNow,
 43152            request.CorrelationId,
 43153            request.TraceId,
 43154            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    {
 42175        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    {
 2196        return Create(request, actor, acknowledged: false, acknowledgmentId, occurredUtc, metadata, schemaVersion);
 197    }
 198
 199    private static string NormalizeIdentifier(string? identifier)
 200    {
 43201        return string.IsNullOrWhiteSpace(identifier)
 43202            ? Guid.NewGuid().ToString("N")
 43203            : identifier.Trim();
 204    }
 205
 206    private static string? NormalizeOptional(string? value)
 207    {
 129208        return string.IsNullOrWhiteSpace(value)
 129209            ? null
 129210            : value.Trim();
 211    }
 212
 213    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 214        IReadOnlyDictionary<string, string>? metadata)
 215    {
 43216        if (metadata is null || metadata.Count == 0)
 217        {
 29218            return EmptyMetadata;
 219        }
 220
 14221        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 222
 68223        foreach (KeyValuePair<string, string> item in metadata)
 224        {
 20225            if (string.IsNullOrWhiteSpace(item.Key))
 226            {
 227                continue;
 228            }
 229
 14230            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 231        }
 232
 14233        return normalizedMetadata.Count == 0
 14234            ? EmptyMetadata
 14235            : 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>)