< 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: 47
Uncovered lines: 0
Coverable lines: 47
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_PayloadType()100%11100%
get_SchemaVersion()100%11100%
get_ContentType()100%11100%
get_ContentHash()100%11100%
get_SizeBytes()100%11100%
get_Metadata()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
 5417    private GovernanceEmissionPayload(
 5418        string payloadType,
 5419        string? schemaVersion,
 5420        string? contentType,
 5421        string? contentHash,
 5422        long? sizeBytes,
 5423        IReadOnlyDictionary<string, string> metadata)
 24    {
 5425        ArgumentException.ThrowIfNullOrWhiteSpace(payloadType);
 26
 5327        PayloadType = payloadType.Trim();
 5328        SchemaVersion = NormalizeOptional(schemaVersion);
 5329        ContentType = NormalizeOptional(contentType);
 5330        ContentHash = NormalizeOptional(contentHash);
 5331        SizeBytes = NormalizeSizeBytes(sizeBytes);
 5232        Metadata = metadata;
 5233    }
 34
 35    /// <summary>
 36    /// Gets the provider-neutral payload type.
 37    /// </summary>
 3938    public string PayloadType { get; }
 39
 40    /// <summary>
 41    /// Gets the payload schema version, when available.
 42    /// </summary>
 3743    public string? SchemaVersion { get; }
 44
 45    /// <summary>
 46    /// Gets the payload content type, when available.
 47    /// </summary>
 3748    public string? ContentType { get; }
 49
 50    /// <summary>
 51    /// Gets a hash of the payload content, when available.
 52    /// </summary>
 3953    public string? ContentHash { get; }
 54
 55    /// <summary>
 56    /// Gets the payload size in bytes, when available.
 57    /// </summary>
 3758    public long? SizeBytes { get; }
 59
 60    /// <summary>
 61    /// Gets minimized provider-neutral payload metadata.
 62    /// </summary>
 3563    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    {
 5481        return new GovernanceEmissionPayload(
 5482            payloadType,
 5483            schemaVersion,
 5484            contentType,
 5485            contentHash,
 5486            sizeBytes,
 5487            NormalizeMetadata(metadata));
 88    }
 89
 90    private static string? NormalizeOptional(string? value)
 91    {
 15992        return string.IsNullOrWhiteSpace(value)
 15993            ? null
 15994            : value.Trim();
 95    }
 96
 97    private static long? NormalizeSizeBytes(long? sizeBytes)
 98    {
 5399        return sizeBytes < 0
 53100            ? throw new ArgumentOutOfRangeException(nameof(sizeBytes), sizeBytes, "Payload size must be greater than or 
 53101            : sizeBytes;
 102    }
 103
 104    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 105        IReadOnlyDictionary<string, string>? metadata)
 106    {
 54107        if (metadata is null || metadata.Count == 0)
 108        {
 12109            return EmptyMetadata;
 110        }
 111
 42112        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 113
 180114        foreach (KeyValuePair<string, string> item in metadata)
 115        {
 48116            if (string.IsNullOrWhiteSpace(item.Key))
 117            {
 118                continue;
 119            }
 120
 47121            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 122        }
 123
 42124        return normalizedMetadata.Count == 0
 42125            ? EmptyMetadata
 42126            : new ReadOnlyDictionary<string, string>(normalizedMetadata);
 127    }
 128}