From 64325954f0fa02e77ae44630cd70e05c05aeb983 Mon Sep 17 00:00:00 2001 From: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:09:52 +1000 Subject: [PATCH 1/2] fix: Should map metadata when converting from ResolutionDetails to FlagEvaluationDetails Signed-off-by: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> --- src/OpenFeature/Extension/ResolutionDetailsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenFeature/Extension/ResolutionDetailsExtensions.cs b/src/OpenFeature/Extension/ResolutionDetailsExtensions.cs index 616e530a..f38356ad 100644 --- a/src/OpenFeature/Extension/ResolutionDetailsExtensions.cs +++ b/src/OpenFeature/Extension/ResolutionDetailsExtensions.cs @@ -7,7 +7,7 @@ internal static class ResolutionDetailsExtensions public static FlagEvaluationDetails ToFlagEvaluationDetails(this ResolutionDetails details) { return new FlagEvaluationDetails(details.FlagKey, details.Value, details.ErrorType, details.Reason, - details.Variant, details.ErrorMessage); + details.Variant, details.ErrorMessage, details.FlagMetadata); } } } From 3dba5ee82223ed60220889e7868a96ad5d76db44 Mon Sep 17 00:00:00 2001 From: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:09:47 +1000 Subject: [PATCH 2/2] test: Make sure ToFlagEvalutionDetails passes FlagMetadata Signed-off-by: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> --- .../OpenFeatureClientTests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/OpenFeature.Tests/OpenFeatureClientTests.cs b/test/OpenFeature.Tests/OpenFeatureClientTests.cs index 86c61f83..b3c0d5af 100644 --- a/test/OpenFeature.Tests/OpenFeatureClientTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -11,6 +12,7 @@ using NSubstitute.ExceptionExtensions; using OpenFeature.Constant; using OpenFeature.Error; +using OpenFeature.Extension; using OpenFeature.Model; using OpenFeature.Tests.Internal; using Xunit; @@ -365,5 +367,27 @@ public void Should_Get_And_Set_Context() client.SetContext(new EvaluationContextBuilder().Set(KEY, VAL).Build()); Assert.Equal(VAL, client.GetContext().GetValue(KEY).AsInteger); } + + + [Fact] + public void ToFlagEvaluationDetails_Should_Convert_All_Properties() + { + var fixture = new Fixture(); + var flagName = fixture.Create(); + var boolValue = fixture.Create(); + var errorType = fixture.Create(); + var reason = fixture.Create(); + var variant = fixture.Create(); + var errorMessage = fixture.Create(); + var flagData = fixture + .CreateMany>(10) + .ToDictionary(x => x.Key, x => x.Value); + var flagMetadata = new FlagMetadata(flagData); + + var expected = new ResolutionDetails(flagName, boolValue, errorType, reason, variant, errorMessage, flagMetadata); + var result = expected.ToFlagEvaluationDetails(); + + result.Should().BeEquivalentTo(expected); + } } }