| | | 1 | | using Intentum.Core.Behavior; |
| | | 2 | | using Intentum.Core.Intents; |
| | | 3 | | using Intentum.Runtime.Policy; |
| | | 4 | | using Xunit; |
| | | 5 | | |
| | | 6 | | namespace Intentum.Testing; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Assertion helpers for BehaviorSpace testing. |
| | | 10 | | /// </summary> |
| | | 11 | | public 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> |
| | | 52 | | public 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) |
| | 1 | 58 | | { |
| | 1 | 59 | | Assert.Equal(expectedLevel, intent.Confidence.Level); |
| | 1 | 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) |
| | 1 | 66 | | { |
| | 1 | 67 | | Assert.InRange(intent.Confidence.Score, minScore, maxScore); |
| | 1 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Asserts that the intent has at least one signal. |
| | | 72 | | /// </summary> |
| | | 73 | | public static void HasSignals(Intent intent) |
| | 1 | 74 | | { |
| | 1 | 75 | | Assert.NotEmpty(intent.Signals); |
| | 1 | 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) |
| | 1 | 82 | | { |
| | 1 | 83 | | Assert.Equal(expectedCount, intent.Signals.Count); |
| | 1 | 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) |
| | 1 | 90 | | { |
| | 2 | 91 | | Assert.Contains(intent.Signals, s => s.Description.Contains(description, StringComparison.OrdinalIgnoreCase)); |
| | 1 | 92 | | } |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Assertion helpers for PolicyDecision testing. |
| | | 97 | | /// </summary> |
| | | 98 | | public 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) |
| | | 104 | | { |
| | | 105 | | Assert.Contains(decision, allowedDecisions); |
| | | 106 | | } |
| | | 107 | | |
| | | 108 | | /// <summary> |
| | | 109 | | /// Asserts that the decision is Allow. |
| | | 110 | | /// </summary> |
| | | 111 | | public static void IsAllow(PolicyDecision decision) |
| | | 112 | | { |
| | | 113 | | Assert.Equal(PolicyDecision.Allow, decision); |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// Asserts that the decision is Block. |
| | | 118 | | /// </summary> |
| | | 119 | | public static void IsBlock(PolicyDecision decision) |
| | | 120 | | { |
| | | 121 | | Assert.Equal(PolicyDecision.Block, decision); |
| | | 122 | | } |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// Asserts that the decision is not Block. |
| | | 126 | | /// </summary> |
| | | 127 | | public static void IsNotBlock(PolicyDecision decision) |
| | | 128 | | { |
| | | 129 | | Assert.NotEqual(PolicyDecision.Block, decision); |
| | | 130 | | } |
| | | 131 | | } |