< Summary

Information
Class: AsiBackbone.Testing.Contracts.GovernancePolicyEvaluatorContract<T>
Assembly: AsiBackbone.Testing
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Testing/Contracts/GovernancePolicyEvaluatorContract.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 58
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
VerifyEvaluatorReturnsSafeDecisionAsync()100%44100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Testing/Contracts/GovernancePolicyEvaluatorContract.cs

#LineLine coverage
 1using AsiBackbone.Core.Constraints;
 2using AsiBackbone.Core.Decisions;
 3using AsiBackbone.Core.Evaluation;
 4
 5namespace AsiBackbone.Testing.Contracts;
 6
 7/// <summary>
 8/// Reusable contract fixture for <see cref="IGovernancePolicyEvaluator{TContext}" /> implementations.
 9/// </summary>
 10/// <typeparam name="TContext">The framework-neutral evaluation context type.</typeparam>
 11public abstract class GovernancePolicyEvaluatorContract<TContext>
 12    where TContext : IGovernanceEvaluationContext
 13{
 14    /// <summary>
 15    /// Creates the evaluator implementation under test.
 16    /// </summary>
 17    /// <returns>The evaluator implementation to validate.</returns>
 18    protected abstract IGovernancePolicyEvaluator<TContext> CreateEvaluator();
 19
 20    /// <summary>
 21    /// Creates the context supplied to the evaluator implementation under test.
 22    /// </summary>
 23    /// <returns>The evaluation context to validate with.</returns>
 24    protected abstract TContext CreateEvaluationContext();
 25
 26    /// <summary>
 27    /// Verifies that the evaluator returns a safe, non-null decision and preserves supplied decision telemetry.
 28    /// </summary>
 29    /// <param name="cancellationToken">A token that can cancel the contract validation.</param>
 30    /// <returns>The verified governance decision.</returns>
 31    public async ValueTask<GovernanceDecision> VerifyEvaluatorReturnsSafeDecisionAsync(CancellationToken cancellationTok
 32    {
 733        IGovernancePolicyEvaluator<TContext> evaluator = CreateEvaluator()
 734            ?? throw new GovernanceContractViolationException("Policy evaluator contract must provide an evaluator insta
 635        TContext context = CreateEvaluationContext()
 636            ?? throw new GovernanceContractViolationException("Policy evaluator contract must provide an evaluation cont
 37
 38        try
 39        {
 540            GovernanceDecision decision = await evaluator.EvaluateAsync(context, cancellationToken).ConfigureAwait(false
 241            return GovernanceDecisionContract.VerifyTelemetryFromContext(decision, context, "Policy evaluator decision")
 42        }
 143        catch (OperationCanceledException)
 44        {
 145            throw;
 46        }
 247        catch (GovernanceContractViolationException)
 48        {
 249            throw;
 50        }
 151        catch (Exception exception)
 52        {
 153            throw new GovernanceContractViolationException(
 154                "Policy evaluator implementations must not fail open or bypass the policy pipeline by throwing during no
 155                exception);
 56        }
 157    }
 58}