Skip to content

Commit 9185b76

Browse files
authored
ci: Add integration tests to the test action (#383)
Signed-off-by: André Silva <[email protected]>
1 parent accf571 commit 9185b76

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

test/OpenFeature.IntegrationTests/FeatureFlagIntegrationTest.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class FeatureFlagIntegrationTest
2727
public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string userId, bool expectedResult, ServiceLifetime serviceLifetime)
2828
{
2929
// Arrange
30-
using var server = await CreateServerAsync(services =>
30+
using var server = await CreateServerAsync(serviceLifetime, services =>
3131
{
3232
switch (serviceLifetime)
3333
{
@@ -59,7 +59,7 @@ public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string us
5959
Assert.Equal(expectedResult, responseContent.FeatureValue);
6060
}
6161

62-
private static async Task<TestServer> CreateServerAsync(Action<IServiceCollection>? configureServices = null)
62+
private static async Task<TestServer> CreateServerAsync(ServiceLifetime serviceLifetime, Action<IServiceCollection>? configureServices = null)
6363
{
6464
var builder = WebApplication.CreateBuilder();
6565
builder.WebHost.UseTestServer();
@@ -82,8 +82,17 @@ private static async Task<TestServer> CreateServerAsync(Action<IServiceCollectio
8282
});
8383
cfg.AddInMemoryProvider(provider =>
8484
{
85-
var flagService = provider.GetRequiredService<IFeatureFlagConfigurationService>();
86-
return flagService.GetFlags();
85+
if (serviceLifetime == ServiceLifetime.Scoped)
86+
{
87+
using var scoped = provider.CreateScope();
88+
var flagService = scoped.ServiceProvider.GetRequiredService<IFeatureFlagConfigurationService>();
89+
return flagService.GetFlags();
90+
}
91+
else
92+
{
93+
var flagService = provider.GetRequiredService<IFeatureFlagConfigurationService>();
94+
return flagService.GetFlags();
95+
}
8796
});
8897
});
8998

test/OpenFeature.IntegrationTests/OpenFeature.IntegrationTests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1515
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
1616
<PackageReference Include="xunit" />
17-
<PackageReference Include="xunit.runner.visualstudio" />
17+
<PackageReference Include="xunit.runner.visualstudio">
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PrivateAssets>all</PrivateAssets>
20+
</PackageReference>
1821
<PackageReference Include="NSubstitute" />
1922
</ItemGroup>
2023

0 commit comments

Comments
 (0)