diff --git a/Directory.Packages.props b/Directory.Packages.props
index b856f939..384be972 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -43,9 +43,9 @@
-
-
-
+
+
+
diff --git a/global.json b/global.json
index d8d11dbe..4e257725 100644
--- a/global.json
+++ b/global.json
@@ -3,5 +3,8 @@
"rollForward": "latestFeature",
"version": "10.0.100",
"allowPrerelease": false
+ },
+ "test": {
+ "runner": "Microsoft.Testing.Platform"
}
}
diff --git a/test/OpenFeature.E2ETests/OpenFeature.E2ETests.csproj b/test/OpenFeature.E2ETests/OpenFeature.E2ETests.csproj
index 11120976..60c293f6 100644
--- a/test/OpenFeature.E2ETests/OpenFeature.E2ETests.csproj
+++ b/test/OpenFeature.E2ETests/OpenFeature.E2ETests.csproj
@@ -2,6 +2,7 @@
OpenFeature.E2ETests
+ Exe
@@ -14,10 +15,10 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/test/OpenFeature.E2ETests/Steps/ExcludedTagsStep.cs b/test/OpenFeature.E2ETests/Steps/ExcludedTagsStep.cs
index 1037c189..cac03e3b 100644
--- a/test/OpenFeature.E2ETests/Steps/ExcludedTagsStep.cs
+++ b/test/OpenFeature.E2ETests/Steps/ExcludedTagsStep.cs
@@ -11,6 +11,6 @@ public class ExcludedTagsStep
[BeforeScenario]
public static void BeforeScenario()
{
- Skip.If(true, "Tag is not supported");
+ Assert.SkipWhen(true, "Tag is not supported");
}
}
diff --git a/test/OpenFeature.Hosting.Tests/Internal/FeatureLifecycleManagerTests.cs b/test/OpenFeature.Hosting.Tests/Internal/FeatureLifecycleManagerTests.cs
index 2d379fc4..94bcf1f3 100644
--- a/test/OpenFeature.Hosting.Tests/Internal/FeatureLifecycleManagerTests.cs
+++ b/test/OpenFeature.Hosting.Tests/Internal/FeatureLifecycleManagerTests.cs
@@ -26,7 +26,7 @@ public async Task EnsureInitializedAsync_SetsProvider()
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, NullLogger.Instance);
- await lifecycleManager.EnsureInitializedAsync();
+ await lifecycleManager.EnsureInitializedAsync(TestContext.Current.CancellationToken);
// Assert
var actualProvider = api.GetProvider();
@@ -53,7 +53,7 @@ public async Task EnsureInitializedAsync_SetsMultipleProvider()
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, NullLogger.Instance);
- await lifecycleManager.EnsureInitializedAsync();
+ await lifecycleManager.EnsureInitializedAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(provider1, api.GetProvider("provider1"));
@@ -80,7 +80,7 @@ public async Task EnsureInitializedAsync_AddsHooks()
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, NullLogger.Instance);
- await lifecycleManager.EnsureInitializedAsync();
+ await lifecycleManager.EnsureInitializedAsync(TestContext.Current.CancellationToken);
// Assert
var actualHooks = api.GetHooks();
@@ -108,7 +108,7 @@ public async Task EnsureInitializedAsync_AddHandlers()
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, NullLogger.Instance);
- await lifecycleManager.EnsureInitializedAsync();
+ await lifecycleManager.EnsureInitializedAsync(TestContext.Current.CancellationToken);
// Assert
Assert.True(hookExecuted);
@@ -122,13 +122,13 @@ public async Task ShutdownAsync_ResetsApi()
var provider = new NoOpFeatureProvider();
var api = Api.Instance;
- await api.SetProviderAsync(provider);
+ await api.SetProviderAsync(provider, TestContext.Current.CancellationToken);
api.AddHooks(new NoOpHook());
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, NullLogger.Instance);
- await lifecycleManager.ShutdownAsync();
+ await lifecycleManager.ShutdownAsync(TestContext.Current.CancellationToken);
// Assert
var actualProvider = api.GetProvider();
@@ -154,7 +154,7 @@ public async Task EnsureInitializedAsync_LogStartingInitialization()
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, logger);
- await lifecycleManager.EnsureInitializedAsync();
+ await lifecycleManager.EnsureInitializedAsync(TestContext.Current.CancellationToken);
// Assert
var log = logger.LatestRecord;
@@ -181,7 +181,7 @@ public async Task ShutdownAsync_LogShuttingDown()
// Act
using var serviceProvider = services.BuildServiceProvider();
var lifecycleManager = new FeatureLifecycleManager(api, serviceProvider, logger);
- await lifecycleManager.ShutdownAsync();
+ await lifecycleManager.ShutdownAsync(TestContext.Current.CancellationToken);
// Assert
var log = logger.LatestRecord;
@@ -190,13 +190,13 @@ public async Task ShutdownAsync_LogShuttingDown()
Assert.Equal(LogLevel.Information, log.Level);
}
- public async Task InitializeAsync()
+ public async ValueTask InitializeAsync()
{
await Api.Instance.ShutdownAsync();
}
// Make sure the singleton is cleared between tests
- public async Task DisposeAsync()
+ public async ValueTask DisposeAsync()
{
await Api.Instance.ShutdownAsync().ConfigureAwait(false);
}
diff --git a/test/OpenFeature.Hosting.Tests/OpenFeature.Hosting.Tests.csproj b/test/OpenFeature.Hosting.Tests/OpenFeature.Hosting.Tests.csproj
index 88251769..d86f8641 100644
--- a/test/OpenFeature.Hosting.Tests/OpenFeature.Hosting.Tests.csproj
+++ b/test/OpenFeature.Hosting.Tests/OpenFeature.Hosting.Tests.csproj
@@ -2,6 +2,7 @@
OpenFeature.Hosting.Tests
+ Exe
@@ -17,7 +18,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/test/OpenFeature.Hosting.Tests/Providers/Memory/FeatureBuilderExtensionsTests.cs b/test/OpenFeature.Hosting.Tests/Providers/Memory/FeatureBuilderExtensionsTests.cs
index b36dc82d..b87f097a 100644
--- a/test/OpenFeature.Hosting.Tests/Providers/Memory/FeatureBuilderExtensionsTests.cs
+++ b/test/OpenFeature.Hosting.Tests/Providers/Memory/FeatureBuilderExtensionsTests.cs
@@ -48,7 +48,7 @@ public async Task AddInMemoryProvider_WithFlags_AddsProvider()
Assert.NotNull(featureProvider);
Assert.IsType(featureProvider);
- var result = await featureProvider.ResolveBooleanValueAsync("feature1", false);
+ var result = await featureProvider.ResolveBooleanValueAsync("feature1", false, cancellationToken: TestContext.Current.CancellationToken);
Assert.True(result.Value);
}
@@ -130,7 +130,7 @@ public async Task AddInMemoryProvider_WithDomainAndFlags_AddsProvider()
Assert.IsType(featureProvider);
var context = EvaluationContext.Builder().Set("group", "alpha").Build();
- var result = await featureProvider.ResolveBooleanValueAsync("feature2", false, context);
+ var result = await featureProvider.ResolveBooleanValueAsync("feature2", false, context, TestContext.Current.CancellationToken);
Assert.True(result.Value);
}
@@ -178,7 +178,7 @@ public async Task AddInMemoryProvider_WithOptions_AddsProvider()
Assert.NotNull(featureProvider);
Assert.IsType(featureProvider);
- var result = await featureProvider.ResolveBooleanValueAsync("new-feature", true);
+ var result = await featureProvider.ResolveBooleanValueAsync("new-feature", true, cancellationToken: TestContext.Current.CancellationToken);
Assert.False(result.Value);
}
@@ -208,7 +208,7 @@ public async Task AddInMemoryProvider_WithDomainAndOptions_AddsProvider()
Assert.NotNull(featureProvider);
Assert.IsType(featureProvider);
- var result = await featureProvider.ResolveBooleanValueAsync("new-feature", true);
+ var result = await featureProvider.ResolveBooleanValueAsync("new-feature", true, cancellationToken: TestContext.Current.CancellationToken);
Assert.False(result.Value);
}
diff --git a/test/OpenFeature.IntegrationTests/FeatureFlagIntegrationTest.cs b/test/OpenFeature.IntegrationTests/FeatureFlagIntegrationTest.cs
index 9638ff8c..d8271748 100644
--- a/test/OpenFeature.IntegrationTests/FeatureFlagIntegrationTest.cs
+++ b/test/OpenFeature.IntegrationTests/FeatureFlagIntegrationTest.cs
@@ -54,8 +54,8 @@ public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string us
var requestUri = $"/features/{userId}/flags/{FeatureA}";
// Act
- var response = await client.GetAsync(requestUri).ConfigureAwait(true);
- var responseContent = await response.Content.ReadFromJsonAsync>().ConfigureAwait(true);
+ var response = await client.GetAsync(requestUri, TestContext.Current.CancellationToken).ConfigureAwait(true);
+ var responseContent = await response.Content.ReadFromJsonAsync>(cancellationToken: TestContext.Current.CancellationToken).ConfigureAwait(true);
// Assert
Assert.True(response.IsSuccessStatusCode, "Expected HTTP status code 200 OK.");
@@ -85,7 +85,7 @@ public async Task VerifyLoggingHookIsRegisteredAsync()
var requestUri = $"/features/{TestUserId}/flags/{FeatureA}";
// Act
- var response = await client.GetAsync(requestUri).ConfigureAwait(true);
+ var response = await client.GetAsync(requestUri, TestContext.Current.CancellationToken).ConfigureAwait(true);
var logs = logger.Collector.GetSnapshot();
// Assert
@@ -120,7 +120,7 @@ public async Task VerifyHandlerIsRegisteredAsync()
var requestUri = $"/features/{TestUserId}/flags/{FeatureA}";
// Act
- var response = await client.GetAsync(requestUri).ConfigureAwait(true);
+ var response = await client.GetAsync(requestUri, TestContext.Current.CancellationToken).ConfigureAwait(true);
// Assert
Assert.True(response.IsSuccessStatusCode, "Expected HTTP status code 200 OK.");
@@ -152,7 +152,7 @@ public async Task VerifyMultipleHandlersAreRegisteredAsync()
var requestUri = $"/features/{TestUserId}/flags/{FeatureA}";
// Act
- var response = await client.GetAsync(requestUri).ConfigureAwait(true);
+ var response = await client.GetAsync(requestUri, TestContext.Current.CancellationToken).ConfigureAwait(true);
// Assert
Assert.True(response.IsSuccessStatusCode, "Expected HTTP status code 200 OK.");
@@ -191,7 +191,7 @@ public async Task VerifyHandlersAreRegisteredWithServiceProviderAsync()
var requestUri = $"/features/{TestUserId}/flags/{FeatureA}";
// Act
- var response = await client.GetAsync(requestUri).ConfigureAwait(true);
+ var response = await client.GetAsync(requestUri, TestContext.Current.CancellationToken).ConfigureAwait(true);
// Assert
Assert.True(response.IsSuccessStatusCode, "Expected HTTP status code 200 OK.");
diff --git a/test/OpenFeature.IntegrationTests/OpenFeature.IntegrationTests.csproj b/test/OpenFeature.IntegrationTests/OpenFeature.IntegrationTests.csproj
index 35d85dfd..da2ef563 100644
--- a/test/OpenFeature.IntegrationTests/OpenFeature.IntegrationTests.csproj
+++ b/test/OpenFeature.IntegrationTests/OpenFeature.IntegrationTests.csproj
@@ -2,6 +2,7 @@
net8.0;net9.0;net10.0
+ Exe
@@ -16,7 +17,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderEventTests.cs b/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderEventTests.cs
index d41e91cf..a1f5eb22 100644
--- a/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderEventTests.cs
+++ b/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderEventTests.cs
@@ -38,7 +38,7 @@ public async Task InitializeAsync_OnSuccess_EmitsProviderReadyEvent()
var multiProvider = CreateMultiProvider(_provider1, _provider2);
// Act
- await multiProvider.InitializeAsync(_context);
+ await multiProvider.InitializeAsync(_context, TestContext.Current.CancellationToken);
// Assert
var events = await ReadEvents(multiProvider.GetEventChannel());
@@ -54,7 +54,7 @@ public async Task InitializeAsync_OnProviderFailure_EmitsProviderErrorEvent()
var multiProvider = CreateMultiProvider(failedProvider, _provider2);
// Act & Assert
- await Assert.ThrowsAsync(() => multiProvider.InitializeAsync(_context));
+ await Assert.ThrowsAsync(() => multiProvider.InitializeAsync(_context, TestContext.Current.CancellationToken));
// Verify the error event was emitted
var events = await ReadEvents(multiProvider.GetEventChannel());
@@ -70,7 +70,7 @@ public async Task EvaluateAsync_OnUnsupportedRunMode_EmitsProviderErrorEvent()
_strategy.RunMode.Returns((RunMode)999); // Invalid run mode
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, _context);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, _context, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(ErrorType.ProviderFatal, result.ErrorType);
@@ -92,7 +92,7 @@ public async Task EvaluateAsync_OnGeneralException_EmitsProviderErrorEvent()
.Throws(new InvalidOperationException("Evaluation failed"));
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, _context);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, _context, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(ErrorType.General, result.ErrorType);
@@ -119,7 +119,7 @@ public async Task HandleProviderEvent_OnConfigurationChanged_ReEmitsEventWithCor
// Act - Simulate child provider emitting configuration changed event
await EmitEventToProvider(_provider1, configEvent);
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert
var events = await ReadEvents(multiProvider.GetEventChannel());
@@ -138,7 +138,7 @@ public async Task HandleProviderEvent_OnProviderReady_EmitsMultiProviderReadyWhe
// Act - Simulate both child providers becoming ready
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderReady));
await EmitEventToProvider(_provider2, CreateEvent(ProviderEventTypes.ProviderReady));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert - Should emit MultiProvider ready event when all providers are ready
var events = await ReadEvents(multiProvider.GetEventChannel(), expectedCount: 2);
@@ -156,7 +156,7 @@ public async Task HandleProviderEvent_OnProviderError_EmitsMultiProviderErrorEve
// Act - Simulate child provider emitting error event
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderError, ErrorType.ProviderFatal));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert
var events = await ReadEvents(multiProvider.GetEventChannel());
@@ -173,7 +173,7 @@ public async Task HandleProviderEvent_OnProviderStale_EmitsMultiProviderStaleEve
// Act - Simulate child provider emitting stale event
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderStale));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert
var events = await ReadEvents(multiProvider.GetEventChannel());
@@ -190,7 +190,7 @@ public async Task HandleProviderEvent_OnSameStatus_DoesNotEmitEvent()
// Act - Simulate child provider emitting ready event when MultiProvider is already ready
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderReady));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert - Should not emit any events since status didn't change
var events = await ReadEvents(multiProvider.GetEventChannel(), expectedCount: 0, timeoutMs: 300);
@@ -202,15 +202,15 @@ public async Task MultipleProviders_WithStatusTransitions_EmitsCorrectAggregateE
{
// Arrange
var multiProvider = CreateMultiProvider(_provider1, _provider2);
- await multiProvider.InitializeAsync(_context);
- await Task.Delay(50);
+ await multiProvider.InitializeAsync(_context, TestContext.Current.CancellationToken);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Act - Simulate one provider going to error state
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderError, ErrorType.General));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Simulate the error provider recovering
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderReady));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert - Should see: Init Ready -> Error -> Ready
var events = await ReadEvents(multiProvider.GetEventChannel(), expectedCount: 3);
@@ -233,7 +233,7 @@ public async Task HandleProviderEvent_WithEventMetadata_PropagatesMetadata()
// Act
await EmitEventToProvider(_provider1, eventPayload);
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert
var events = await ReadEvents(multiProvider.GetEventChannel());
@@ -247,14 +247,14 @@ public async Task ShutdownAsync_StopsEventProcessing()
{
// Arrange
var multiProvider = CreateMultiProvider(_provider1);
- await multiProvider.InitializeAsync(_context);
+ await multiProvider.InitializeAsync(_context, TestContext.Current.CancellationToken);
// Act
- await multiProvider.ShutdownAsync();
+ await multiProvider.ShutdownAsync(TestContext.Current.CancellationToken);
// Try to emit an event after shutdown - it should not be processed
await EmitEventToProvider(_provider1, CreateEvent(ProviderEventTypes.ProviderReady));
- await Task.Delay(50);
+ await Task.Delay(50, TestContext.Current.CancellationToken);
// Assert - Should not process any events after shutdown
var events = await ReadEvents(multiProvider.GetEventChannel(), expectedCount: 0, timeoutMs: 300);
@@ -267,10 +267,10 @@ public async Task ShutdownAsync_WithProviderFailures_ThrowsAggregateException()
// Arrange
var failingProvider = new TestProvider("failing", shutdownException: new InvalidOperationException("Shutdown failed"));
var multiProvider = CreateMultiProvider(failingProvider, _provider2);
- await multiProvider.InitializeAsync(_context);
+ await multiProvider.InitializeAsync(_context, TestContext.Current.CancellationToken);
// Act & Assert - Should throw AggregateException due to provider shutdown failure
- var exception = await Assert.ThrowsAsync(() => multiProvider.ShutdownAsync());
+ var exception = await Assert.ThrowsAsync(() => multiProvider.ShutdownAsync(TestContext.Current.CancellationToken));
Assert.Contains("Failed to shutdown providers", exception.Message);
}
@@ -279,17 +279,17 @@ public async Task DisposeAsync_CleansUpEventProcessing()
{
// Arrange
var multiProvider = CreateMultiProvider(_provider1);
- await multiProvider.InitializeAsync(_context);
+ await multiProvider.InitializeAsync(_context, TestContext.Current.CancellationToken);
// Act
await multiProvider.DisposeAsync();
// Assert - Should not throw and should handle disposal gracefully
- await Task.Delay(100); // Give time for any potential processing
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Give time for any potential processing
// Verify that subsequent operations on disposed provider throw
await Assert.ThrowsAsync(() =>
- multiProvider.ResolveBooleanValueAsync(TestFlagKey, false));
+ multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, cancellationToken: TestContext.Current.CancellationToken));
}
// Helper methods
diff --git a/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTests.cs b/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTests.cs
index 615b67c7..b8e0131b 100644
--- a/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTests.cs
+++ b/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTests.cs
@@ -119,7 +119,7 @@ public async Task ResolveBooleanValueAsync_CallsEvaluateAsync()
.Returns(finalResult);
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -142,7 +142,7 @@ public async Task ResolveStringValueAsync_CallsEvaluateAsync()
.Returns(finalResult);
// Act
- var result = await multiProvider.ResolveStringValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveStringValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -163,7 +163,7 @@ public async Task InitializeAsync_WithAllSuccessfulProviders_InitializesAllProvi
this._mockProvider2.InitializeAsync(this._evaluationContext, Arg.Any()).Returns(Task.CompletedTask);
// Act
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
await this._mockProvider1.Received(1).InitializeAsync(this._evaluationContext, Arg.Any());
@@ -186,7 +186,7 @@ public async Task InitializeAsync_WithSomeFailingProviders_ThrowsAggregateExcept
this._mockProvider2.InitializeAsync(this._evaluationContext, Arg.Any()).ThrowsAsync(expectedException);
// Act & Assert
- var exception = await Assert.ThrowsAsync(() => multiProvider.InitializeAsync(this._evaluationContext));
+ var exception = await Assert.ThrowsAsync(() => multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken));
Assert.Contains("Failed to initialize providers", exception.Message);
Assert.Contains(Provider2Name, exception.Message);
Assert.Contains(expectedException, exception.InnerExceptions);
@@ -208,7 +208,7 @@ public async Task ShutdownAsync_WithAllSuccessfulProviders_ShutsDownAllProviders
this._mockProvider2.ShutdownAsync(Arg.Any()).Returns(Task.CompletedTask);
// Act
- await multiProvider.ShutdownAsync();
+ await multiProvider.ShutdownAsync(TestContext.Current.CancellationToken);
// Assert
await this._mockProvider1.Received(1).ShutdownAsync(Arg.Any());
@@ -231,7 +231,7 @@ public async Task ShutdownAsync_WithFatalProvider_ShutsDownAllProviders()
this._mockProvider2.ShutdownAsync(Arg.Any()).Returns(Task.CompletedTask);
// Act
- await multiProvider.ShutdownAsync();
+ await multiProvider.ShutdownAsync(TestContext.Current.CancellationToken);
// Assert
await this._mockProvider1.Received(1).ShutdownAsync(Arg.Any());
@@ -255,7 +255,7 @@ public async Task ShutdownAsync_WithSomeFailingProviders_ThrowsAggregateExceptio
this._mockProvider2.ShutdownAsync(Arg.Any()).ThrowsAsync(expectedException);
// Act & Assert
- var exception = await Assert.ThrowsAsync(() => multiProvider.ShutdownAsync());
+ var exception = await Assert.ThrowsAsync(() => multiProvider.ShutdownAsync(TestContext.Current.CancellationToken));
Assert.Contains("Failed to shutdown providers", exception.Message);
Assert.Contains(Provider2Name, exception.Message);
Assert.Contains(expectedException, exception.InnerExceptions);
@@ -292,7 +292,7 @@ public async Task ResolveDoubleValueAsync_CallsEvaluateAsync()
.Returns(finalResult);
// Act
- var result = await multiProvider.ResolveDoubleValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveDoubleValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -315,7 +315,7 @@ public async Task ResolveIntegerValueAsync_CallsEvaluateAsync()
.Returns(finalResult);
// Act
- var result = await multiProvider.ResolveIntegerValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveIntegerValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -337,7 +337,7 @@ public async Task ResolveStructureValueAsync_CallsEvaluateAsync()
.Returns(finalResult);
// Act
- var result = await multiProvider.ResolveStructureValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveStructureValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -369,7 +369,7 @@ public async Task EvaluateAsync_WithSequentialMode_EvaluatesProvidersSequentiall
.Returns(expectedDetails);
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -404,7 +404,7 @@ public async Task EvaluateAsync_WithParallelMode_EvaluatesProvidersInParallel()
.Returns(expectedDetails);
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -423,7 +423,7 @@ public async Task EvaluateAsync_WithUnsupportedRunMode_ReturnsErrorDetails()
this._mockStrategy.RunMode.Returns((RunMode)999); // Invalid enum value
// Act & Assert
- var details = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var details = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.ProviderFatal, details.ErrorType);
Assert.Equal(Reason.Error, details.Reason);
Assert.Contains("Unsupported run mode", details.ErrorMessage);
@@ -459,7 +459,7 @@ public async Task EvaluateAsync_WithStrategySkippingProvider_DoesNotCallSkippedP
.Returns(expectedDetails);
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, defaultValue, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedDetails, result);
@@ -613,7 +613,7 @@ public async Task InitializeAsync_WithAllSuccessfulProviders_CompletesWithoutExc
this._mockProvider3.InitializeAsync(this._evaluationContext, Arg.Any()).Returns(Task.CompletedTask);
// Act & Assert
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
// Verify all providers were called
await this._mockProvider1.Received(1).InitializeAsync(this._evaluationContext, Arg.Any());
@@ -639,7 +639,7 @@ public async Task ShutdownAsync_WithAllSuccessfulProviders_CompletesWithoutExcep
this._mockProvider3.ShutdownAsync(Arg.Any()).Returns(Task.CompletedTask);
// Act & Assert
- await multiProvider.ShutdownAsync();
+ await multiProvider.ShutdownAsync(TestContext.Current.CancellationToken);
// Verify all providers were called
await this._mockProvider1.Received(1).ShutdownAsync(Arg.Any());
@@ -757,7 +757,7 @@ public async Task InitializeAsync_AfterDispose_ShouldThrowObjectDisposedExceptio
// Assert
var exception = await Assert.ThrowsAsync(() =>
- multiProvider.InitializeAsync(this._evaluationContext));
+ multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), exception.ObjectName);
}
@@ -773,7 +773,7 @@ public async Task ShutdownAsync_AfterDispose_ShouldThrowObjectDisposedException(
// Assert
var exception = await Assert.ThrowsAsync(() =>
- multiProvider.ShutdownAsync());
+ multiProvider.ShutdownAsync(TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), exception.ObjectName);
}
@@ -789,7 +789,7 @@ public async Task InitializeAsync_WhenAlreadyDisposed_DuringExecution_ShouldExit
// Act & Assert
await Assert.ThrowsAsync(() =>
- multiProvider.InitializeAsync(this._evaluationContext));
+ multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken));
// Verify that the underlying provider was never called since the object was disposed
await this._mockProvider1.DidNotReceive().InitializeAsync(Arg.Any(), Arg.Any());
@@ -807,7 +807,7 @@ public async Task ShutdownAsync_WhenAlreadyDisposed_DuringExecution_ShouldExitEa
// Act & Assert
await Assert.ThrowsAsync(() =>
- multiProvider.ShutdownAsync());
+ multiProvider.ShutdownAsync(TestContext.Current.CancellationToken));
// Verify that the underlying provider was never called since the object was disposed
await this._mockProvider1.DidNotReceive().ShutdownAsync(Arg.Any());
@@ -825,23 +825,23 @@ public async Task EvaluateAsync_AfterDispose_ShouldThrowObjectDisposedException(
// Assert - All evaluate methods should throw ObjectDisposedException
var boolException = await Assert.ThrowsAsync(() =>
- multiProvider.ResolveBooleanValueAsync(TestFlagKey, false));
+ multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), boolException.ObjectName);
var stringException = await Assert.ThrowsAsync(() =>
- multiProvider.ResolveStringValueAsync(TestFlagKey, "default"));
+ multiProvider.ResolveStringValueAsync(TestFlagKey, "default", cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), stringException.ObjectName);
var intException = await Assert.ThrowsAsync(() =>
- multiProvider.ResolveIntegerValueAsync(TestFlagKey, 0));
+ multiProvider.ResolveIntegerValueAsync(TestFlagKey, 0, cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), intException.ObjectName);
var doubleException = await Assert.ThrowsAsync(() =>
- multiProvider.ResolveDoubleValueAsync(TestFlagKey, 0.0));
+ multiProvider.ResolveDoubleValueAsync(TestFlagKey, 0.0, cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), doubleException.ObjectName);
var structureException = await Assert.ThrowsAsync(() =>
- multiProvider.ResolveStructureValueAsync(TestFlagKey, new Value()));
+ multiProvider.ResolveStructureValueAsync(TestFlagKey, new Value(), cancellationToken: TestContext.Current.CancellationToken));
Assert.Equal(nameof(MultiProvider), structureException.ObjectName);
}
@@ -952,7 +952,7 @@ public async Task EvaluateAsync_WithProviderHooks_ExecutesHooksForEachProvider()
var multiProvider = new MultiProvider(providerEntries, this._mockStrategy);
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, this._evaluationContext);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedValue, result.Value);
@@ -1022,7 +1022,7 @@ public async Task EvaluateAsync_WithHookContextModification_IsolatesContextBetwe
var multiProvider = new MultiProvider(providerEntries, this._mockStrategy);
// Act
- await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, this._evaluationContext);
+ await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert - Verify context isolation
Assert.NotNull(capturedContext1);
@@ -1079,7 +1079,7 @@ public async Task EvaluateAsync_WithHookError_HandlesErrorAndContinuesEvaluation
var multiProvider = new MultiProvider(providerEntries, this._mockStrategy);
// Act
- var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, this._evaluationContext);
+ var result = await multiProvider.ResolveBooleanValueAsync(TestFlagKey, false, this._evaluationContext, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(expectedValue, result.Value);
diff --git a/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTrackingTests.cs b/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTrackingTests.cs
index d0d9d3d5..7f703ada 100644
--- a/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTrackingTests.cs
+++ b/test/OpenFeature.Providers.MultiProvider.Tests/MultiProviderTrackingTests.cs
@@ -32,7 +32,7 @@ public async Task Track_WithMultipleReadyProviders_CallsTrackOnAllReadyProviders
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
var trackingDetails = TrackingEventDetails.Builder().SetValue(99.99).Build();
@@ -68,7 +68,7 @@ public async Task Track_WithNullEvaluationContext_CallsTrackWithNullContext()
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
// Act
multiProvider.Track(TestTrackingEventName);
@@ -95,7 +95,7 @@ public async Task Track_WithNullTrackingDetails_CallsTrackWithNullDetails()
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
// Act
multiProvider.Track(TestTrackingEventName, this._evaluationContext);
@@ -131,7 +131,7 @@ public async Task Track_WhenProviderThrowsException_ContinuesWithOtherProviders(
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
// Manually set all providers to Ready status
throwingProvider.Status.Returns(ProviderStatus.Ready);
@@ -161,7 +161,7 @@ public async Task Track_WhenDisposed_ThrowsObjectDisposedException()
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
await multiProvider.DisposeAsync();
// Act & Assert
@@ -198,7 +198,7 @@ public async Task Track_WithCustomStrategy_RespectsStrategyDecision()
};
var multiProvider = new MultiProvider(providerEntries, customStrategy);
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
var trackingDetails = TrackingEventDetails.Builder().SetValue(99.99).Build();
@@ -233,7 +233,7 @@ public async Task Track_WithComplexTrackingDetails_PropagatesAllDetails()
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
var trackingDetails = TrackingEventDetails.Builder()
.SetValue(199.99)
@@ -285,7 +285,7 @@ public async Task Track_WhenInvalidTrackingEventName_DoesNotCallProviders(string
};
var multiProvider = new MultiProvider(providerEntries, new FirstMatchStrategy());
- await multiProvider.InitializeAsync(this._evaluationContext);
+ await multiProvider.InitializeAsync(this._evaluationContext, TestContext.Current.CancellationToken);
// Act & Assert
multiProvider.Track(trackingEventName!, this._evaluationContext, TrackingEventDetails.Empty);
diff --git a/test/OpenFeature.Providers.MultiProvider.Tests/OpenFeature.Providers.MultiProvider.Tests.csproj b/test/OpenFeature.Providers.MultiProvider.Tests/OpenFeature.Providers.MultiProvider.Tests.csproj
index 1a7dae71..c790a5d7 100644
--- a/test/OpenFeature.Providers.MultiProvider.Tests/OpenFeature.Providers.MultiProvider.Tests.csproj
+++ b/test/OpenFeature.Providers.MultiProvider.Tests/OpenFeature.Providers.MultiProvider.Tests.csproj
@@ -2,6 +2,7 @@
OpenFeature.Providers.MultiProvider.Tests
+ Exe
@@ -19,7 +20,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
index 7ef471e4..14850be9 100644
--- a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
+++ b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
@@ -2,15 +2,15 @@ namespace OpenFeature.Tests;
public class ClearOpenFeatureInstanceFixture : IAsyncLifetime
{
- public Task InitializeAsync()
+ public ValueTask InitializeAsync()
{
Api.ResetApi();
- return Task.CompletedTask;
+ return ValueTask.CompletedTask;
}
// Make sure the singleton is cleared between tests
- public async Task DisposeAsync()
+ public async ValueTask DisposeAsync()
{
await Api.Instance.ShutdownAsync().ConfigureAwait(false);
}
diff --git a/test/OpenFeature.Tests/FeatureProviderTests.cs b/test/OpenFeature.Tests/FeatureProviderTests.cs
index 8bea7037..8be88ac5 100644
--- a/test/OpenFeature.Tests/FeatureProviderTests.cs
+++ b/test/OpenFeature.Tests/FeatureProviderTests.cs
@@ -39,23 +39,23 @@ public async Task Provider_Must_Resolve_Flag_Values()
var boolResolutionDetails = new ResolutionDetails(flagName, defaultBoolValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(boolResolutionDetails, await provider.ResolveBooleanValueAsync(flagName, defaultBoolValue));
+ Assert.Equivalent(boolResolutionDetails, await provider.ResolveBooleanValueAsync(flagName, defaultBoolValue, cancellationToken: TestContext.Current.CancellationToken));
var integerResolutionDetails = new ResolutionDetails(flagName, defaultIntegerValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(integerResolutionDetails, await provider.ResolveIntegerValueAsync(flagName, defaultIntegerValue));
+ Assert.Equivalent(integerResolutionDetails, await provider.ResolveIntegerValueAsync(flagName, defaultIntegerValue, cancellationToken: TestContext.Current.CancellationToken));
var doubleResolutionDetails = new ResolutionDetails(flagName, defaultDoubleValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(doubleResolutionDetails, await provider.ResolveDoubleValueAsync(flagName, defaultDoubleValue));
+ Assert.Equivalent(doubleResolutionDetails, await provider.ResolveDoubleValueAsync(flagName, defaultDoubleValue, cancellationToken: TestContext.Current.CancellationToken));
var stringResolutionDetails = new ResolutionDetails(flagName, defaultStringValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(stringResolutionDetails, await provider.ResolveStringValueAsync(flagName, defaultStringValue));
+ Assert.Equivalent(stringResolutionDetails, await provider.ResolveStringValueAsync(flagName, defaultStringValue, cancellationToken: TestContext.Current.CancellationToken));
var structureResolutionDetails = new ResolutionDetails(flagName, defaultStructureValue,
ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(structureResolutionDetails, await provider.ResolveStructureValueAsync(flagName, defaultStructureValue));
+ Assert.Equivalent(structureResolutionDetails, await provider.ResolveStructureValueAsync(flagName, defaultStructureValue, cancellationToken: TestContext.Current.CancellationToken));
}
[Fact]
@@ -74,59 +74,52 @@ public async Task Provider_Must_ErrorType()
var providerMock = Substitute.For();
const string testMessage = "An error message";
- providerMock.ResolveBooleanValueAsync(flagName, defaultBoolValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName, defaultBoolValue, ErrorType.General,
+ providerMock.ResolveBooleanValueAsync(flagName, defaultBoolValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultBoolValue, ErrorType.General,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant, testMessage));
- providerMock.ResolveIntegerValueAsync(flagName, defaultIntegerValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName, defaultIntegerValue, ErrorType.ParseError,
+ providerMock.ResolveIntegerValueAsync(flagName, defaultIntegerValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultIntegerValue, ErrorType.ParseError,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant, testMessage));
- providerMock.ResolveDoubleValueAsync(flagName, defaultDoubleValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName, defaultDoubleValue, ErrorType.InvalidContext,
+ providerMock.ResolveDoubleValueAsync(flagName, defaultDoubleValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultDoubleValue, ErrorType.InvalidContext,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant, testMessage));
- providerMock.ResolveStringValueAsync(flagName, defaultStringValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName, defaultStringValue, ErrorType.TypeMismatch,
+ providerMock.ResolveStringValueAsync(flagName, defaultStringValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultStringValue, ErrorType.TypeMismatch,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant, testMessage));
- providerMock.ResolveStructureValueAsync(flagName, defaultStructureValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName, defaultStructureValue, ErrorType.FlagNotFound,
+ providerMock.ResolveStructureValueAsync(flagName, defaultStructureValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultStructureValue, ErrorType.FlagNotFound,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant, testMessage));
- providerMock.ResolveStructureValueAsync(flagName2, defaultStructureValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName2, defaultStructureValue, ErrorType.ProviderNotReady,
+ providerMock.ResolveStructureValueAsync(flagName2, defaultStructureValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName2, defaultStructureValue, ErrorType.ProviderNotReady,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant, testMessage));
- providerMock.ResolveBooleanValueAsync(flagName2, defaultBoolValue, Arg.Any())
- .Returns(new ResolutionDetails(flagName2, defaultBoolValue, ErrorType.TargetingKeyMissing,
+ providerMock.ResolveBooleanValueAsync(flagName2, defaultBoolValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName2, defaultBoolValue, ErrorType.TargetingKeyMissing,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant));
- var boolRes = await providerMock.ResolveBooleanValueAsync(flagName, defaultBoolValue);
+ var boolRes = await providerMock.ResolveBooleanValueAsync(flagName, defaultBoolValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.General, boolRes.ErrorType);
Assert.Equal(testMessage, boolRes.ErrorMessage);
- var intRes = await providerMock.ResolveIntegerValueAsync(flagName, defaultIntegerValue);
+ var intRes = await providerMock.ResolveIntegerValueAsync(flagName, defaultIntegerValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.ParseError, intRes.ErrorType);
Assert.Equal(testMessage, intRes.ErrorMessage);
- var doubleRes = await providerMock.ResolveDoubleValueAsync(flagName, defaultDoubleValue);
+ var doubleRes = await providerMock.ResolveDoubleValueAsync(flagName, defaultDoubleValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.InvalidContext, doubleRes.ErrorType);
Assert.Equal(testMessage, doubleRes.ErrorMessage);
- var stringRes = await providerMock.ResolveStringValueAsync(flagName, defaultStringValue);
+ var stringRes = await providerMock.ResolveStringValueAsync(flagName, defaultStringValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.TypeMismatch, stringRes.ErrorType);
Assert.Equal(testMessage, stringRes.ErrorMessage);
- var structRes1 = await providerMock.ResolveStructureValueAsync(flagName, defaultStructureValue);
+ var structRes1 = await providerMock.ResolveStructureValueAsync(flagName, defaultStructureValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.FlagNotFound, structRes1.ErrorType);
Assert.Equal(testMessage, structRes1.ErrorMessage);
- var structRes2 = await providerMock.ResolveStructureValueAsync(flagName2, defaultStructureValue);
+ var structRes2 = await providerMock.ResolveStructureValueAsync(flagName2, defaultStructureValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.ProviderNotReady, structRes2.ErrorType);
Assert.Equal(testMessage, structRes2.ErrorMessage);
- var boolRes2 = await providerMock.ResolveBooleanValueAsync(flagName2, defaultBoolValue);
+ var boolRes2 = await providerMock.ResolveBooleanValueAsync(flagName2, defaultBoolValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.TargetingKeyMissing, boolRes2.ErrorType);
Assert.Null(boolRes2.ErrorMessage);
}
diff --git a/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs b/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs
index 5c27959b..70bad07a 100644
--- a/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs
+++ b/test/OpenFeature.Tests/Hooks/LoggingHookTests.cs
@@ -22,7 +22,7 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Debug_Log()
var hook = new LoggingHook(logger, includeContext: false);
// Act
- await hook.BeforeAsync(context);
+ await hook.BeforeAsync(context, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -57,7 +57,7 @@ public async Task BeforeAsync_Without_EvaluationContext_Generates_Correct_Log_Me
var hook = new LoggingHook(logger, includeContext: false);
// Act
- await hook.BeforeAsync(context);
+ await hook.BeforeAsync(context, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -98,7 +98,7 @@ public async Task BeforeAsync_With_EvaluationContext_Generates_Correct_Log_Messa
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.BeforeAsync(context);
+ await hook.BeforeAsync(context, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -130,7 +130,7 @@ public async Task BeforeAsync_With_No_EvaluationContext_Generates_Correct_Log_Me
// Act
var hook = new LoggingHook(logger, includeContext: true);
- await hook.BeforeAsync(context);
+ await hook.BeforeAsync(context, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -168,7 +168,7 @@ public async Task ErrorAsync_Without_EvaluationContext_Generates_Error_Log()
var exception = new Exception("Error within hook!");
// Act
- await hook.ErrorAsync(context, exception);
+ await hook.ErrorAsync(context, exception, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -194,7 +194,7 @@ public async Task ErrorAsync_Without_EvaluationContext_Generates_Correct_Log_Mes
var exception = new Exception("Error within hook!");
// Act
- await hook.ErrorAsync(context, exception);
+ await hook.ErrorAsync(context, exception, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -238,7 +238,7 @@ public async Task ErrorAsync_With_EvaluationContext_Generates_Correct_Log_Messag
var exception = new Exception("Error within hook!");
// Act
- await hook.ErrorAsync(context, exception);
+ await hook.ErrorAsync(context, exception, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -271,7 +271,7 @@ public async Task ErrorAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes
var exception = new Exception("Error within hook!");
// Act
- await hook.ErrorAsync(context, exception);
+ await hook.ErrorAsync(context, exception, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -309,7 +309,7 @@ public async Task AfterAsync_Without_EvaluationContext_Generates_Debug_Log()
var hook = new LoggingHook(logger, includeContext: false);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -334,7 +334,7 @@ public async Task AfterAsync_Without_EvaluationContext_Generates_Correct_Log_Mes
var hook = new LoggingHook(logger, includeContext: false);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -376,7 +376,7 @@ public async Task AfterAsync_With_EvaluationContext_Generates_Correct_Log_Messag
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -416,7 +416,7 @@ public async Task AfterAsync_With_No_EvaluationContext_Generates_Correct_Log_Mes
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(1, logger.Collector.Count);
@@ -464,7 +464,7 @@ public async Task With_Structure_Type_In_Context_Returns_Qualified_Name_Of_Value
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -507,7 +507,7 @@ public async Task Without_Domain_Returns_Missing()
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -548,7 +548,7 @@ public async Task Without_Provider_Returns_Missing()
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -589,7 +589,7 @@ public async Task Without_DefaultValue_Returns_Missing()
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
@@ -630,7 +630,7 @@ public async Task Without_EvaluationContextValue_Returns_Nothing()
var hook = new LoggingHook(logger, includeContext: true);
// Act
- await hook.AfterAsync(context, details);
+ await hook.AfterAsync(context, details, cancellationToken: TestContext.Current.CancellationToken);
// Assert
var record = logger.LatestRecord;
diff --git a/test/OpenFeature.Tests/Hooks/MetricsHookTests.cs b/test/OpenFeature.Tests/Hooks/MetricsHookTests.cs
index f1c3be3a..30fb46f0 100644
--- a/test/OpenFeature.Tests/Hooks/MetricsHookTests.cs
+++ b/test/OpenFeature.Tests/Hooks/MetricsHookTests.cs
@@ -20,9 +20,7 @@ public async Task After_Test()
new ClientMetadata("my-client", "1.0"), new Metadata("my-provider"), evaluationContext);
// Act
- await metricsHook.AfterAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"),
- new Dictionary()).ConfigureAwait(true);
+ await metricsHook.AfterAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -47,9 +45,7 @@ public async Task Without_Reason_After_Test_Defaults_To_Unknown()
new ClientMetadata("my-client", "1.0"), new Metadata("my-provider"), evaluationContext);
// Act
- await metricsHook.AfterAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, reason: null, "default"),
- new Dictionary()).ConfigureAwait(true);
+ await metricsHook.AfterAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, reason: null, "default"), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -78,9 +74,7 @@ public async Task With_CustomDimensions_After_Test()
new ClientMetadata("my-client", "1.0"), new Metadata("my-provider"), evaluationContext);
// Act
- await metricsHook.AfterAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"),
- new Dictionary()).ConfigureAwait(true);
+ await metricsHook.AfterAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -116,9 +110,7 @@ public async Task With_FlagMetadataCallback_After_Test()
});
// Act
- await metricsHook.AfterAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default", errorMessage: null, flagMetadata),
- new Dictionary()).ConfigureAwait(true);
+ await metricsHook.AfterAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default", errorMessage: null, flagMetadata), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -146,7 +138,7 @@ public async Task Error_Test()
var errorMessage = "An error occurred during evaluation";
// Act
- await metricsHook.ErrorAsync(ctx, new Exception(errorMessage), new Dictionary()).ConfigureAwait(true);
+ await metricsHook.ErrorAsync(ctx, new Exception(errorMessage), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -177,7 +169,7 @@ public async Task With_CustomDimensions_Error_Test()
var errorMessage = "An error occurred during evaluation";
// Act
- await metricsHook.ErrorAsync(ctx, new Exception(errorMessage), new Dictionary()).ConfigureAwait(true);
+ await metricsHook.ErrorAsync(ctx, new Exception(errorMessage), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -204,7 +196,7 @@ public async Task Finally_Test()
var evaluationDetails = new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default");
// Act
- await metricsHook.FinallyAsync(ctx, evaluationDetails, new Dictionary()).ConfigureAwait(true);
+ await metricsHook.FinallyAsync(ctx, evaluationDetails, new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -234,7 +226,7 @@ public async Task With_CustomDimensions_Finally_Test()
var evaluationDetails = new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default");
// Act
- await metricsHook.FinallyAsync(ctx, evaluationDetails, new Dictionary()).ConfigureAwait(true);
+ await metricsHook.FinallyAsync(ctx, evaluationDetails, new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -270,7 +262,7 @@ public async Task With_FlagMetadataCallback_Finally_Test()
var evaluationDetails = new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default", flagMetadata: flagMetadata);
// Act
- await metricsHook.FinallyAsync(ctx, evaluationDetails, new Dictionary()).ConfigureAwait(true);
+ await metricsHook.FinallyAsync(ctx, evaluationDetails, new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector.LastMeasurement;
@@ -297,7 +289,7 @@ public async Task Before_Test()
new ClientMetadata("my-client", "1.0"), new Metadata("my-provider"), evaluationContext);
// Act
- await metricsHook.BeforeAsync(ctx, new Dictionary()).ConfigureAwait(true);
+ await metricsHook.BeforeAsync(ctx, new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector1.LastMeasurement;
@@ -327,7 +319,7 @@ public async Task With_CustomDimensions_Before_Test()
new ClientMetadata("my-client", "1.0"), new Metadata("my-provider"), evaluationContext);
// Act
- await metricsHook.BeforeAsync(ctx, new Dictionary()).ConfigureAwait(true);
+ await metricsHook.BeforeAsync(ctx, new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
var measurements = collector1.LastMeasurement;
diff --git a/test/OpenFeature.Tests/Hooks/TraceEnricherHookTests.cs b/test/OpenFeature.Tests/Hooks/TraceEnricherHookTests.cs
index 5f0b617d..b0bca631 100644
--- a/test/OpenFeature.Tests/Hooks/TraceEnricherHookTests.cs
+++ b/test/OpenFeature.Tests/Hooks/TraceEnricherHookTests.cs
@@ -47,9 +47,7 @@ public async Task TestFinally()
// Act
var span = this._tracer.StartActiveSpan("my-span");
- await traceEnricherHook.FinallyAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"),
- new Dictionary()).ConfigureAwait(true);
+ await traceEnricherHook.FinallyAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
span.End();
this._tracerProvider.ForceFlush();
@@ -83,9 +81,7 @@ public async Task TestFinally_WithCustomDimension()
// Act
var span = this._tracer.StartActiveSpan("my-span");
- await traceEnricherHook.FinallyAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"),
- new Dictionary()).ConfigureAwait(true);
+ await traceEnricherHook.FinallyAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
span.End();
this._tracerProvider.ForceFlush();
@@ -126,9 +122,7 @@ public async Task TestFinally_WithFlagEvaluationMetadata()
// Act
var span = this._tracer.StartActiveSpan("my-span");
- await traceEnricherHook.FinallyAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default", flagMetadata: flagMetadata),
- new Dictionary()).ConfigureAwait(true);
+ await traceEnricherHook.FinallyAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default", flagMetadata: flagMetadata), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
span.End();
this._tracerProvider.ForceFlush();
@@ -157,9 +151,7 @@ public async Task TestFinally_NoSpan()
new ClientMetadata("my-client", "1.0"), new Metadata("my-provider"), evaluationContext);
// Act
- await traceEnricherHook.FinallyAsync(ctx,
- new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"),
- new Dictionary()).ConfigureAwait(true);
+ await traceEnricherHook.FinallyAsync(ctx, new FlagEvaluationDetails("my-flag", "foo", Constant.ErrorType.None, "STATIC", "default"), new Dictionary(), TestContext.Current.CancellationToken).ConfigureAwait(true);
this._tracerProvider.ForceFlush();
diff --git a/test/OpenFeature.Tests/OpenFeature.Tests.csproj b/test/OpenFeature.Tests/OpenFeature.Tests.csproj
index 7a529650..e79aa09b 100644
--- a/test/OpenFeature.Tests/OpenFeature.Tests.csproj
+++ b/test/OpenFeature.Tests/OpenFeature.Tests.csproj
@@ -2,6 +2,7 @@
OpenFeature.Tests
+ Exe
@@ -19,7 +20,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/test/OpenFeature.Tests/OpenFeatureClientTests.cs b/test/OpenFeature.Tests/OpenFeatureClientTests.cs
index 9ea3f0dc..13d8ad6d 100644
--- a/test/OpenFeature.Tests/OpenFeatureClientTests.cs
+++ b/test/OpenFeature.Tests/OpenFeatureClientTests.cs
@@ -70,28 +70,28 @@ public async Task OpenFeatureClient_Should_Allow_Flag_Evaluation()
var defaultStructureValue = fixture.Create();
var emptyFlagOptions = new FlagEvaluationOptions(ImmutableList.Empty, ImmutableDictionary.Empty);
- await Api.Instance.SetProviderAsync(new NoOpFeatureProvider());
+ await Api.Instance.SetProviderAsync(new NoOpFeatureProvider(), TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- Assert.Equal(defaultBoolValue, await client.GetBooleanValueAsync(flagName, defaultBoolValue));
- Assert.Equal(defaultBoolValue, await client.GetBooleanValueAsync(flagName, defaultBoolValue, EvaluationContext.Empty));
- Assert.Equal(defaultBoolValue, await client.GetBooleanValueAsync(flagName, defaultBoolValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equal(defaultBoolValue, await client.GetBooleanValueAsync(flagName, defaultBoolValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultBoolValue, await client.GetBooleanValueAsync(flagName, defaultBoolValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultBoolValue, await client.GetBooleanValueAsync(flagName, defaultBoolValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
- Assert.Equal(defaultIntegerValue, await client.GetIntegerValueAsync(flagName, defaultIntegerValue));
- Assert.Equal(defaultIntegerValue, await client.GetIntegerValueAsync(flagName, defaultIntegerValue, EvaluationContext.Empty));
- Assert.Equal(defaultIntegerValue, await client.GetIntegerValueAsync(flagName, defaultIntegerValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equal(defaultIntegerValue, await client.GetIntegerValueAsync(flagName, defaultIntegerValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultIntegerValue, await client.GetIntegerValueAsync(flagName, defaultIntegerValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultIntegerValue, await client.GetIntegerValueAsync(flagName, defaultIntegerValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
- Assert.Equal(defaultDoubleValue, await client.GetDoubleValueAsync(flagName, defaultDoubleValue));
- Assert.Equal(defaultDoubleValue, await client.GetDoubleValueAsync(flagName, defaultDoubleValue, EvaluationContext.Empty));
- Assert.Equal(defaultDoubleValue, await client.GetDoubleValueAsync(flagName, defaultDoubleValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equal(defaultDoubleValue, await client.GetDoubleValueAsync(flagName, defaultDoubleValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultDoubleValue, await client.GetDoubleValueAsync(flagName, defaultDoubleValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultDoubleValue, await client.GetDoubleValueAsync(flagName, defaultDoubleValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
- Assert.Equal(defaultStringValue, await client.GetStringValueAsync(flagName, defaultStringValue));
- Assert.Equal(defaultStringValue, await client.GetStringValueAsync(flagName, defaultStringValue, EvaluationContext.Empty));
- Assert.Equal(defaultStringValue, await client.GetStringValueAsync(flagName, defaultStringValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equal(defaultStringValue, await client.GetStringValueAsync(flagName, defaultStringValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultStringValue, await client.GetStringValueAsync(flagName, defaultStringValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equal(defaultStringValue, await client.GetStringValueAsync(flagName, defaultStringValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
- Assert.Equivalent(defaultStructureValue, await client.GetObjectValueAsync(flagName, defaultStructureValue));
- Assert.Equivalent(defaultStructureValue, await client.GetObjectValueAsync(flagName, defaultStructureValue, EvaluationContext.Empty));
- Assert.Equivalent(defaultStructureValue, await client.GetObjectValueAsync(flagName, defaultStructureValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equivalent(defaultStructureValue, await client.GetObjectValueAsync(flagName, defaultStructureValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(defaultStructureValue, await client.GetObjectValueAsync(flagName, defaultStructureValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(defaultStructureValue, await client.GetObjectValueAsync(flagName, defaultStructureValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
}
[Fact]
@@ -116,33 +116,33 @@ public async Task OpenFeatureClient_Should_Allow_Details_Flag_Evaluation()
var defaultStructureValue = fixture.Create();
var emptyFlagOptions = new FlagEvaluationOptions(ImmutableList.Empty, ImmutableDictionary.Empty);
- await Api.Instance.SetProviderAsync(new NoOpFeatureProvider());
+ await Api.Instance.SetProviderAsync(new NoOpFeatureProvider(), TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
var boolFlagEvaluationDetails = new FlagEvaluationDetails(flagName, defaultBoolValue, ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(boolFlagEvaluationDetails, await client.GetBooleanDetailsAsync(flagName, defaultBoolValue));
- Assert.Equivalent(boolFlagEvaluationDetails, await client.GetBooleanDetailsAsync(flagName, defaultBoolValue, EvaluationContext.Empty));
- Assert.Equivalent(boolFlagEvaluationDetails, await client.GetBooleanDetailsAsync(flagName, defaultBoolValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equivalent(boolFlagEvaluationDetails, await client.GetBooleanDetailsAsync(flagName, defaultBoolValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(boolFlagEvaluationDetails, await client.GetBooleanDetailsAsync(flagName, defaultBoolValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(boolFlagEvaluationDetails, await client.GetBooleanDetailsAsync(flagName, defaultBoolValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
var integerFlagEvaluationDetails = new FlagEvaluationDetails(flagName, defaultIntegerValue, ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(integerFlagEvaluationDetails, await client.GetIntegerDetailsAsync(flagName, defaultIntegerValue));
- Assert.Equivalent(integerFlagEvaluationDetails, await client.GetIntegerDetailsAsync(flagName, defaultIntegerValue, EvaluationContext.Empty));
- Assert.Equivalent(integerFlagEvaluationDetails, await client.GetIntegerDetailsAsync(flagName, defaultIntegerValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equivalent(integerFlagEvaluationDetails, await client.GetIntegerDetailsAsync(flagName, defaultIntegerValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(integerFlagEvaluationDetails, await client.GetIntegerDetailsAsync(flagName, defaultIntegerValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(integerFlagEvaluationDetails, await client.GetIntegerDetailsAsync(flagName, defaultIntegerValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
var doubleFlagEvaluationDetails = new FlagEvaluationDetails(flagName, defaultDoubleValue, ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(doubleFlagEvaluationDetails, await client.GetDoubleDetailsAsync(flagName, defaultDoubleValue));
- Assert.Equivalent(doubleFlagEvaluationDetails, await client.GetDoubleDetailsAsync(flagName, defaultDoubleValue, EvaluationContext.Empty));
- Assert.Equivalent(doubleFlagEvaluationDetails, await client.GetDoubleDetailsAsync(flagName, defaultDoubleValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equivalent(doubleFlagEvaluationDetails, await client.GetDoubleDetailsAsync(flagName, defaultDoubleValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(doubleFlagEvaluationDetails, await client.GetDoubleDetailsAsync(flagName, defaultDoubleValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(doubleFlagEvaluationDetails, await client.GetDoubleDetailsAsync(flagName, defaultDoubleValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
var stringFlagEvaluationDetails = new FlagEvaluationDetails(flagName, defaultStringValue, ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(stringFlagEvaluationDetails, await client.GetStringDetailsAsync(flagName, defaultStringValue));
- Assert.Equivalent(stringFlagEvaluationDetails, await client.GetStringDetailsAsync(flagName, defaultStringValue, EvaluationContext.Empty));
- Assert.Equivalent(stringFlagEvaluationDetails, await client.GetStringDetailsAsync(flagName, defaultStringValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equivalent(stringFlagEvaluationDetails, await client.GetStringDetailsAsync(flagName, defaultStringValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(stringFlagEvaluationDetails, await client.GetStringDetailsAsync(flagName, defaultStringValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(stringFlagEvaluationDetails, await client.GetStringDetailsAsync(flagName, defaultStringValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
var structureFlagEvaluationDetails = new FlagEvaluationDetails(flagName, defaultStructureValue, ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
- Assert.Equivalent(structureFlagEvaluationDetails, await client.GetObjectDetailsAsync(flagName, defaultStructureValue));
- Assert.Equivalent(structureFlagEvaluationDetails, await client.GetObjectDetailsAsync(flagName, defaultStructureValue, EvaluationContext.Empty));
- Assert.Equivalent(structureFlagEvaluationDetails, await client.GetObjectDetailsAsync(flagName, defaultStructureValue, EvaluationContext.Empty, emptyFlagOptions));
+ Assert.Equivalent(structureFlagEvaluationDetails, await client.GetObjectDetailsAsync(flagName, defaultStructureValue, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(structureFlagEvaluationDetails, await client.GetObjectDetailsAsync(flagName, defaultStructureValue, EvaluationContext.Empty, cancellationToken: TestContext.Current.CancellationToken));
+ Assert.Equivalent(structureFlagEvaluationDetails, await client.GetObjectDetailsAsync(flagName, defaultStructureValue, EvaluationContext.Empty, emptyFlagOptions, TestContext.Current.CancellationToken));
}
[Fact]
@@ -163,18 +163,18 @@ public async Task OpenFeatureClient_Should_Return_DefaultValue_When_Type_Mismatc
var mockedLogger = Substitute.For>();
// This will fail to case a String to TestStructure
- mockedFeatureProvider.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any()).Throws();
+ mockedFeatureProvider.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Throws();
mockedFeatureProvider.GetMetadata().Returns(new Metadata(fixture.Create()));
mockedFeatureProvider.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(mockedFeatureProvider);
+ await Api.Instance.SetProviderAsync(mockedFeatureProvider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion, mockedLogger);
- var evaluationDetails = await client.GetObjectDetailsAsync(flagName, defaultValue);
+ var evaluationDetails = await client.GetObjectDetailsAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.TypeMismatch, evaluationDetails.ErrorType);
Assert.Equal(new InvalidCastException().Message, evaluationDetails.ErrorMessage);
- _ = mockedFeatureProvider.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any());
+ _ = mockedFeatureProvider.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
mockedLogger.Received(0).IsEnabled(LogLevel.Error);
}
@@ -189,7 +189,7 @@ public async Task Provider_Status_Should_Be_Ready_If_Init_Succeeds()
var provider = new TestProvider();
FeatureClient client = Api.Instance.GetClient(name);
Assert.Equal(ProviderStatus.NotReady, provider.Status);
- await Api.Instance.SetProviderAsync(name, provider);
+ await Api.Instance.SetProviderAsync(name, provider, TestContext.Current.CancellationToken);
// after init fails fatally, status should be READY
Assert.Equal(ProviderStatus.Ready, client.ProviderStatus);
@@ -205,7 +205,7 @@ public async Task Provider_Status_Should_Be_Error_If_Init_Fails()
var provider = new TestProvider("some-name", new GeneralException("fake"));
FeatureClient client = Api.Instance.GetClient(name);
Assert.Equal(ProviderStatus.NotReady, provider.Status);
- await Api.Instance.SetProviderAsync(name, provider);
+ await Api.Instance.SetProviderAsync(name, provider, TestContext.Current.CancellationToken);
// after init fails fatally, status should be ERROR
Assert.Equal(ProviderStatus.Error, client.ProviderStatus);
@@ -221,7 +221,7 @@ public async Task Provider_Status_Should_Be_Fatal_If_Init_Fatal()
var provider = new TestProvider(name, new ProviderFatalException("fatal"));
FeatureClient client = Api.Instance.GetClient(name);
Assert.Equal(ProviderStatus.NotReady, provider.Status);
- await Api.Instance.SetProviderAsync(name, provider);
+ await Api.Instance.SetProviderAsync(name, provider, TestContext.Current.CancellationToken);
// after init fails fatally, status should be FATAL
Assert.Equal(ProviderStatus.Fatal, client.ProviderStatus);
@@ -238,9 +238,9 @@ public async Task Must_Short_Circuit_Not_Ready()
var provider = new TestProvider(name, null, int.MaxValue);
FeatureClient client = Api.Instance.GetClient(name);
Assert.Equal(ProviderStatus.NotReady, provider.Status);
- _ = Api.Instance.SetProviderAsync(name, provider);
+ _ = Api.Instance.SetProviderAsync(name, provider, TestContext.Current.CancellationToken);
- var details = await client.GetStringDetailsAsync("some-flag", defaultStr);
+ var details = await client.GetStringDetailsAsync("some-flag", defaultStr, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(defaultStr, details.Value);
Assert.Equal(ErrorType.ProviderNotReady, details.ErrorType);
Assert.Equal(Reason.Error, details.Reason);
@@ -257,9 +257,9 @@ public async Task Must_Short_Circuit_Fatal()
var provider = new TestProvider(name, new ProviderFatalException("fake"));
FeatureClient client = Api.Instance.GetClient(name);
Assert.Equal(ProviderStatus.NotReady, provider.Status);
- _ = Api.Instance.SetProviderAsync(name, provider);
+ _ = Api.Instance.SetProviderAsync(name, provider, TestContext.Current.CancellationToken);
- var details = await client.GetStringDetailsAsync("some-flag", defaultStr);
+ var details = await client.GetStringDetailsAsync("some-flag", defaultStr, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(defaultStr, details.Value);
Assert.Equal(ErrorType.ProviderFatal, details.ErrorType);
Assert.Equal(Reason.Error, details.Reason);
@@ -275,16 +275,16 @@ public async Task Should_Resolve_BooleanValue()
var defaultValue = fixture.Create();
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveBooleanValueAsync(flagName, defaultValue, Arg.Any()).Returns(new ResolutionDetails(flagName, defaultValue));
+ featureProviderMock.ResolveBooleanValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultValue));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- Assert.Equal(defaultValue, await client.GetBooleanValueAsync(flagName, defaultValue));
+ Assert.Equal(defaultValue, await client.GetBooleanValueAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken));
- _ = featureProviderMock.Received(1).ResolveBooleanValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveBooleanValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -297,16 +297,16 @@ public async Task Should_Resolve_StringValue()
var defaultValue = fixture.Create();
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveStringValueAsync(flagName, defaultValue, Arg.Any()).Returns(new ResolutionDetails(flagName, defaultValue));
+ featureProviderMock.ResolveStringValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultValue));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- Assert.Equal(defaultValue, await client.GetStringValueAsync(flagName, defaultValue));
+ Assert.Equal(defaultValue, await client.GetStringValueAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken));
- _ = featureProviderMock.Received(1).ResolveStringValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveStringValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -319,16 +319,16 @@ public async Task Should_Resolve_IntegerValue()
var defaultValue = fixture.Create();
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveIntegerValueAsync(flagName, defaultValue, Arg.Any()).Returns(new ResolutionDetails(flagName, defaultValue));
+ featureProviderMock.ResolveIntegerValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultValue));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- Assert.Equal(defaultValue, await client.GetIntegerValueAsync(flagName, defaultValue));
+ Assert.Equal(defaultValue, await client.GetIntegerValueAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken));
- _ = featureProviderMock.Received(1).ResolveIntegerValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveIntegerValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -341,16 +341,16 @@ public async Task Should_Resolve_DoubleValue()
var defaultValue = fixture.Create();
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveDoubleValueAsync(flagName, defaultValue, Arg.Any()).Returns(new ResolutionDetails(flagName, defaultValue));
+ featureProviderMock.ResolveDoubleValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultValue));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- Assert.Equal(defaultValue, await client.GetDoubleValueAsync(flagName, defaultValue));
+ Assert.Equal(defaultValue, await client.GetDoubleValueAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken));
- _ = featureProviderMock.Received(1).ResolveDoubleValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveDoubleValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -363,16 +363,16 @@ public async Task Should_Resolve_StructureValue()
var defaultValue = fixture.Create();
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any()).Returns(new ResolutionDetails(flagName, defaultValue));
+ featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(new ResolutionDetails(flagName, defaultValue));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- Assert.Equal(defaultValue, await client.GetObjectValueAsync(flagName, defaultValue));
+ Assert.Equal(defaultValue, await client.GetObjectValueAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken));
- _ = featureProviderMock.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -386,18 +386,18 @@ public async Task When_Error_Is_Returned_From_Provider_Should_Return_Error()
const string testMessage = "Couldn't parse flag data.";
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any()).Returns(Task.FromResult(new ResolutionDetails(flagName, defaultValue, ErrorType.ParseError, "ERROR", null, testMessage)));
+ featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(Task.FromResult(new ResolutionDetails(flagName, defaultValue, ErrorType.ParseError, "ERROR", null, testMessage)));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- var response = await client.GetObjectDetailsAsync(flagName, defaultValue);
+ var response = await client.GetObjectDetailsAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.ParseError, response.ErrorType);
Assert.Equal(Reason.Error, response.Reason);
Assert.Equal(testMessage, response.ErrorMessage);
- _ = featureProviderMock.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -411,18 +411,18 @@ public async Task When_Exception_Occurs_During_Evaluation_Should_Return_Error()
const string testMessage = "Couldn't parse flag data.";
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any()).Throws(new FeatureProviderException(ErrorType.ParseError, testMessage));
+ featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Throws(new FeatureProviderException(ErrorType.ParseError, testMessage));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
- var response = await client.GetObjectDetailsAsync(flagName, defaultValue);
+ var response = await client.GetObjectDetailsAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.ParseError, response.ErrorType);
Assert.Equal(Reason.Error, response.Reason);
Assert.Equal(testMessage, response.ErrorMessage);
- _ = featureProviderMock.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any());
+ _ = featureProviderMock.Received(1).ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
}
[Fact]
@@ -436,23 +436,22 @@ public async Task When_Error_Is_Returned_From_Provider_Should_Not_Run_After_Hook
const string testMessage = "Couldn't parse flag data.";
var featureProviderMock = Substitute.For();
- featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any())
- .Returns(Task.FromResult(new ResolutionDetails(flagName, defaultValue, ErrorType.ParseError,
+ featureProviderMock.ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken).Returns(Task.FromResult(new ResolutionDetails(flagName, defaultValue, ErrorType.ParseError,
"ERROR", null, testMessage)));
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(featureProviderMock);
+ await Api.Instance.SetProviderAsync(featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
var testHook = new TestHook();
client.AddHooks(testHook);
- var response = await client.GetObjectDetailsAsync(flagName, defaultValue);
+ var response = await client.GetObjectDetailsAsync(flagName, defaultValue, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(ErrorType.ParseError, response.ErrorType);
Assert.Equal(Reason.Error, response.Reason);
Assert.Equal(testMessage, response.ErrorMessage);
_ = featureProviderMock.Received(1)
- .ResolveStructureValueAsync(flagName, defaultValue, Arg.Any());
+ .ResolveStructureValueAsync(flagName, defaultValue, Arg.Any(), TestContext.Current.CancellationToken);
Assert.Equal(1, testHook.BeforeCallCount);
Assert.Equal(0, testHook.AfterCallCount);
@@ -479,7 +478,7 @@ public async Task Cancellation_Token_Added_Is_Passed_To_Provider()
var token = args.ArgAt(3);
while (!token.IsCancellationRequested)
{
- await Task.Delay(10); // artificially delay until cancelled
+ await Task.Delay(10, TestContext.Current.CancellationToken); // artificially delay until cancelled
}
return new ResolutionDetails(flagName, defaultString, ErrorType.None, cancelledReason);
@@ -487,7 +486,7 @@ public async Task Cancellation_Token_Added_Is_Passed_To_Provider()
featureProviderMock.GetMetadata().Returns(new Metadata(fixture.Create()));
featureProviderMock.GetProviderHooks().Returns(ImmutableList.Empty);
- await Api.Instance.SetProviderAsync(domain, featureProviderMock);
+ await Api.Instance.SetProviderAsync(domain, featureProviderMock, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(domain, clientVersion);
var task = client.GetStringDetailsAsync(flagName, defaultString, EvaluationContext.Empty, null, cts.Token);
cts.Cancel(); // cancel before awaiting
@@ -540,7 +539,7 @@ public void ToFlagEvaluationDetails_Should_Convert_All_Properties()
public async Task TheClient_ImplementsATrackingFunction()
{
var provider = new TestProvider();
- await Api.Instance.SetProviderAsync(provider);
+ await Api.Instance.SetProviderAsync(provider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient();
const string trackingEventName = "trackingEventName";
@@ -581,7 +580,7 @@ public async Task TheClient_ImplementsATrackingFunction()
public async Task PassingAnEmptyStringAsTrackingEventName_ThrowsArgumentException()
{
var provider = new TestProvider();
- await Api.Instance.SetProviderAsync(provider);
+ await Api.Instance.SetProviderAsync(provider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient();
Assert.Throws(() => client.Track(""));
@@ -591,7 +590,7 @@ public async Task PassingAnEmptyStringAsTrackingEventName_ThrowsArgumentExceptio
public async Task PassingABlankStringAsTrackingEventName_ThrowsArgumentException()
{
var provider = new TestProvider();
- await Api.Instance.SetProviderAsync(provider);
+ await Api.Instance.SetProviderAsync(provider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient();
Assert.Throws(() => client.Track(" \n "));
@@ -604,7 +603,7 @@ public async Task PassingABlankStringAsTrackingEventName_ThrowsArgumentException
public async Task PassingBlankClientName_DoesNotThrowArgumentNullException(string? clientName)
{
var provider = new TestProvider();
- await Api.Instance.SetProviderAsync(provider);
+ await Api.Instance.SetProviderAsync(provider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient(clientName);
var ex = Record.Exception(() => client.AddHandler(ProviderEventTypes.ProviderReady, (args) => { }));
@@ -648,7 +647,7 @@ public async Task PassingBlankClientName_DoesNotThrowArgumentNullException(strin
public async Task TheClient_MergesTheEvaluationContextInTheCorrectOrder(string key, EvaluationContext? globalEvaluationContext, EvaluationContext? clientEvaluationContext, EvaluationContext? invocationEvaluationContext, string expectedResult)
{
var provider = new TestProvider();
- await Api.Instance.SetProviderAsync(provider);
+ await Api.Instance.SetProviderAsync(provider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient();
const string trackingEventName = "trackingEventName";
@@ -672,15 +671,15 @@ public async Task FinallyHook_IncludesEvaluationDetails()
var provider = new TestProvider();
var providerHook = Substitute.For();
provider.AddHook(providerHook);
- await Api.Instance.SetProviderAsync(provider);
+ await Api.Instance.SetProviderAsync(provider, TestContext.Current.CancellationToken);
var client = Api.Instance.GetClient();
const string flagName = "flagName";
// Act
- var evaluationDetails = await client.GetBooleanDetailsAsync(flagName, true);
+ var evaluationDetails = await client.GetBooleanDetailsAsync(flagName, true, cancellationToken: TestContext.Current.CancellationToken);
// Assert
- await providerHook.Received(1).FinallyAsync(Arg.Any>(), evaluationDetails);
+ await providerHook.Received(1).FinallyAsync(Arg.Any>(), evaluationDetails, cancellationToken: TestContext.Current.CancellationToken);
}
}
diff --git a/test/OpenFeature.Tests/OpenFeatureEventTests.cs b/test/OpenFeature.Tests/OpenFeatureEventTests.cs
index 45821899..b32eb9bc 100644
--- a/test/OpenFeature.Tests/OpenFeatureEventTests.cs
+++ b/test/OpenFeature.Tests/OpenFeatureEventTests.cs
@@ -69,11 +69,11 @@ public async Task API_Level_Event_Handlers_Should_Be_Registered()
Api.Instance.AddHandler(ProviderEventTypes.ProviderStale, eventHandler);
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
- await testProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged);
- await testProvider.SendEventAsync(ProviderEventTypes.ProviderError);
- await testProvider.SendEventAsync(ProviderEventTypes.ProviderStale);
+ await testProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged, TestContext.Current.CancellationToken);
+ await testProvider.SendEventAsync(ProviderEventTypes.ProviderError, TestContext.Current.CancellationToken);
+ await testProvider.SendEventAsync(ProviderEventTypes.ProviderStale, TestContext.Current.CancellationToken);
await Utils.AssertUntilAsync(_ => eventHandler
.Received()
@@ -116,7 +116,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_
var eventHandler = Substitute.For();
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
@@ -140,7 +140,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_
var eventHandler = Substitute.For();
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
@@ -164,7 +164,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Error_State_
var eventHandler = Substitute.For();
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
testProvider.Status = ProviderStatus.Error;
@@ -189,7 +189,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Stale_State_
var eventHandler = Substitute.For();
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
testProvider.Status = ProviderStatus.Stale;
@@ -217,14 +217,14 @@ public async Task API_Level_Event_Handlers_Should_Be_Exchangeable()
Api.Instance.AddHandler(ProviderEventTypes.ProviderConfigurationChanged, eventHandler);
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
- await testProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged);
+ await testProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged, TestContext.Current.CancellationToken);
var newTestProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(newTestProvider);
+ await Api.Instance.SetProviderAsync(newTestProvider, TestContext.Current.CancellationToken);
- await newTestProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged);
+ await newTestProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged, TestContext.Current.CancellationToken);
await Utils.AssertUntilAsync(
_ => eventHandler.Received(2).Invoke(Arg.Is(payload => payload.ProviderName == testProvider.GetMetadata().Name && payload.Type == ProviderEventTypes.ProviderReady))
@@ -246,13 +246,13 @@ public async Task API_Level_Event_Handlers_Should_Be_Removable()
Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
Thread.Sleep(1000);
Api.Instance.RemoveHandler(ProviderEventTypes.ProviderReady, eventHandler);
var newTestProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(newTestProvider);
+ await Api.Instance.SetProviderAsync(newTestProvider, TestContext.Current.CancellationToken);
eventHandler.Received(1).Invoke(Arg.Is(payload => payload.ProviderName == testProvider.GetMetadata().Name));
}
@@ -277,7 +277,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Executed_When_Other_Handler
Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
var testProvider = new TestProvider(fixture.Create());
- await Api.Instance.SetProviderAsync(testProvider);
+ await Api.Instance.SetProviderAsync(testProvider, TestContext.Current.CancellationToken);
await Utils.AssertUntilAsync(
_ => failingEventHandler.Received().Invoke(Arg.Is(payload => payload.ProviderName == testProvider.GetMetadata().Name))
@@ -302,7 +302,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Registered()
var myClient = Api.Instance.GetClient(domain, clientVersion);
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(myClient.GetMetadata().Name!, testProvider);
+ await Api.Instance.SetProviderAsync(myClient.GetMetadata().Name!, testProvider, TestContext.Current.CancellationToken);
myClient.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
@@ -333,7 +333,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Executed_When_Other_Hand
myClient.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
var testProvider = new TestProvider();
- await Api.Instance.SetProviderAsync(myClient.GetMetadata().Name!, testProvider);
+ await Api.Instance.SetProviderAsync(myClient.GetMetadata().Name!, testProvider, TestContext.Current.CancellationToken);
await Utils.AssertUntilAsync(
_ => failingEventHandler.Received().Invoke(Arg.Is(payload => payload.ProviderName == testProvider.GetMetadata().Name))
@@ -362,9 +362,9 @@ public async Task Client_Level_Event_Handlers_Should_Be_Registered_To_Default_Pr
var clientProvider = new TestProvider(fixture.Create());
// set the default provider on API level, but not specifically to the client
- await Api.Instance.SetProviderAsync(apiProvider);
+ await Api.Instance.SetProviderAsync(apiProvider, TestContext.Current.CancellationToken);
// set the other provider specifically for the client
- await Api.Instance.SetProviderAsync(myClientWithBoundProvider.GetMetadata().Name!, clientProvider);
+ await Api.Instance.SetProviderAsync(myClientWithBoundProvider.GetMetadata().Name!, clientProvider, TestContext.Current.CancellationToken);
myClientWithNoBoundProvider.AddHandler(ProviderEventTypes.ProviderReady, eventHandler);
myClientWithBoundProvider.AddHandler(ProviderEventTypes.ProviderReady, clientEventHandler);
@@ -394,11 +394,11 @@ public async Task Client_Level_Event_Handlers_Should_Be_Receive_Events_From_Name
var clientProvider = new TestProvider(fixture.Create());
// set the default provider
- await Api.Instance.SetProviderAsync(defaultProvider);
+ await Api.Instance.SetProviderAsync(defaultProvider, TestContext.Current.CancellationToken);
client.AddHandler(ProviderEventTypes.ProviderConfigurationChanged, clientEventHandler);
- await defaultProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged);
+ await defaultProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged, TestContext.Current.CancellationToken);
// verify that the client received the event from the default provider as there is no named provider registered yet
await Utils.AssertUntilAsync(
@@ -407,11 +407,11 @@ await Utils.AssertUntilAsync(
);
// set the other provider specifically for the client
- await Api.Instance.SetProviderAsync(client.GetMetadata().Name!, clientProvider);
+ await Api.Instance.SetProviderAsync(client.GetMetadata().Name!, clientProvider, TestContext.Current.CancellationToken);
// now, send another event for the default handler
- await defaultProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged);
- await clientProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged);
+ await defaultProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged, TestContext.Current.CancellationToken);
+ await clientProvider.SendEventAsync(ProviderEventTypes.ProviderConfigurationChanged, TestContext.Current.CancellationToken);
// now the client should have received only the event from the named provider
await Utils.AssertUntilAsync(
@@ -439,7 +439,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Informed_About_Ready_Sta
var myClient = Api.Instance.GetClient(fixture.Create(), fixture.Create