Skip to content

Commit

Permalink
test: Fix up xunit warnings
Browse files Browse the repository at this point in the history
Don't need to use ConfigureAwait in unit tests

Signed-off-by: Benjamin Evenson <[email protected]>
  • Loading branch information
benjiro committed Feb 18, 2024
1 parent fd0a541 commit f43e444
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions test/OpenFeature.Tests/Providers/Memory/InMemoryProviderTests.cs
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit f43e444

Please sign in to comment.