Skip to content

Commit

Permalink
ci: Add integration tests to the test action (#383)
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
  • Loading branch information
askpt authored Feb 21, 2025
1 parent accf571 commit 9185b76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 13 additions & 4 deletions test/OpenFeature.IntegrationTests/FeatureFlagIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FeatureFlagIntegrationTest
public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string userId, bool expectedResult, ServiceLifetime serviceLifetime)
{
// Arrange
using var server = await CreateServerAsync(services =>
using var server = await CreateServerAsync(serviceLifetime, services =>
{
switch (serviceLifetime)
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string us
Assert.Equal(expectedResult, responseContent.FeatureValue);
}

private static async Task<TestServer> CreateServerAsync(Action<IServiceCollection>? configureServices = null)
private static async Task<TestServer> CreateServerAsync(ServiceLifetime serviceLifetime, Action<IServiceCollection>? configureServices = null)
{
var builder = WebApplication.CreateBuilder();
builder.WebHost.UseTestServer();
Expand All @@ -82,8 +82,17 @@ private static async Task<TestServer> CreateServerAsync(Action<IServiceCollectio
});
cfg.AddInMemoryProvider(provider =>
{
var flagService = provider.GetRequiredService<IFeatureFlagConfigurationService>();
return flagService.GetFlags();
if (serviceLifetime == ServiceLifetime.Scoped)
{
using var scoped = provider.CreateScope();
var flagService = scoped.ServiceProvider.GetRequiredService<IFeatureFlagConfigurationService>();
return flagService.GetFlags();
}
else
{
var flagService = provider.GetRequiredService<IFeatureFlagConfigurationService>();
return flagService.GetFlags();
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NSubstitute" />
</ItemGroup>

Expand Down

0 comments on commit 9185b76

Please sign in to comment.