-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't need to use ConfigureAwait in unit tests Signed-off-by: Benjamin Evenson <[email protected]>
- Loading branch information
Showing
1 changed file
with
19 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Diagnostics.CodeAnalysis; | ||
using OpenFeature.Constant; | ||
using OpenFeature.Error; | ||
using OpenFeature.Model; | ||
using OpenFeature.Providers.Memory; | ||
using Xunit; | ||
|
||
namespace OpenFeature.Tests | ||
namespace OpenFeature.Tests.Providers.Memory | ||
{ | ||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task")] | ||
public class InMemoryProviderTests | ||
{ | ||
private FeatureProvider commonProvider; | ||
|
@@ -112,7 +111,7 @@ public InMemoryProviderTests() | |
[Fact] | ||
public async void GetBoolean_ShouldEvaluateWithReasonAndVariant() | ||
{ | ||
ResolutionDetails<bool> details = await this.commonProvider.ResolveBooleanValue("boolean-flag", false, EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<bool> details = await this.commonProvider.ResolveBooleanValue("boolean-flag", false, EvaluationContext.Empty); | ||
Assert.True(details.Value); | ||
Assert.Equal(Reason.Static, details.Reason); | ||
Assert.Equal("on", details.Variant); | ||
|
@@ -121,7 +120,7 @@ public async void GetBoolean_ShouldEvaluateWithReasonAndVariant() | |
[Fact] | ||
public async void GetString_ShouldEvaluateWithReasonAndVariant() | ||
{ | ||
ResolutionDetails<string> details = await this.commonProvider.ResolveStringValue("string-flag", "nope", EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<string> details = await this.commonProvider.ResolveStringValue("string-flag", "nope", EvaluationContext.Empty); | ||
Assert.Equal("hi", details.Value); | ||
Assert.Equal(Reason.Static, details.Reason); | ||
Assert.Equal("greeting", details.Variant); | ||
|
@@ -130,7 +129,7 @@ public async void GetString_ShouldEvaluateWithReasonAndVariant() | |
[Fact] | ||
public async void GetInt_ShouldEvaluateWithReasonAndVariant() | ||
{ | ||
ResolutionDetails<int> details = await this.commonProvider.ResolveIntegerValue("integer-flag", 13, EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<int> details = await this.commonProvider.ResolveIntegerValue("integer-flag", 13, EvaluationContext.Empty); | ||
Assert.Equal(10, details.Value); | ||
Assert.Equal(Reason.Static, details.Reason); | ||
Assert.Equal("ten", details.Variant); | ||
|
@@ -139,7 +138,7 @@ public async void GetInt_ShouldEvaluateWithReasonAndVariant() | |
[Fact] | ||
public async void GetDouble_ShouldEvaluateWithReasonAndVariant() | ||
{ | ||
ResolutionDetails<double> details = await this.commonProvider.ResolveDoubleValue("float-flag", 13, EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<double> details = await this.commonProvider.ResolveDoubleValue("float-flag", 13, EvaluationContext.Empty); | ||
Assert.Equal(0.5, details.Value); | ||
Assert.Equal(Reason.Static, details.Reason); | ||
Assert.Equal("half", details.Variant); | ||
|
@@ -148,7 +147,7 @@ public async void GetDouble_ShouldEvaluateWithReasonAndVariant() | |
[Fact] | ||
public async void GetStruct_ShouldEvaluateWithReasonAndVariant() | ||
{ | ||
ResolutionDetails<Value> details = await this.commonProvider.ResolveStructureValue("object-flag", new Value(), EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<Value> details = await this.commonProvider.ResolveStructureValue("object-flag", new Value(), EvaluationContext.Empty); | ||
Assert.Equal(true, details.Value.AsStructure["showImages"].AsBoolean); | ||
Assert.Equal("Check out these pics!", details.Value.AsStructure["title"].AsString); | ||
Assert.Equal(100, details.Value.AsStructure["imagesPerPage"].AsInteger); | ||
|
@@ -160,7 +159,7 @@ public async void GetStruct_ShouldEvaluateWithReasonAndVariant() | |
public async void GetString_ContextSensitive_ShouldEvaluateWithReasonAndVariant() | ||
{ | ||
EvaluationContext context = EvaluationContext.Builder().Set("email", "[email protected]").Build(); | ||
ResolutionDetails<string> details = await this.commonProvider.ResolveStringValue("context-aware", "nope", context).ConfigureAwait(false); | ||
ResolutionDetails<string> details = await this.commonProvider.ResolveStringValue("context-aware", "nope", context); | ||
Assert.Equal("INTERNAL", details.Value); | ||
Assert.Equal(Reason.TargetingMatch, details.Reason); | ||
Assert.Equal("internal", details.Variant); | ||
|
@@ -170,32 +169,32 @@ public async void GetString_ContextSensitive_ShouldEvaluateWithReasonAndVariant( | |
public async void EmptyFlags_ShouldWork() | ||
{ | ||
var provider = new InMemoryProvider(); | ||
await provider.UpdateFlags().ConfigureAwait(false); | ||
await provider.UpdateFlags(); | ||
Assert.Equal("InMemory", provider.GetMetadata().Name); | ||
} | ||
|
||
[Fact] | ||
public async void MissingFlag_ShouldThrow() | ||
{ | ||
await Assert.ThrowsAsync<FlagNotFoundException>(() => commonProvider.ResolveBooleanValue("missing-flag", false, EvaluationContext.Empty)).ConfigureAwait(false); | ||
await Assert.ThrowsAsync<FlagNotFoundException>(() => this.commonProvider.ResolveBooleanValue("missing-flag", false, EvaluationContext.Empty)); | ||
} | ||
|
||
[Fact] | ||
public async void MismatchedFlag_ShouldThrow() | ||
{ | ||
await Assert.ThrowsAsync<TypeMismatchException>(() => commonProvider.ResolveStringValue("boolean-flag", "nope", EvaluationContext.Empty)).ConfigureAwait(false); | ||
await Assert.ThrowsAsync<TypeMismatchException>(() => this.commonProvider.ResolveStringValue("boolean-flag", "nope", EvaluationContext.Empty)); | ||
} | ||
|
||
[Fact] | ||
public async void MissingDefaultVariant_ShouldThrow() | ||
{ | ||
await Assert.ThrowsAsync<GeneralException>(() => commonProvider.ResolveBooleanValue("invalid-flag", false, EvaluationContext.Empty)).ConfigureAwait(false); | ||
await Assert.ThrowsAsync<GeneralException>(() => this.commonProvider.ResolveBooleanValue("invalid-flag", false, EvaluationContext.Empty)); | ||
} | ||
|
||
[Fact] | ||
public async void MissingEvaluatedVariant_ShouldThrow() | ||
{ | ||
await Assert.ThrowsAsync<GeneralException>(() => commonProvider.ResolveBooleanValue("invalid-evaluator-flag", false, EvaluationContext.Empty)).ConfigureAwait(false); | ||
await Assert.ThrowsAsync<GeneralException>(() => this.commonProvider.ResolveBooleanValue("invalid-evaluator-flag", false, EvaluationContext.Empty)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -212,7 +211,7 @@ public async void PutConfiguration_shouldUpdateConfigAndRunHandlers() | |
) | ||
}}); | ||
|
||
ResolutionDetails<bool> details = await provider.ResolveBooleanValue("old-flag", false, EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<bool> details = await provider.ResolveBooleanValue("old-flag", false, EvaluationContext.Empty); | ||
Assert.True(details.Value); | ||
|
||
// update flags | ||
|
@@ -225,15 +224,15 @@ await provider.UpdateFlags(new Dictionary<string, Flag>(){ | |
}, | ||
defaultVariant: "greeting" | ||
) | ||
}}).ConfigureAwait(false); | ||
}}); | ||
|
||
var res = await provider.GetEventChannel().Reader.ReadAsync().ConfigureAwait(false) as ProviderEventPayload; | ||
var res = await provider.GetEventChannel().Reader.ReadAsync() as ProviderEventPayload; | ||
Assert.Equal(ProviderEventTypes.ProviderConfigurationChanged, res.Type); | ||
|
||
await Assert.ThrowsAsync<FlagNotFoundException>(() => provider.ResolveBooleanValue("old-flag", false, EvaluationContext.Empty)).ConfigureAwait(false); | ||
await Assert.ThrowsAsync<FlagNotFoundException>(() => provider.ResolveBooleanValue("old-flag", false, EvaluationContext.Empty)); | ||
|
||
// new flag should be present, old gone (defaults), handler run. | ||
ResolutionDetails<string> detailsAfter = await provider.ResolveStringValue("new-flag", "nope", EvaluationContext.Empty).ConfigureAwait(false); | ||
ResolutionDetails<string> detailsAfter = await provider.ResolveStringValue("new-flag", "nope", EvaluationContext.Empty); | ||
Assert.True(details.Value); | ||
Assert.Equal("hi", detailsAfter.Value); | ||
} | ||
|