< Summary

Information
Class: AsiBackbone.Core.Classification.DlpFailurePolicyContext
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Classification/DlpFailurePolicyContext.cs
Line coverage
100%
Covered lines: 77
Uncovered lines: 0
Coverable lines: 77
Total lines: 199
Line coverage: 100%
Branch coverage
100%
Covered branches: 24
Total branches: 24
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%88100%
get_FailureKind()100%11100%
get_RiskLevel()100%11100%
get_IntentCategory()100%11100%
get_Environment()100%11100%
get_CorrelationId()100%11100%
get_TraceId()100%11100%
get_PolicyVersion()100%11100%
get_PolicyHash()100%11100%
get_Timeout()100%11100%
get_Metadata()100%11100%
get_HasTimeout()100%11100%
get_HasMetadata()100%11100%
Create(...)100%11100%
TimeoutFailure(...)100%11100%
NormalizeOptional(...)100%22100%
NormalizeMetadata(...)100%1414100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Classification/DlpFailurePolicyContext.cs

#LineLine coverage
 1using System.Collections.ObjectModel;
 2
 3namespace AsiBackbone.Core.Classification;
 4
 5/// <summary>
 6/// Represents provider-neutral context for resolving DLP or classification failure behavior.
 7/// </summary>
 8public sealed class DlpFailurePolicyContext
 9{
 210    private static readonly IReadOnlyDictionary<string, string> EmptyMetadata =
 211        new ReadOnlyDictionary<string, string>(
 212            new Dictionary<string, string>(StringComparer.Ordinal));
 13
 9414    private DlpFailurePolicyContext(
 9415        DlpClassificationFailureKind failureKind,
 9416        DlpIntentRiskLevel riskLevel,
 9417        string? intentCategory,
 9418        string? environment,
 9419        string? correlationId,
 9420        string? traceId,
 9421        string? policyVersion,
 9422        string? policyHash,
 9423        TimeSpan? timeout,
 9424        IReadOnlyDictionary<string, string> metadata)
 25    {
 9426        if (!Enum.IsDefined(failureKind))
 27        {
 228            throw new ArgumentOutOfRangeException(nameof(failureKind), failureKind, "DLP failure kind must be defined.")
 29        }
 30
 9231        if (!Enum.IsDefined(riskLevel))
 32        {
 233            throw new ArgumentOutOfRangeException(nameof(riskLevel), riskLevel, "DLP intent risk level must be defined."
 34        }
 35
 9036        if (timeout < TimeSpan.Zero)
 37        {
 238            throw new ArgumentOutOfRangeException(nameof(timeout), timeout, "Timeout must be greater than or equal to ze
 39        }
 40
 8841        FailureKind = failureKind;
 8842        RiskLevel = riskLevel;
 8843        IntentCategory = NormalizeOptional(intentCategory);
 8844        Environment = NormalizeOptional(environment);
 8845        CorrelationId = NormalizeOptional(correlationId);
 8846        TraceId = NormalizeOptional(traceId);
 8847        PolicyVersion = NormalizeOptional(policyVersion);
 8848        PolicyHash = NormalizeOptional(policyHash);
 8849        Timeout = timeout;
 8850        Metadata = metadata;
 8851    }
 52
 53    /// <summary>
 54    /// Gets the provider-neutral DLP or classification failure kind.
 55    /// </summary>
 22856    public DlpClassificationFailureKind FailureKind { get; }
 57
 58    /// <summary>
 59    /// Gets the host-assigned risk level for the intent.
 60    /// </summary>
 14461    public DlpIntentRiskLevel RiskLevel { get; }
 62
 63    /// <summary>
 64    /// Gets the host-defined intent category, when supplied.
 65    /// </summary>
 6866    public string? IntentCategory { get; }
 67
 68    /// <summary>
 69    /// Gets the host-defined environment, when supplied.
 70    /// </summary>
 6871    public string? Environment { get; }
 72
 73    /// <summary>
 74    /// Gets the correlation identifier associated with the governed flow, when supplied.
 75    /// </summary>
 6476    public string? CorrelationId { get; }
 77
 78    /// <summary>
 79    /// Gets the trace identifier associated with the governed flow, when supplied.
 80    /// </summary>
 6481    public string? TraceId { get; }
 82
 83    /// <summary>
 84    /// Gets the policy version associated with the governed flow, when supplied.
 85    /// </summary>
 6486    public string? PolicyVersion { get; }
 87
 88    /// <summary>
 89    /// Gets the policy hash associated with the governed flow, when supplied.
 90    /// </summary>
 6491    public string? PolicyHash { get; }
 92
 93    /// <summary>
 94    /// Gets the timeout value associated with the failure, when applicable.
 95    /// </summary>
 7696    public TimeSpan? Timeout { get; }
 97
 98    /// <summary>
 99    /// Gets provider-neutral host metadata associated with the failure.
 100    /// </summary>
 84101    public IReadOnlyDictionary<string, string> Metadata { get; }
 102
 103    /// <summary>
 104    /// Gets a value indicating whether timeout context is present.
 105    /// </summary>
 4106    public bool HasTimeout => Timeout.HasValue;
 107
 108    /// <summary>
 109    /// Gets a value indicating whether metadata is present.
 110    /// </summary>
 10111    public bool HasMetadata => Metadata.Count > 0;
 112
 113    /// <summary>
 114    /// Creates a provider-neutral DLP or classification failure policy context.
 115    /// </summary>
 116    public static DlpFailurePolicyContext Create(
 117        DlpClassificationFailureKind failureKind,
 118        DlpIntentRiskLevel riskLevel,
 119        string? intentCategory = null,
 120        string? environment = null,
 121        string? correlationId = null,
 122        string? traceId = null,
 123        string? policyVersion = null,
 124        string? policyHash = null,
 125        TimeSpan? timeout = null,
 126        IReadOnlyDictionary<string, string>? metadata = null)
 127    {
 94128        return new DlpFailurePolicyContext(
 94129            failureKind,
 94130            riskLevel,
 94131            intentCategory,
 94132            environment,
 94133            correlationId,
 94134            traceId,
 94135            policyVersion,
 94136            policyHash,
 94137            timeout,
 94138            NormalizeMetadata(metadata));
 139    }
 140
 141    /// <summary>
 142    /// Creates timeout-specific failure policy context.
 143    /// </summary>
 144    public static DlpFailurePolicyContext TimeoutFailure(
 145        DlpIntentRiskLevel riskLevel,
 146        TimeSpan? timeout = null,
 147        string? intentCategory = null,
 148        string? environment = null,
 149        string? correlationId = null,
 150        string? traceId = null,
 151        string? policyVersion = null,
 152        string? policyHash = null,
 153        IReadOnlyDictionary<string, string>? metadata = null)
 154    {
 12155        return Create(
 12156            DlpClassificationFailureKind.Timeout,
 12157            riskLevel,
 12158            intentCategory,
 12159            environment,
 12160            correlationId,
 12161            traceId,
 12162            policyVersion,
 12163            policyHash,
 12164            timeout,
 12165            metadata);
 166    }
 167
 168    private static string? NormalizeOptional(string? value)
 169    {
 528170        return string.IsNullOrWhiteSpace(value)
 528171            ? null
 528172            : value.Trim();
 173    }
 174
 175    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 176        IReadOnlyDictionary<string, string>? metadata)
 177    {
 94178        if (metadata is null || metadata.Count == 0)
 179        {
 86180            return EmptyMetadata;
 181        }
 182
 8183        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 184
 48185        foreach (KeyValuePair<string, string> item in metadata)
 186        {
 16187            if (string.IsNullOrWhiteSpace(item.Key))
 188            {
 189                continue;
 190            }
 191
 10192            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 193        }
 194
 8195        return normalizedMetadata.Count == 0
 8196            ? EmptyMetadata
 8197            : new ReadOnlyDictionary<string, string>(normalizedMetadata);
 198    }
 199}