11using Microsoft . Extensions . DependencyInjection ;
22using ModularityKit . Mutator . Abstractions ;
3+ using ModularityKit . Mutator . Abstractions . Audit ;
34using ModularityKit . Mutator . Abstractions . Changes ;
45using ModularityKit . Mutator . Abstractions . Context ;
56using ModularityKit . Mutator . Abstractions . Engine ;
7+ using ModularityKit . Mutator . Abstractions . History ;
68using ModularityKit . Mutator . Abstractions . Intent ;
79using ModularityKit . Mutator . Abstractions . Policies ;
810using ModularityKit . Mutator . Abstractions . Results ;
11+ using ModularityKit . Mutator . Benchmarks . Diagnostics . Support ;
912using ModularityKit . Mutator . Runtime ;
1013
1114namespace ModularityKit . Mutator . Benchmarks . Policy ;
@@ -21,6 +24,8 @@ public static IMutationEngine BuildEngine(Action<IMutationEngine>? configure = n
2124 {
2225 var services = new ServiceCollection ( ) ;
2326 services . AddMutators ( MutationEngineOptions . Performance ) ;
27+ services . AddSingleton < IMutationAuditor > ( new NoOpAuditor ( ) ) ;
28+ services . AddSingleton < IMutationHistoryStore > ( new NoOpHistoryStore ( ) ) ;
2429
2530 var engine = services
2631 . BuildServiceProvider ( )
@@ -85,7 +90,15 @@ public MutationResult<PolicyBenchmarkState> Apply(PolicyBenchmarkState state)
8590 /// </summary>
8691 public sealed class SyncAllowBenchmarkPolicy : IMutationPolicy < PolicyBenchmarkState >
8792 {
88- public SyncAllowBenchmarkPolicy ( int priority ) => Priority = priority ;
93+ private readonly PolicyDecision _decision ;
94+ private readonly Task < PolicyDecision > _decisionTask ;
95+
96+ public SyncAllowBenchmarkPolicy ( int priority )
97+ {
98+ Priority = priority ;
99+ _decision = PolicyDecision . Allow ( Name , "Synchronous benchmark policy allowed the mutation." ) ;
100+ _decisionTask = Task . FromResult ( _decision ) ;
101+ }
89102
90103 public string Name => $ "{ nameof ( SyncAllowBenchmarkPolicy ) } _{ Priority } ";
91104
@@ -94,31 +107,43 @@ public sealed class SyncAllowBenchmarkPolicy : IMutationPolicy<PolicyBenchmarkSt
94107 public string ? Description => "Synchronous allow policy for benchmark measurements." ;
95108
96109 public PolicyDecision Evaluate ( IMutation < PolicyBenchmarkState > mutation , PolicyBenchmarkState state )
97- => PolicyDecision . Allow ( Name , "Synchronous benchmark policy allowed the mutation." ) ;
110+ => _decision ;
111+
112+ public Task < PolicyDecision > EvaluateAsync (
113+ IMutation < PolicyBenchmarkState > mutation ,
114+ PolicyBenchmarkState state ,
115+ CancellationToken cancellationToken = default )
116+ => _decisionTask ;
98117 }
99118
100119 /// <summary>
101120 /// Asynchronous allow policy used in benchmark scenarios.
102121 /// </summary>
103122 public sealed class AsyncAllowBenchmarkPolicy : IMutationPolicy < PolicyBenchmarkState >
104123 {
105- public AsyncAllowBenchmarkPolicy ( int priority ) => Priority = priority ;
124+ private readonly PolicyDecision _decision ;
125+ private readonly Task < PolicyDecision > _decisionTask ;
126+
127+ public AsyncAllowBenchmarkPolicy ( int priority )
128+ {
129+ Priority = priority ;
130+ _decision = PolicyDecision . Allow ( Name , "Asynchronous benchmark policy allowed the mutation." ) ;
131+ _decisionTask = Task . FromResult ( _decision ) ;
132+ }
106133
107134 public string Name => $ "{ nameof ( AsyncAllowBenchmarkPolicy ) } _{ Priority } ";
108135
109136 public int Priority { get ; }
110137
111138 public string ? Description => "Asynchronous allow policy for benchmark measurements." ;
112139
113- public async Task < PolicyDecision > EvaluateAsync (
140+ public Task < PolicyDecision > EvaluateAsync (
114141 IMutation < PolicyBenchmarkState > mutation ,
115142 PolicyBenchmarkState state ,
116143 CancellationToken cancellationToken = default )
117144 {
118- await Task . CompletedTask ;
119145 cancellationToken . ThrowIfCancellationRequested ( ) ;
120-
121- return PolicyDecision . Allow ( Name , "Asynchronous benchmark policy allowed the mutation." ) ;
146+ return _decisionTask ;
122147 }
123148 }
124149}
0 commit comments