From 8a6d14bd88680cd377ce0a576a3821bd5f8420f9 Mon Sep 17 00:00:00 2001 From: Casey Waldren Date: Fri, 25 Oct 2024 12:34:09 -0700 Subject: [PATCH] add FeatureFlagBuilder.Prerequisites helper --- pkgs/sdk/client/src/DataModel.cs | 2 +- .../ModelBuilders.cs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkgs/sdk/client/src/DataModel.cs b/pkgs/sdk/client/src/DataModel.cs index 923e0169..30eda5f3 100644 --- a/pkgs/sdk/client/src/DataModel.cs +++ b/pkgs/sdk/client/src/DataModel.cs @@ -59,7 +59,7 @@ internal FeatureFlag( TrackEvents = trackEvents; TrackReason = trackReason; DebugEventsUntilDate = debugEventsUntilDate; - Prerequisites = prerequisites; + Prerequisites = prerequisites != null ? new List(prerequisites) : null; } /// diff --git a/pkgs/sdk/client/test/LaunchDarkly.ClientSdk.Tests/ModelBuilders.cs b/pkgs/sdk/client/test/LaunchDarkly.ClientSdk.Tests/ModelBuilders.cs index a32ffb92..3ae085e2 100644 --- a/pkgs/sdk/client/test/LaunchDarkly.ClientSdk.Tests/ModelBuilders.cs +++ b/pkgs/sdk/client/test/LaunchDarkly.ClientSdk.Tests/ModelBuilders.cs @@ -16,6 +16,7 @@ internal class FeatureFlagBuilder private bool _trackReason; private UnixMillisecondTime? _debugEventsUntilDate; private EvaluationReason? _reason; + private List _prerequisites; public FeatureFlagBuilder() { @@ -30,11 +31,12 @@ public FeatureFlagBuilder(FeatureFlag from) _trackReason = from.TrackReason; _debugEventsUntilDate = from.DebugEventsUntilDate; _reason = from.Reason; + _prerequisites = from.Prerequisites != null ? new List(from.Prerequisites) : null; } public FeatureFlag Build() { - return new FeatureFlag(_value, _variation, _reason, _version, _flagVersion, _trackEvents, _trackReason, _debugEventsUntilDate); + return new FeatureFlag(_value, _variation, _reason, _version, _flagVersion, _trackEvents, _trackReason, _debugEventsUntilDate, _prerequisites); } public FeatureFlagBuilder Value(LdValue value) @@ -88,6 +90,18 @@ public FeatureFlagBuilder DebugEventsUntilDate(UnixMillisecondTime? debugEventsU _debugEventsUntilDate = debugEventsUntilDate; return this; } + + public FeatureFlagBuilder Prerequisites(params string[] prerequisites) + { + if (prerequisites == null || prerequisites.Length == 0) + { + _prerequisites = null; + return this; + } + + _prerequisites = new List(prerequisites); + return this; + } } internal class DataSetBuilder