Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public class FeatureFlagConfigurationSetting : ConfigurationSetting

private static readonly string[] s_requiredJsonPropertyNames =
{
"id",
"enabled",
"conditions"
"id"
};

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,91 @@ public void InvalidConditionTypeIsTreatedAsInvalid()

Assert.IsTrue(_jsonComparer.Equals(expected.RootElement, actual.RootElement));
}

[Test]
public void FeatureFlagWithoutConditionsIsValid()
{
var featureFlagValue = "{\"id\":\"my feature\",\"enabled\":true}";
var featureFlag = new FeatureFlagConfigurationSetting();
featureFlag.Value = featureFlagValue;

Assert.AreEqual("my feature", featureFlag.FeatureId);
Assert.AreEqual(true, featureFlag.IsEnabled);
Assert.AreEqual(0, featureFlag.ClientFilters.Count);
}
Comment on lines +404 to +414
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage: There should be a test verifying that a feature flag with only id can roundtrip without modification. Currently, the CanRountripValue test doesn't include test cases for minimal feature flags (e.g., {"id":"my feature"}).

Consider adding test cases to CanRountripValue or creating a new test that verifies:

var featureFlagValue = "{\"id\":\"my feature\"}";
var featureFlag = new FeatureFlagConfigurationSetting();
featureFlag.Value = featureFlagValue;

using var expected = JsonDocument.Parse(featureFlagValue);
using var actual = JsonDocument.Parse(featureFlag.Value);
Assert.IsTrue(_jsonComparer.Equals(expected.RootElement, actual.RootElement));

This would ensure that reading and serializing without modification preserves the original minimal JSON structure.

Copilot uses AI. Check for mistakes.

[Test]
public void FeatureFlagWithoutConditionsCanBeModified()
{
var featureFlagValue = "{\"id\":\"my feature\",\"enabled\":false}";
var featureFlag = new FeatureFlagConfigurationSetting();
featureFlag.Value = featureFlagValue;

featureFlag.IsEnabled = true;
featureFlag.Description = "New description";
featureFlag.DisplayName = "New display name";

Assert.AreEqual("my feature", featureFlag.FeatureId);
Assert.AreEqual(true, featureFlag.IsEnabled);
Assert.AreEqual("New description", featureFlag.Description);
Assert.AreEqual("New display name", featureFlag.DisplayName);
Assert.AreEqual(0, featureFlag.ClientFilters.Count);

using var actual = JsonDocument.Parse(featureFlag.Value);
Assert.IsTrue(actual.RootElement.TryGetProperty("id", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("enabled", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("description", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("display_name", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("conditions", out _));
}

[Test]
public void FeatureFlagWithOnlyIdIsValid()
{
var featureFlagValue = "{\"id\":\"my feature\"}";
var featureFlag = new FeatureFlagConfigurationSetting();
featureFlag.Value = featureFlagValue;

Assert.AreEqual("my feature", featureFlag.FeatureId);
Assert.AreEqual(false, featureFlag.IsEnabled);
Assert.AreEqual(0, featureFlag.ClientFilters.Count);
}

[Test]
public void FeatureFlagWithoutEnabledIsValid()
{
var featureFlagValue = "{\"id\":\"my feature\",\"conditions\":{}}";
var featureFlag = new FeatureFlagConfigurationSetting();
featureFlag.Value = featureFlagValue;

Assert.AreEqual("my feature", featureFlag.FeatureId);
Assert.AreEqual(false, featureFlag.IsEnabled);
Assert.AreEqual(0, featureFlag.ClientFilters.Count);
}

[Test]
public void FeatureFlagWithoutEnabledCanBeModified()
{
var featureFlagValue = "{\"id\":\"my feature\",\"conditions\":{}}";
var featureFlag = new FeatureFlagConfigurationSetting();
featureFlag.Value = featureFlagValue;

featureFlag.IsEnabled = true;
featureFlag.Description = "New description";
featureFlag.DisplayName = "New display name";

Assert.AreEqual("my feature", featureFlag.FeatureId);
Assert.AreEqual(true, featureFlag.IsEnabled);
Assert.AreEqual("New description", featureFlag.Description);
Assert.AreEqual("New display name", featureFlag.DisplayName);
Assert.AreEqual(0, featureFlag.ClientFilters.Count);

using var actual = JsonDocument.Parse(featureFlag.Value);
Assert.IsTrue(actual.RootElement.TryGetProperty("id", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("enabled", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("description", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("display_name", out _));
Assert.IsTrue(actual.RootElement.TryGetProperty("conditions", out _));
}
}
}
Loading