Skip to content

Commit 9da576d

Browse files
committed
Adding FeatureFlagParser class's unit tests
Signed-off-by: Ash.Wani <[email protected]>
1 parent 373ce3f commit 9da576d

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

test/OpenFeature.Contrib.Providers.AwsAppConfig.Test/AppConfigKeyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void Constructor_WithThreeParts_SetsPropertiesCorrectly()
141141
public void Constructor_WithInvalidPattern_ShouldThrowArgumentException(string key)
142142
{
143143
// Act & Assert
144-
var exception = Assert.Throws<ArgumentException>(() => new AppConfigKey("::"));
144+
var exception = Assert.Throws<ArgumentException>(() => new AppConfigKey(key));
145145
Assert.Equal("Invalid key format. Flag key is expected in configurationProfileId:flagKey[:attributeKey] format", exception.Message);
146146
}
147147

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Xunit;
2+
using System;
3+
using System.Text.Json;
4+
using OpenFeature.Model;
5+
using Microsoft.Extensions.Configuration;
6+
using OpenFeature.Contrib.Providers.AwsAppConfig;
7+
8+
public class FeatureFlagParserTests
9+
{
10+
private readonly string _jsonContent;
11+
12+
public FeatureFlagParserTests()
13+
{
14+
_jsonContent = System.IO.File.ReadAllText("test-data.json");
15+
}
16+
17+
[Fact]
18+
public void ParseFeatureFlag_EnabledFlag_ReturnsValue()
19+
{
20+
// Act
21+
var result = FeatureFlagParser.ParseFeatureFlag("test-enabled-flag", new Value(), _jsonContent);
22+
23+
// Assert
24+
Assert.True(result.IsStructure);
25+
Assert.True(result.AsStructure["enabled"].AsBoolean);
26+
Assert.Equal("testValue", result.AsStructure["additionalAttribute"].AsString);
27+
}
28+
29+
[Fact]
30+
public void ParseFeatureFlag_DisabledFlag_ReturnsValue()
31+
{
32+
// Act
33+
var result = FeatureFlagParser.ParseFeatureFlag("test-disabled-flag", new Value(), _jsonContent);
34+
35+
// Assert
36+
Assert.True(result.IsStructure);
37+
Assert.False(result.AsStructure["enabled"].AsBoolean);
38+
}
39+
40+
[Theory]
41+
[InlineData("")]
42+
[InlineData(null)]
43+
[InlineData("invalid")]
44+
public void ParseFeatureFlag_WhenValueIsInvalid_ThrowsArgumentNullException(string input)
45+
{
46+
// Act & Assert
47+
if(input == null){
48+
Assert.Throws<ArgumentNullException>(() => FeatureFlagParser.ParseFeatureFlag("test-enabled-flag", new Value(), input));
49+
}
50+
else
51+
{
52+
Assert.Throws<JsonException>(() => FeatureFlagParser.ParseFeatureFlag("test-enabled-flag", new Value(), input));
53+
}
54+
55+
}
56+
}

test/OpenFeature.Contrib.Providers.AwsAppConfig.Test/OpenFeature.Contrib.Providers.AwsAppConfig.Test.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44
<ProjectReference Include="..\..\src\OpenFeature.Contrib.Providers.AwsAppConfig\OpenFeature.Contrib.Providers.AwsAppConfig.csproj" />
55
</ItemGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" />
9+
</ItemGroup>
10+
711
<PropertyGroup>
812
<IsPackable>false</IsPackable>
913
<IsTestProject>true</IsTestProject>
1014
</PropertyGroup>
1115

16+
<ItemGroup>
17+
<None Update="test-data.json">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
1222
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"test-enabled-flag": {
3+
"enabled": true,
4+
"additionalAttribute": "testValue"
5+
},
6+
"test-disabled-flag": {
7+
"enabled": false
8+
}
9+
}

0 commit comments

Comments
 (0)