< Summary

Information
Class: Intentum.Testing.PolicyDecisionAssertions
Assembly: Intentum.Testing
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Testing/BehaviorSpaceAssertions.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 131
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
IsOneOf(...)100%11100%
IsAllow(...)100%11100%
IsBlock(...)100%11100%
IsNotBlock(...)100%11100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Testing/BehaviorSpaceAssertions.cs

#LineLine coverage
 1using Intentum.Core.Behavior;
 2using Intentum.Core.Intents;
 3using Intentum.Runtime.Policy;
 4using Xunit;
 5
 6namespace Intentum.Testing;
 7
 8/// <summary>
 9/// Assertion helpers for BehaviorSpace testing.
 10/// </summary>
 11public static class BehaviorSpaceAssertions
 12{
 13    /// <summary>
 14    /// Asserts that the behavior space contains a specific event.
 15    /// </summary>
 16    public static void ContainsEvent(
 17        BehaviorSpace space,
 18        string actor,
 19        string action)
 20    {
 21        Assert.Contains(space.Events, e => { _ = e; return e.Actor == actor && e.Action == action; });
 22    }
 23
 24    /// <summary>
 25    /// Asserts that the behavior space contains a specific number of events.
 26    /// </summary>
 27    public static void HasEventCount(BehaviorSpace space, int expectedCount)
 28    {
 29        Assert.Equal(expectedCount, space.Events.Count);
 30    }
 31
 32    /// <summary>
 33    /// Asserts that the behavior space contains events for a specific actor.
 34    /// </summary>
 35    public static void ContainsActor(BehaviorSpace space, string actor)
 36    {
 37        Assert.Contains(space.Events, e => { _ = e; return e.Actor == actor; });
 38    }
 39
 40    /// <summary>
 41    /// Asserts that the behavior space contains a specific action.
 42    /// </summary>
 43    public static void ContainsAction(BehaviorSpace space, string action)
 44    {
 45        Assert.Contains(space.Events, e => { _ = e; return e.Action == action; });
 46    }
 47}
 48
 49/// <summary>
 50/// Assertion helpers for Intent testing.
 51/// </summary>
 52public static class IntentAssertions
 53{
 54    /// <summary>
 55    /// Asserts that the intent has a specific confidence level.
 56    /// </summary>
 57    public static void HasConfidenceLevel(Intent intent, string expectedLevel)
 58    {
 59        Assert.Equal(expectedLevel, intent.Confidence.Level);
 60    }
 61
 62    /// <summary>
 63    /// Asserts that the intent has a confidence score within a range.
 64    /// </summary>
 65    public static void HasConfidenceScore(Intent intent, double minScore, double maxScore)
 66    {
 67        Assert.InRange(intent.Confidence.Score, minScore, maxScore);
 68    }
 69
 70    /// <summary>
 71    /// Asserts that the intent has at least one signal.
 72    /// </summary>
 73    public static void HasSignals(Intent intent)
 74    {
 75        Assert.NotEmpty(intent.Signals);
 76    }
 77
 78    /// <summary>
 79    /// Asserts that the intent has a specific number of signals.
 80    /// </summary>
 81    public static void HasSignalCount(Intent intent, int expectedCount)
 82    {
 83        Assert.Equal(expectedCount, intent.Signals.Count);
 84    }
 85
 86    /// <summary>
 87    /// Asserts that the intent contains a signal with a specific description.
 88    /// </summary>
 89    public static void ContainsSignal(Intent intent, string description)
 90    {
 91        Assert.Contains(intent.Signals, s => s.Description.Contains(description, StringComparison.OrdinalIgnoreCase));
 92    }
 93}
 94
 95/// <summary>
 96/// Assertion helpers for PolicyDecision testing.
 97/// </summary>
 98public static class PolicyDecisionAssertions
 99{
 100    /// <summary>
 101    /// Asserts that the decision is one of the allowed values.
 102    /// </summary>
 103    public static void IsOneOf(PolicyDecision decision, params PolicyDecision[] allowedDecisions)
 1104    {
 1105        Assert.Contains(decision, allowedDecisions);
 1106    }
 107
 108    /// <summary>
 109    /// Asserts that the decision is Allow.
 110    /// </summary>
 111    public static void IsAllow(PolicyDecision decision)
 1112    {
 1113        Assert.Equal(PolicyDecision.Allow, decision);
 1114    }
 115
 116    /// <summary>
 117    /// Asserts that the decision is Block.
 118    /// </summary>
 119    public static void IsBlock(PolicyDecision decision)
 1120    {
 1121        Assert.Equal(PolicyDecision.Block, decision);
 1122    }
 123
 124    /// <summary>
 125    /// Asserts that the decision is not Block.
 126    /// </summary>
 127    public static void IsNotBlock(PolicyDecision decision)
 2128    {
 2129        Assert.NotEqual(PolicyDecision.Block, decision);
 2130    }
 131}