From 242d03ef242ace0f54840ec13e91b4994319e015 Mon Sep 17 00:00:00 2001 From: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> Date: Fri, 26 Jul 2024 23:26:34 +1000 Subject: [PATCH] fix: Should map metadata when converting from ResolutionDetails to FlagEvaluationDetails (#282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## This PR When converting the ResolutionDetails to FlagEvalutionDetails we aren't passing the ImmutableMetadata to the new object. ### Related Issues Fixes [#281](https://github.com/open-feature/dotnet-sdk/issues/281) ### Notes This PR is done on a common merge base so we can merge it into v1 as well ### Follow-up Tasks N/A ### How to test Unit test added to covert the missing test case --------- Signed-off-by: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com> Signed-off-by: Artyom Tonoyan --- .../Extension/ResolutionDetailsExtensions.cs | 2 +- .../OpenFeatureClientTests.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 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); } } } diff --git a/test/OpenFeature.Tests/OpenFeatureClientTests.cs b/test/OpenFeature.Tests/OpenFeatureClientTests.cs index 925de66a..d1a91c1f 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; @@ -480,5 +482,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 ImmutableMetadata(flagData); + + var expected = new ResolutionDetails(flagName, boolValue, errorType, reason, variant, errorMessage, flagMetadata); + var result = expected.ToFlagEvaluationDetails(); + + result.Should().BeEquivalentTo(expected); + } } }