< Summary

Information
Class: AsiBackbone.Core.Emissions.GovernanceEmissionPayload
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Emissions/GovernanceEmissionPayload.cs
Line coverage
100%
Covered lines: 41
Uncovered lines: 0
Coverable lines: 41
Total lines: 128
Line coverage: 100%
Branch coverage
83%
Covered branches: 15
Total branches: 18
Branch coverage: 83.3%
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_HasMetadata()100%11100%
Create(...)100%11100%
NormalizeOptional(...)100%22100%
NormalizeSizeBytes(...)100%22100%
NormalizeMetadata(...)78.57%1414100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Emissions/GovernanceEmissionPayload.cs

#LineLine coverage
 1using System.Collections.ObjectModel;
 2
 3namespace AsiBackbone.Core.Emissions;
 4
 5/// <summary>
 6/// Describes a minimized provider-neutral payload associated with a governance emission envelope.
 7/// </summary>
 8/// <remarks>
 9/// This type intentionally describes payload identity, shape, and safe diagnostics. It does not require raw protected c
 10/// </remarks>
 11public sealed class GovernanceEmissionPayload
 12{
 313    private static readonly IReadOnlyDictionary<string, string> EmptyMetadata =
 314        new ReadOnlyDictionary<string, string>(
 315            new Dictionary<string, string>(StringComparer.Ordinal));
 16
 6417    private GovernanceEmissionPayload(
 6418        string payloadType,
 6419        string? schemaVersion,
 6420        string? contentType,
 6421        string? contentHash,
 6422        long? sizeBytes,
 6423        IReadOnlyDictionary<string, string> metadata)
 24    {
 6425        ArgumentException.ThrowIfNullOrWhiteSpace(payloadType);
 26
 6327        PayloadType = payloadType.Trim();
 6328        SchemaVersion = NormalizeOptional(schemaVersion);
 6329        ContentType = NormalizeOptional(contentType);
 6330        ContentHash = NormalizeOptional(contentHash);
 6331        SizeBytes = NormalizeSizeBytes(sizeBytes);
 6232        Metadata = metadata;
 6233    }
 34
 35    /// <summary>
 36    /// Gets the provider-neutral payload type.
 37    /// </summary>
 38    public string PayloadType { get; }
 39
 40    /// <summary>
 41    /// Gets the payload schema version, when available.
 42    /// </summary>
 43    public string? SchemaVersion { get; }
 44
 45    /// <summary>
 46    /// Gets the payload content type, when available.
 47    /// </summary>
 48    public string? ContentType { get; }
 49
 50    /// <summary>
 51    /// Gets a hash of the payload content, when available.
 52    /// </summary>
 53    public string? ContentHash { get; }
 54
 55    /// <summary>
 56    /// Gets the payload size in bytes, when available.
 57    /// </summary>
 58    public long? SizeBytes { get; }
 59
 60    /// <summary>
 61    /// Gets minimized provider-neutral payload metadata.
 62    /// </summary>
 63    public IReadOnlyDictionary<string, string> Metadata { get; }
 64
 65    /// <summary>
 66    /// Gets a value indicating whether payload metadata is present.
 67    /// </summary>
 168    public bool HasMetadata => Metadata.Count > 0;
 69
 70    /// <summary>
 71    /// Creates a minimized provider-neutral payload descriptor.
 72    /// </summary>
 73    public static GovernanceEmissionPayload Create(
 74        string payloadType,
 75        string? schemaVersion = null,
 76        string? contentType = null,
 77        string? contentHash = null,
 78        long? sizeBytes = null,
 79        IReadOnlyDictionary<string, string>? metadata = null)
 80    {
 6481        return new GovernanceEmissionPayload(
 6482            payloadType,
 6483            schemaVersion,
 6484            contentType,
 6485            contentHash,
 6486            sizeBytes,
 6487            NormalizeMetadata(metadata));
 88    }
 89
 90    private static string? NormalizeOptional(string? value)
 91    {
 18992        return string.IsNullOrWhiteSpace(value)
 18993            ? null
 18994            : value.Trim();
 95    }
 96
 97    private static long? NormalizeSizeBytes(long? sizeBytes)
 98    {
 6399        return sizeBytes < 0
 63100            ? throw new ArgumentOutOfRangeException(nameof(sizeBytes), sizeBytes, "Payload size must be greater than or 
 63101            : sizeBytes;
 102    }
 103
 104    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 105        IReadOnlyDictionary<string, string>? metadata)
 106    {
 64107        if (metadata is null || metadata.Count == 0)
 108        {
 14109            return EmptyMetadata;
 110        }
 111
 50112        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 113
 222114        foreach (KeyValuePair<string, string> item in metadata)
 115        {
 61116            if (string.IsNullOrWhiteSpace(item.Key))
 117            {
 118                continue;
 119            }
 120
 60121            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 122        }
 123
 50124        return normalizedMetadata.Count == 0
 50125            ? EmptyMetadata
 50126            : new ReadOnlyDictionary<string, string>(normalizedMetadata);
 127    }
 128}