Skip to content

Commit 6551b95

Browse files
committed
feat: Enhance TestProvider with tracking invocation methods and event simulation
Signed-off-by: André Silva <[email protected]>
1 parent b4a1b69 commit 6551b95

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/OpenFeature.Providers.MultiProvider.Tests/Utils/TestProvider.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
using OpenFeature.Constant;
12
using OpenFeature.Model;
23

34
namespace OpenFeature.Providers.MultiProvider.Tests.Utils;
45

6+
/// <summary>
7+
/// Represents a tracking invocation for testing purposes.
8+
/// </summary>
9+
public record TrackingInvocation(string EventName, EvaluationContext? EvaluationContext, TrackingEventDetails? TrackingEventDetails);
10+
511
/// <summary>
612
/// A test implementation of FeatureProvider for MultiProvider testing.
713
/// </summary>
@@ -10,6 +16,7 @@ public class TestProvider : FeatureProvider
1016
private readonly string _name;
1117
private readonly Exception? _initException;
1218
private readonly Exception? _shutdownException;
19+
private readonly List<TrackingInvocation> _trackingInvocations = new();
1320

1421
public TestProvider(string name, Exception? initException = null, Exception? shutdownException = null)
1522
{
@@ -18,6 +25,10 @@ public TestProvider(string name, Exception? initException = null, Exception? shu
1825
this._shutdownException = shutdownException;
1926
}
2027

28+
public IReadOnlyList<TrackingInvocation> GetTrackingInvocations() => this._trackingInvocations.AsReadOnly();
29+
30+
public void ResetTrackingInvocations() => this._trackingInvocations.Clear();
31+
2132
public override Metadata GetMetadata() => new(this._name);
2233

2334
public override async Task InitializeAsync(EvaluationContext context, CancellationToken cancellationToken = default)
@@ -59,4 +70,23 @@ public override Task<ResolutionDetails<double>> ResolveDoubleValueAsync(string f
5970
public override Task<ResolutionDetails<Value>> ResolveStructureValueAsync(string flagKey, Value defaultValue,
6071
EvaluationContext? context = null, CancellationToken cancellationToken = default) =>
6172
Task.FromResult(new ResolutionDetails<Value>(flagKey, defaultValue));
73+
74+
public override void Track(string trackingEventName, EvaluationContext? evaluationContext = default, TrackingEventDetails? trackingEventDetails = default)
75+
{
76+
this._trackingInvocations.Add(new TrackingInvocation(trackingEventName, evaluationContext, trackingEventDetails));
77+
}
78+
79+
/// <summary>
80+
/// Sends a provider event to simulate status changes.
81+
/// </summary>
82+
public async Task SendProviderEventAsync(ProviderEventTypes eventType, ErrorType? errorType = null, CancellationToken cancellationToken = default)
83+
{
84+
var payload = new ProviderEventPayload
85+
{
86+
Type = eventType,
87+
ProviderName = this._name,
88+
ErrorType = errorType
89+
};
90+
await this.EventChannel.Writer.WriteAsync(payload, cancellationToken);
91+
}
6292
}

0 commit comments

Comments
 (0)