< 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{
 613    private static readonly IReadOnlyDictionary<string, string> EmptyMetadata =
 614        new ReadOnlyDictionary<string, string>(
 615            new Dictionary<string, string>(StringComparer.Ordinal));
 16
 11217    private GovernanceEmissionPayload(
 11218        string payloadType,
 11219        string? schemaVersion,
 11220        string? contentType,
 11221        string? contentHash,
 11222        long? sizeBytes,
 11223        IReadOnlyDictionary<string, string> metadata)
 24    {
 11225        ArgumentException.ThrowIfNullOrWhiteSpace(payloadType);
 26
 11027        PayloadType = payloadType.Trim();
 11028        SchemaVersion = NormalizeOptional(schemaVersion);
 11029        ContentType = NormalizeOptional(contentType);
 11030        ContentHash = NormalizeOptional(contentHash);
 11031        SizeBytes = NormalizeSizeBytes(sizeBytes);
 10832        Metadata = metadata;
 10833    }
 34
 35    /// <summary>
 36    /// Gets the provider-neutral payload type.
 37    /// </summary>
 8438    public string PayloadType { get; }
 39
 40    /// <summary>
 41    /// Gets the payload schema version, when available.
 42    /// </summary>
 8243    public string? SchemaVersion { get; }
 44
 45    /// <summary>
 46    /// Gets the payload content type, when available.
 47    /// </summary>
 8248    public string? ContentType { get; }
 49
 50    /// <summary>
 51    /// Gets a hash of the payload content, when available.
 52    /// </summary>
 8453    public string? ContentHash { get; }
 54
 55    /// <summary>
 56    /// Gets the payload size in bytes, when available.
 57    /// </summary>
 8258    public long? SizeBytes { get; }
 59
 60    /// <summary>
 61    /// Gets minimized provider-neutral payload metadata.
 62    /// </summary>
 9663    public IReadOnlyDictionary<string, string> Metadata { get; }
 64
 65    /// <summary>
 66    /// Gets a value indicating whether payload metadata is present.
 67    /// </summary>
 268    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    {
 11281        return new GovernanceEmissionPayload(
 11282            payloadType,
 11283            schemaVersion,
 11284            contentType,
 11285            contentHash,
 11286            sizeBytes,
 11287            NormalizeMetadata(metadata));
 88    }
 89
 90    private static string? NormalizeOptional(string? value)
 91    {
 33092        return string.IsNullOrWhiteSpace(value)
 33093            ? null
 33094            : value.Trim();
 95    }
 96
 97    private static long? NormalizeSizeBytes(long? sizeBytes)
 98    {
 11099        return sizeBytes < 0
 110100            ? throw new ArgumentOutOfRangeException(nameof(sizeBytes), sizeBytes, "Payload size must be greater than or 
 110101            : sizeBytes;
 102    }
 103
 104    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 105        IReadOnlyDictionary<string, string>? metadata)
 106    {
 112107        if (metadata is null || metadata.Count == 0)
 108        {
 26109            return EmptyMetadata;
 110        }
 111
 86112        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 113
 388114        foreach (KeyValuePair<string, string> item in metadata)
 115        {
 108116            if (string.IsNullOrWhiteSpace(item.Key))
 117            {
 118                continue;
 119            }
 120
 106121            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 122        }
 123
 86124        return normalizedMetadata.Count == 0
 86125            ? EmptyMetadata
 86126            : new ReadOnlyDictionary<string, string>(normalizedMetadata);
 127    }
 128}