diff --git a/Directory.Packages.props b/Directory.Packages.props index e4d708a4..0714935e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -12,20 +12,20 @@ - + - - + + - + - - + + diff --git a/test/OpenFeature.Tests/OpenFeatureTests.cs b/test/OpenFeature.Tests/OpenFeatureTests.cs index d43bf045..02c41917 100644 --- a/test/OpenFeature.Tests/OpenFeatureTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureTests.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -9,6 +10,7 @@ namespace OpenFeature.Tests { + [SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task")] public class OpenFeatureTests : ClearOpenFeatureInstanceFixture { [Fact] @@ -28,14 +30,14 @@ public async Task OpenFeature_Should_Initialize_Provider() var providerMockDefault = Substitute.For(); providerMockDefault.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync(providerMockDefault).ConfigureAwait(false); - await providerMockDefault.Received(1).Initialize(Api.Instance.GetContext()).ConfigureAwait(false); + await Api.Instance.SetProviderAsync(providerMockDefault); + await providerMockDefault.Received(1).Initialize(Api.Instance.GetContext()); var providerMockNamed = Substitute.For(); providerMockNamed.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync("the-name", providerMockNamed).ConfigureAwait(false); - await providerMockNamed.Received(1).Initialize(Api.Instance.GetContext()).ConfigureAwait(false); + await Api.Instance.SetProviderAsync("the-name", providerMockNamed); + await providerMockNamed.Received(1).Initialize(Api.Instance.GetContext()); } [Fact] @@ -46,28 +48,28 @@ public async Task OpenFeature_Should_Shutdown_Unused_Provider() var providerA = Substitute.For(); providerA.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync(providerA).ConfigureAwait(false); - await providerA.Received(1).Initialize(Api.Instance.GetContext()).ConfigureAwait(false); + await Api.Instance.SetProviderAsync(providerA); + await providerA.Received(1).Initialize(Api.Instance.GetContext()); var providerB = Substitute.For(); providerB.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync(providerB).ConfigureAwait(false); - await providerB.Received(1).Initialize(Api.Instance.GetContext()).ConfigureAwait(false); - await providerA.Received(1).Shutdown().ConfigureAwait(false); + await Api.Instance.SetProviderAsync(providerB); + await providerB.Received(1).Initialize(Api.Instance.GetContext()); + await providerA.Received(1).Shutdown(); var providerC = Substitute.For(); providerC.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync("named", providerC).ConfigureAwait(false); - await providerC.Received(1).Initialize(Api.Instance.GetContext()).ConfigureAwait(false); + await Api.Instance.SetProviderAsync("named", providerC); + await providerC.Received(1).Initialize(Api.Instance.GetContext()); var providerD = Substitute.For(); providerD.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync("named", providerD).ConfigureAwait(false); - await providerD.Received(1).Initialize(Api.Instance.GetContext()).ConfigureAwait(false); - await providerC.Received(1).Shutdown().ConfigureAwait(false); + await Api.Instance.SetProviderAsync("named", providerD); + await providerD.Received(1).Initialize(Api.Instance.GetContext()); + await providerC.Received(1).Shutdown(); } [Fact] @@ -80,13 +82,13 @@ public async Task OpenFeature_Should_Support_Shutdown() var providerB = Substitute.For(); providerB.GetStatus().Returns(ProviderStatus.NotReady); - await Api.Instance.SetProviderAsync(providerA).ConfigureAwait(false); - await Api.Instance.SetProviderAsync("named", providerB).ConfigureAwait(false); + await Api.Instance.SetProviderAsync(providerA); + await Api.Instance.SetProviderAsync("named", providerB); - await Api.Instance.Shutdown().ConfigureAwait(false); + await Api.Instance.Shutdown(); - await providerA.Received(1).Shutdown().ConfigureAwait(false); - await providerB.Received(1).Shutdown().ConfigureAwait(false); + await providerA.Received(1).Shutdown(); + await providerB.Received(1).Shutdown(); } [Fact] @@ -95,8 +97,8 @@ public async Task OpenFeature_Should_Not_Change_Named_Providers_When_Setting_Def { var openFeature = Api.Instance; - await openFeature.SetProviderAsync(new NoOpFeatureProvider()).ConfigureAwait(false); - await openFeature.SetProviderAsync(TestProvider.DefaultName, new TestProvider()).ConfigureAwait(false); + await openFeature.SetProviderAsync(new NoOpFeatureProvider()); + await openFeature.SetProviderAsync(TestProvider.DefaultName, new TestProvider()); var defaultClient = openFeature.GetProviderMetadata(); var namedClient = openFeature.GetProviderMetadata(TestProvider.DefaultName); @@ -111,7 +113,7 @@ public async Task OpenFeature_Should_Set_Default_Provide_When_No_Name_Provided() { var openFeature = Api.Instance; - await openFeature.SetProviderAsync(new TestProvider()).ConfigureAwait(false); + await openFeature.SetProviderAsync(new TestProvider()); var defaultClient = openFeature.GetProviderMetadata(); @@ -178,9 +180,9 @@ public void OpenFeature_Should_Add_Hooks() [Fact] [Specification("1.1.5", "The API MUST provide a function for retrieving the metadata field of the configured `provider`.")] - public void OpenFeature_Should_Get_Metadata() + public async Task OpenFeature_Should_Get_Metadata() { - Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait(); + await Api.Instance.SetProviderAsync(new NoOpFeatureProvider()); var openFeature = Api.Instance; var metadata = openFeature.GetProviderMetadata(); @@ -239,8 +241,8 @@ public async Task OpenFeature_Should_Allow_Multiple_Client_Mapping() client1.GetMetadata().Name.Should().Be("client1"); client2.GetMetadata().Name.Should().Be("client2"); - client1.GetBooleanValue("test", false).Result.Should().BeTrue(); - client2.GetBooleanValue("test", false).Result.Should().BeFalse(); + (await client1.GetBooleanValue("test", false)).Should().BeTrue(); + (await client2.GetBooleanValue("test", false)).Should().BeFalse(); } } } diff --git a/test/OpenFeature.Tests/StructureTests.cs b/test/OpenFeature.Tests/StructureTests.cs index c781b83b..310303ed 100644 --- a/test/OpenFeature.Tests/StructureTests.cs +++ b/test/OpenFeature.Tests/StructureTests.cs @@ -89,7 +89,7 @@ public void Values_Should_Return_Values() var structure = Structure.Builder() .Set(KEY, VAL).Build(); - Assert.Equal(1, structure.Values.Count); + Assert.Single(structure.Values); } [Fact] @@ -100,7 +100,7 @@ public void Keys_Should_Return_Keys() var structure = Structure.Builder() .Set(KEY, VAL).Build(); - Assert.Equal(1, structure.Keys.Count); + Assert.Single(structure.Keys); Assert.Equal(0, structure.Keys.IndexOf(KEY)); } diff --git a/test/OpenFeature.Tests/TestUtilsTest.cs b/test/OpenFeature.Tests/TestUtilsTest.cs index 141194b3..1d0882b0 100644 --- a/test/OpenFeature.Tests/TestUtilsTest.cs +++ b/test/OpenFeature.Tests/TestUtilsTest.cs @@ -1,23 +1,22 @@ using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using OpenFeature.Model; +using System.Diagnostics.CodeAnalysis; using Xunit; namespace OpenFeature.Tests { + [SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task")] public class TestUtilsTest { [Fact] public async void Should_Fail_If_Assertion_Fails() { - await Assert.ThrowsAnyAsync(() => Utils.AssertUntilAsync(_ => Assert.True(1.Equals(2)), 100, 10)).ConfigureAwait(false); + await Assert.ThrowsAnyAsync(() => Utils.AssertUntilAsync(_ => Assert.True(1.Equals(2)), 100, 10)); } [Fact] public async void Should_Pass_If_Assertion_Fails() { - await Utils.AssertUntilAsync(_ => Assert.True(1.Equals(1))).ConfigureAwait(false); + await Utils.AssertUntilAsync(_ => Assert.True(1.Equals(1))); } } } diff --git a/test/OpenFeature.Tests/ValueTests.cs b/test/OpenFeature.Tests/ValueTests.cs index 4540618b..031fea9a 100644 --- a/test/OpenFeature.Tests/ValueTests.cs +++ b/test/OpenFeature.Tests/ValueTests.cs @@ -53,7 +53,7 @@ public void Int_Object_Arg_Should_Contain_Object() } catch (Exception) { - Assert.True(false, "Expected no exception."); + Assert.Fail("Expected no exception."); } }