Skip to content

Commit

Permalink
fix: make segment ids deserialize as ints instead of strings (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleek authored Nov 17, 2023
1 parent cccf3ef commit 3378109
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Unleash/Internal/ActivationStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class ActivationStrategy
public string Name { get; }
public Dictionary<string, string> Parameters { get; }
public List<Constraint> Constraints { get; }
public List<string> Segments { get; }
public List<int> Segments { get; }
public List<VariantDefinition> Variants { get; }

public ActivationStrategy(string name, Dictionary<string, string> parameters, List<Constraint> constraints = null, List<string> segments = null, List<VariantDefinition> variants = null)
public ActivationStrategy(string name, Dictionary<string, string> parameters, List<Constraint> constraints = null, List<int> segments = null, List<VariantDefinition> variants = null)
{
Name = name;
Parameters = parameters ?? new Dictionary<string, string>();
Constraints = constraints ?? new List<Constraint>();
Segments = segments ?? new List<string>();
Segments = segments ?? new List<int>();
Variants = variants ?? new List<VariantDefinition>();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Unleash/Internal/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Unleash.Internal
{
public class Segment
{
public string Id { get; }
public int Id { get; }
public List<Constraint> Constraints { get; }
public Segment(string id, List<Constraint> constraints = null)
public Segment(int id, List<Constraint> constraints = null)
{
Id = id;
Constraints = constraints ?? new List<Constraint>();
Expand Down
6 changes: 3 additions & 3 deletions src/Unleash/Internal/ToggleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class ToggleCollection

private readonly Dictionary<string, FeatureToggle> togglesCache;

private readonly Dictionary<string, Segment> segmentsCache;
private readonly Dictionary<int, Segment> segmentsCache;

public ToggleCollection(ICollection<FeatureToggle> features = null, ICollection<Segment> segments = null)
{
Features = features ?? new List<FeatureToggle>(0);
Segments = segments ?? new List<Segment>(0);

togglesCache = new Dictionary<string, FeatureToggle>(Features.Count);
segmentsCache = new Dictionary<string, Segment>(Segments.Count);
segmentsCache = new Dictionary<int, Segment>(Segments.Count);

foreach (var featureToggle in Features) {
togglesCache.Add(featureToggle.Name, featureToggle);
Expand All @@ -47,7 +47,7 @@ public FeatureToggle GetToggleByName(string name)
: null;
}

public Segment GetSegmentById(string id)
public Segment GetSegmentById(int id)
{
return segmentsCache.TryGetValue(id, out var value)
? value
Expand Down
6 changes: 3 additions & 3 deletions tests/Unleash.Tests/Strategy/Segments_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Two_Constraints_With_Item_Id_Equals_1_And_Context_Item_Id_Equals_1_S
{
// Arrange
var appname = "masstest";
var segmentIds = new List<string>() { "1", "2" };
var segmentIds = new List<int>() { 1, 2 };
var toggles = new List<FeatureToggle>()
{
new FeatureToggle("item", "release", true, false, new List<ActivationStrategy>() { new ActivationStrategy("default", new Dictionary<string, string>(), null, segmentIds) })
Expand All @@ -49,7 +49,7 @@ public void Two_Constraints_One_Correct_In_Segment_One_Wrong_In_Strategy_Should_
{
// Arrange
var appname = "masstest";
var segmentIds = new List<string>() { "1" };
var segmentIds = new List<int>() { 1 };
var toggles = new List<FeatureToggle>()
{
new FeatureToggle("item", "release", true, false, new List<ActivationStrategy>() { new ActivationStrategy("default", new Dictionary<string, string>(), new List<Constraint>() { new Constraint("item-id", Operator.NUM_EQ, false, false, "15") }, segmentIds) })
Expand All @@ -74,7 +74,7 @@ public void Two_Constraints_One_In_Segment_One_In_Strategy_Both_Correct_Should_E
{
// Arrange
var appname = "masstest";
var segmentIds = new List<string>() { "1" };
var segmentIds = new List<int>() { 1 };
var toggles = new List<FeatureToggle>()
{
new FeatureToggle("item", "release", true, false, new List<ActivationStrategy>() { new ActivationStrategy("default", new Dictionary<string, string>(), new List<Constraint>() { new Constraint("item-id", Operator.NUM_EQ, false, false, "1") }, segmentIds) })
Expand Down

0 comments on commit 3378109

Please sign in to comment.