< Summary

Information
Class: AsiBackbone.Core.Metadata.GovernanceMetadataBudgetValidationResult
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Metadata/GovernanceMetadataBudgetValidationResult.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 69
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_IsValid()100%11100%
get_NormalizedMetadata()100%11100%
get_Violations()100%11100%
get_EstimatedSerializedBytes()100%11100%
Create(...)100%11100%
ThrowIfInvalid(...)75%44100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Metadata/GovernanceMetadataBudgetValidationResult.cs

#LineLine coverage
 1namespace AsiBackbone.Core.Metadata;
 2
 3/// <summary>
 4/// Represents the result of optional governance metadata budget validation.
 5/// </summary>
 6public sealed class GovernanceMetadataBudgetValidationResult
 7{
 638    private GovernanceMetadataBudgetValidationResult(
 639        IReadOnlyDictionary<string, string> normalizedMetadata,
 6310        IReadOnlyList<string> violations,
 6311        int estimatedSerializedBytes)
 12    {
 6313        ArgumentNullException.ThrowIfNull(normalizedMetadata);
 6314        ArgumentNullException.ThrowIfNull(violations);
 15
 6316        NormalizedMetadata = normalizedMetadata;
 6317        Violations = violations;
 6318        EstimatedSerializedBytes = estimatedSerializedBytes;
 6319    }
 20
 21    /// <summary>
 22    /// Gets a value indicating whether the metadata satisfied the supplied budget.
 23    /// </summary>
 3924    public bool IsValid => Violations.Count == 0;
 25
 26    /// <summary>
 27    /// Gets normalized metadata after trimming keys and values and dropping blank keys.
 28    /// </summary>
 1629    public IReadOnlyDictionary<string, string> NormalizedMetadata { get; }
 30
 31    /// <summary>
 32    /// Gets budget validation violations. Empty when <see cref="IsValid" /> is <see langword="true" />.
 33    /// </summary>
 5534    public IReadOnlyList<string> Violations { get; }
 35
 36    /// <summary>
 37    /// Gets the estimated UTF-8 serialized metadata size used for budget comparison.
 38    /// </summary>
 439    public int EstimatedSerializedBytes { get; }
 40
 41    /// <summary>
 42    /// Creates a validation result.
 43    /// </summary>
 44    public static GovernanceMetadataBudgetValidationResult Create(
 45        IReadOnlyDictionary<string, string> normalizedMetadata,
 46        IReadOnlyList<string> violations,
 47        int estimatedSerializedBytes)
 48    {
 6349        return new GovernanceMetadataBudgetValidationResult(
 6350            normalizedMetadata,
 6351            violations,
 6352            estimatedSerializedBytes);
 53    }
 54
 55    /// <summary>
 56    /// Throws an <see cref="ArgumentException" /> when validation failed.
 57    /// </summary>
 58    public void ThrowIfInvalid(string? parameterName = null)
 59    {
 460        if (IsValid)
 61        {
 262            return;
 63        }
 64
 265        throw new ArgumentException(
 266            $"Metadata budget validation failed: {string.Join("; ", Violations)}",
 267            string.IsNullOrWhiteSpace(parameterName) ? "metadata" : parameterName);
 68    }
 69}