< 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{
 110    private static readonly IReadOnlyDictionary<string, string> EmptyMetadata =
 111        new ReadOnlyDictionary<string, string>(
 112            new Dictionary<string, string>(StringComparer.Ordinal));
 13
 4714    private DlpFailurePolicyContext(
 4715        DlpClassificationFailureKind failureKind,
 4716        DlpIntentRiskLevel riskLevel,
 4717        string? intentCategory,
 4718        string? environment,
 4719        string? correlationId,
 4720        string? traceId,
 4721        string? policyVersion,
 4722        string? policyHash,
 4723        TimeSpan? timeout,
 4724        IReadOnlyDictionary<string, string> metadata)
 25    {
 4726        if (!Enum.IsDefined(failureKind))
 27        {
 128            throw new ArgumentOutOfRangeException(nameof(failureKind), failureKind, "DLP failure kind must be defined.")
 29        }
 30
 4631        if (!Enum.IsDefined(riskLevel))
 32        {
 133            throw new ArgumentOutOfRangeException(nameof(riskLevel), riskLevel, "DLP intent risk level must be defined."
 34        }
 35
 4536        if (timeout < TimeSpan.Zero)
 37        {
 138            throw new ArgumentOutOfRangeException(nameof(timeout), timeout, "Timeout must be greater than or equal to ze
 39        }
 40
 4441        FailureKind = failureKind;
 4442        RiskLevel = riskLevel;
 4443        IntentCategory = NormalizeOptional(intentCategory);
 4444        Environment = NormalizeOptional(environment);
 4445        CorrelationId = NormalizeOptional(correlationId);
 4446        TraceId = NormalizeOptional(traceId);
 4447        PolicyVersion = NormalizeOptional(policyVersion);
 4448        PolicyHash = NormalizeOptional(policyHash);
 4449        Timeout = timeout;
 4450        Metadata = metadata;
 4451    }
 52
 53    /// <summary>
 54    /// Gets the provider-neutral DLP or classification failure kind.
 55    /// </summary>
 11456    public DlpClassificationFailureKind FailureKind { get; }
 57
 58    /// <summary>
 59    /// Gets the host-assigned risk level for the intent.
 60    /// </summary>
 7261    public DlpIntentRiskLevel RiskLevel { get; }
 62
 63    /// <summary>
 64    /// Gets the host-defined intent category, when supplied.
 65    /// </summary>
 3466    public string? IntentCategory { get; }
 67
 68    /// <summary>
 69    /// Gets the host-defined environment, when supplied.
 70    /// </summary>
 3471    public string? Environment { get; }
 72
 73    /// <summary>
 74    /// Gets the correlation identifier associated with the governed flow, when supplied.
 75    /// </summary>
 3276    public string? CorrelationId { get; }
 77
 78    /// <summary>
 79    /// Gets the trace identifier associated with the governed flow, when supplied.
 80    /// </summary>
 3281    public string? TraceId { get; }
 82
 83    /// <summary>
 84    /// Gets the policy version associated with the governed flow, when supplied.
 85    /// </summary>
 3286    public string? PolicyVersion { get; }
 87
 88    /// <summary>
 89    /// Gets the policy hash associated with the governed flow, when supplied.
 90    /// </summary>
 3291    public string? PolicyHash { get; }
 92
 93    /// <summary>
 94    /// Gets the timeout value associated with the failure, when applicable.
 95    /// </summary>
 3896    public TimeSpan? Timeout { get; }
 97
 98    /// <summary>
 99    /// Gets provider-neutral host metadata associated with the failure.
 100    /// </summary>
 42101    public IReadOnlyDictionary<string, string> Metadata { get; }
 102
 103    /// <summary>
 104    /// Gets a value indicating whether timeout context is present.
 105    /// </summary>
 2106    public bool HasTimeout => Timeout.HasValue;
 107
 108    /// <summary>
 109    /// Gets a value indicating whether metadata is present.
 110    /// </summary>
 5111    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    {
 47128        return new DlpFailurePolicyContext(
 47129            failureKind,
 47130            riskLevel,
 47131            intentCategory,
 47132            environment,
 47133            correlationId,
 47134            traceId,
 47135            policyVersion,
 47136            policyHash,
 47137            timeout,
 47138            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    {
 6155        return Create(
 6156            DlpClassificationFailureKind.Timeout,
 6157            riskLevel,
 6158            intentCategory,
 6159            environment,
 6160            correlationId,
 6161            traceId,
 6162            policyVersion,
 6163            policyHash,
 6164            timeout,
 6165            metadata);
 166    }
 167
 168    private static string? NormalizeOptional(string? value)
 169    {
 264170        return string.IsNullOrWhiteSpace(value)
 264171            ? null
 264172            : value.Trim();
 173    }
 174
 175    private static IReadOnlyDictionary<string, string> NormalizeMetadata(
 176        IReadOnlyDictionary<string, string>? metadata)
 177    {
 47178        if (metadata is null || metadata.Count == 0)
 179        {
 43180            return EmptyMetadata;
 181        }
 182
 4183        Dictionary<string, string> normalizedMetadata = new(StringComparer.Ordinal);
 184
 24185        foreach (KeyValuePair<string, string> item in metadata)
 186        {
 8187            if (string.IsNullOrWhiteSpace(item.Key))
 188            {
 189                continue;
 190            }
 191
 5192            normalizedMetadata[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 193        }
 194
 4195        return normalizedMetadata.Count == 0
 4196            ? EmptyMetadata
 4197            : new ReadOnlyDictionary<string, string>(normalizedMetadata);
 198    }
 199}