Skip to content

Commit

Permalink
Merge branch 'main' into beeme1mr-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
beeme1mr authored Feb 12, 2025
2 parents e1a8c1c + 3bdc79b commit fb0c8e1
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 208 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3
uses: github/codeql-action/init@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3
uses: github/codeql-action/autobuild@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -69,4 +69,4 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3
uses: github/codeql-action/analyze@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dotnet test test/OpenFeature.Tests/
To be able to run the e2e tests, first we need to initialize the submodule and copy the test files:

```bash
git submodule update --init --recursive && cp test-harness/features/evaluation.feature test/OpenFeature.E2ETests/Features/
git submodule update --init --recursive && cp spec/specification/assets/gherkin/evaluation.feature test/OpenFeature.E2ETests/Features/
```

Now you can run the tests using:
Expand Down
23 changes: 10 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
</PropertyGroup>

<ItemGroup Label="src">
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.1" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.1" />
<PackageVersion Include="System.Threading.Channels" Version="9.0.1" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.2" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.2" />
<PackageVersion Include="System.Threading.Channels" Version="9.0.2" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

Expand All @@ -21,14 +21,11 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="FluentAssertions" Version="7.1.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="9.1.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="SpecFlow" Version="3.9.74" />
<PackageVersion Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
<PackageVersion Include="SpecFlow.xUnit" Version="3.9.74" />
<PackageVersion Include="Reqnroll.xUnit" Version="2.3.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -44,7 +43,7 @@ public async Task EnsureInitializedAsync_ShouldLogAndSetProvider_WhenProviderExi
await _systemUnderTest.EnsureInitializedAsync().ConfigureAwait(true);

// Assert
Api.Instance.GetProvider().Should().BeSameAs(featureProvider);
Assert.Equal(featureProvider, Api.Instance.GetProvider());
}

[Fact]
Expand All @@ -58,7 +57,7 @@ public async Task EnsureInitializedAsync_ShouldThrowException_WhenProviderDoesNo

// Assert
var exception = await Assert.ThrowsAsync<InvalidOperationException>(act).ConfigureAwait(true);
exception.Should().NotBeNull();
exception.Message.Should().NotBeNullOrWhiteSpace();
Assert.NotNull(exception);
Assert.False(string.IsNullOrWhiteSpace(exception.Message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenFeature.Model;
Expand Down Expand Up @@ -28,12 +27,11 @@ public void AddContext_Delegate_ShouldAddServiceToCollection(bool useServiceProv
_systemUnderTest.AddContext((_, _) => { });

// Assert
featureBuilder.Should().BeSameAs(_systemUnderTest, "The method should return the same builder instance.");
_systemUnderTest.IsContextConfigured.Should().BeTrue("The context should be configured.");
_services.Should().ContainSingle(serviceDescriptor =>
Assert.Equal(_systemUnderTest, featureBuilder);
Assert.True(_systemUnderTest.IsContextConfigured, "The context should be configured.");
Assert.Single(_services, serviceDescriptor =>
serviceDescriptor.ServiceType == typeof(EvaluationContext) &&
serviceDescriptor.Lifetime == ServiceLifetime.Transient,
"A transient service of type EvaluationContext should be added.");
serviceDescriptor.Lifetime == ServiceLifetime.Transient);
}

[Theory]
Expand All @@ -54,9 +52,9 @@ public void AddContext_Delegate_ShouldCorrectlyHandles(bool useServiceProviderDe
var context = serviceProvider.GetService<EvaluationContext>();

// Assert
_systemUnderTest.IsContextConfigured.Should().BeTrue("The context should be configured.");
context.Should().NotBeNull("The EvaluationContext should be resolvable.");
delegateCalled.Should().BeTrue("The delegate should be invoked.");
Assert.True(_systemUnderTest.IsContextConfigured, "The context should be configured.");
Assert.NotNull(context);
Assert.True(delegateCalled, "The delegate should be invoked.");
}

#if NET8_0_OR_GREATER
Expand All @@ -80,15 +78,14 @@ public void AddProvider_ShouldAddProviderToCollection(int providerRegistrationTy
};

// Assert
_systemUnderTest.IsContextConfigured.Should().BeFalse("The context should not be configured.");
_systemUnderTest.HasDefaultProvider.Should().Be(expectsDefaultProvider, "The default provider flag should be set correctly.");
_systemUnderTest.IsPolicyConfigured.Should().BeFalse("The policy should not be configured.");
_systemUnderTest.DomainBoundProviderRegistrationCount.Should().Be(expectsDomainBoundProvider, "The domain-bound provider count should be correct.");
featureBuilder.Should().BeSameAs(_systemUnderTest, "The method should return the same builder instance.");
_services.Should().ContainSingle(serviceDescriptor =>
Assert.False(_systemUnderTest.IsContextConfigured, "The context should not be configured.");
Assert.Equal(expectsDefaultProvider, _systemUnderTest.HasDefaultProvider);
Assert.False(_systemUnderTest.IsPolicyConfigured, "The policy should not be configured.");
Assert.Equal(expectsDomainBoundProvider, _systemUnderTest.DomainBoundProviderRegistrationCount);
Assert.Equal(_systemUnderTest, featureBuilder);
Assert.Single(_services, serviceDescriptor =>
serviceDescriptor.ServiceType == typeof(FeatureProvider) &&
serviceDescriptor.Lifetime == ServiceLifetime.Transient,
"A singleton service of type FeatureProvider should be added.");
serviceDescriptor.Lifetime == ServiceLifetime.Transient);
}

class TestOptions : OpenFeatureOptions { }
Expand Down Expand Up @@ -124,8 +121,8 @@ public void AddProvider_ShouldResolveCorrectProvider(int providerRegistrationTyp
};

// Assert
provider.Should().NotBeNull("The FeatureProvider should be resolvable.");
provider.Should().BeOfType<NoOpFeatureProvider>("The resolved provider should be of type DefaultFeatureProvider.");
Assert.NotNull(provider);
Assert.IsType<NoOpFeatureProvider>(provider);
}

[Theory]
Expand Down Expand Up @@ -172,11 +169,11 @@ public void AddProvider_VerifiesDefaultAndDomainBoundProvidersBasedOnConfigurati
};

// Assert
_systemUnderTest.IsContextConfigured.Should().BeFalse("The context should not be configured.");
_systemUnderTest.HasDefaultProvider.Should().Be(expectsDefaultProvider, "The default provider flag should be set correctly.");
_systemUnderTest.IsPolicyConfigured.Should().BeFalse("The policy should not be configured.");
_systemUnderTest.DomainBoundProviderRegistrationCount.Should().Be(expectsDomainBoundProvider, "The domain-bound provider count should be correct.");
featureBuilder.Should().BeSameAs(_systemUnderTest, "The method should return the same builder instance.");
Assert.False(_systemUnderTest.IsContextConfigured, "The context should not be configured.");
Assert.Equal(expectsDefaultProvider, _systemUnderTest.HasDefaultProvider);
Assert.False(_systemUnderTest.IsPolicyConfigured, "The policy should not be configured.");
Assert.Equal(expectsDomainBoundProvider, _systemUnderTest.DomainBoundProviderRegistrationCount);
Assert.Equal(_systemUnderTest, featureBuilder);
}

[Theory]
Expand Down Expand Up @@ -240,8 +237,8 @@ public void AddProvider_ConfiguresPolicyNameAcrossMultipleProviderSetups(int pro
serviceProvider.GetRequiredKeyedService<FeatureProvider>(name);

// Assert
featureBuilder.IsPolicyConfigured.Should().BeTrue("The policy should be configured.");
provider.Should().NotBeNull("The FeatureProvider should be resolvable.");
provider.Should().BeOfType<NoOpFeatureProvider>("The resolved provider should be of type DefaultFeatureProvider.");
Assert.True(featureBuilder.IsPolicyConfigured, "The policy should be configured.");
Assert.NotNull(provider);
Assert.IsType<NoOpFeatureProvider>(provider);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Xunit;
Expand All @@ -22,9 +21,9 @@ public void AddOpenFeature_ShouldRegisterApiInstanceAndLifecycleManagerAsSinglet
// Act
_systemUnderTest.AddOpenFeature(_configureAction);

_systemUnderTest.Should().ContainSingle(s => s.ServiceType == typeof(Api) && s.Lifetime == ServiceLifetime.Singleton);
_systemUnderTest.Should().ContainSingle(s => s.ServiceType == typeof(IFeatureLifecycleManager) && s.Lifetime == ServiceLifetime.Singleton);
_systemUnderTest.Should().ContainSingle(s => s.ServiceType == typeof(IFeatureClient) && s.Lifetime == ServiceLifetime.Scoped);
Assert.Single(_systemUnderTest, s => s.ServiceType == typeof(Api) && s.Lifetime == ServiceLifetime.Singleton);
Assert.Single(_systemUnderTest, s => s.ServiceType == typeof(IFeatureLifecycleManager) && s.Lifetime == ServiceLifetime.Singleton);
Assert.Single(_systemUnderTest, s => s.ServiceType == typeof(IFeatureClient) && s.Lifetime == ServiceLifetime.Scoped);
}

[Fact]
Expand Down
5 changes: 1 addition & 4 deletions test/OpenFeature.E2ETests/OpenFeature.E2ETests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SpecFlow" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" />
<PackageReference Include="SpecFlow.xUnit" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Reqnroll.xUnit" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using OpenFeature.Extension;
using OpenFeature.Model;
using OpenFeature.Providers.Memory;
using TechTalk.SpecFlow;
using Reqnroll;
using Xunit;

namespace OpenFeature.E2ETests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Net.Http.Json;
using System.Text.Json;
using FluentAssertions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
Expand Down Expand Up @@ -54,10 +53,10 @@ public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string us
var responseContent = await response.Content.ReadFromJsonAsync<FeatureFlagResponse<bool>>().ConfigureAwait(true); ;

// Assert
response.IsSuccessStatusCode.Should().BeTrue("Expected HTTP status code 200 OK.");
responseContent.Should().NotBeNull("Expected response content to be non-null.");
responseContent!.FeatureName.Should().Be(FeatureA, "Expected feature name to be 'feature-a'.");
responseContent.FeatureValue.Should().Be(expectedResult, "Expected feature value to match the expected result.");
Assert.True(response.IsSuccessStatusCode, "Expected HTTP status code 200 OK.");
Assert.NotNull(responseContent);
Assert.Equal(FeatureA, responseContent!.FeatureName);
Assert.Equal(expectedResult, responseContent.FeatureValue);
}

private static async Task<TestServer> CreateServerAsync(Action<IServiceCollection>? configureServices = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="NSubstitute" />
</ItemGroup>

Expand Down
11 changes: 6 additions & 5 deletions test/OpenFeature.Tests/FeatureProviderExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using FluentAssertions;
using OpenFeature.Constant;
using OpenFeature.Error;
using OpenFeature.Extension;
Expand All @@ -18,7 +17,8 @@ public class FeatureProviderExceptionTests
public void FeatureProviderException_Should_Resolve_Description(ErrorType errorType, string errorDescription)
{
var ex = new FeatureProviderException(errorType);
ex.ErrorType.GetDescription().Should().Be(errorDescription);

Assert.Equal(errorDescription, ex.ErrorType.GetDescription());
}

[Theory]
Expand All @@ -27,9 +27,10 @@ public void FeatureProviderException_Should_Resolve_Description(ErrorType errorT
public void FeatureProviderException_Should_Allow_Custom_ErrorCode_Messages(ErrorType errorCode, string message)
{
var ex = new FeatureProviderException(errorCode, message, new ArgumentOutOfRangeException("flag"));
ex.ErrorType.Should().Be(errorCode);
ex.Message.Should().Be(message);
ex.InnerException.Should().BeOfType<ArgumentOutOfRangeException>();

Assert.Equal(errorCode, ex.ErrorType);
Assert.Equal(message, ex.Message);
Assert.IsType<ArgumentOutOfRangeException>(ex.InnerException);
}

private enum TestEnum
Expand Down
Loading

0 comments on commit fb0c8e1

Please sign in to comment.