Skip to content

Commit 2f8bd21

Browse files
benjiroaskpt
andauthored
fix: Should map metadata when converting from ResolutionDetails to FlagEvaluationDetails (#282)
## This PR When converting the ResolutionDetails to FlagEvalutionDetails we aren't passing the ImmutableMetadata to the new object. ### Related Issues Fixes [#281](#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 <[email protected]> Co-authored-by: André Silva <[email protected]>
1 parent 2dbe1f4 commit 2f8bd21

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/OpenFeature/Extension/ResolutionDetailsExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static class ResolutionDetailsExtensions
77
public static FlagEvaluationDetails<T> ToFlagEvaluationDetails<T>(this ResolutionDetails<T> details)
88
{
99
return new FlagEvaluationDetails<T>(details.FlagKey, details.Value, details.ErrorType, details.Reason,
10-
details.Variant, details.ErrorMessage);
10+
details.Variant, details.ErrorMessage, details.FlagMetadata);
1111
}
1212
}
1313
}

test/OpenFeature.Tests/OpenFeatureClientTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Collections.Immutable;
34
using System.Diagnostics.CodeAnalysis;
45
using System.Linq;
@@ -11,6 +12,7 @@
1112
using NSubstitute.ExceptionExtensions;
1213
using OpenFeature.Constant;
1314
using OpenFeature.Error;
15+
using OpenFeature.Extension;
1416
using OpenFeature.Model;
1517
using OpenFeature.Tests.Internal;
1618
using Xunit;
@@ -480,5 +482,27 @@ public void Should_Get_And_Set_Context()
480482
client.SetContext(new EvaluationContextBuilder().Set(KEY, VAL).Build());
481483
Assert.Equal(VAL, client.GetContext().GetValue(KEY).AsInteger);
482484
}
485+
486+
487+
[Fact]
488+
public void ToFlagEvaluationDetails_Should_Convert_All_Properties()
489+
{
490+
var fixture = new Fixture();
491+
var flagName = fixture.Create<string>();
492+
var boolValue = fixture.Create<bool>();
493+
var errorType = fixture.Create<ErrorType>();
494+
var reason = fixture.Create<string>();
495+
var variant = fixture.Create<string>();
496+
var errorMessage = fixture.Create<string>();
497+
var flagData = fixture
498+
.CreateMany<KeyValuePair<string, object>>(10)
499+
.ToDictionary(x => x.Key, x => x.Value);
500+
var flagMetadata = new ImmutableMetadata(flagData);
501+
502+
var expected = new ResolutionDetails<bool>(flagName, boolValue, errorType, reason, variant, errorMessage, flagMetadata);
503+
var result = expected.ToFlagEvaluationDetails();
504+
505+
result.Should().BeEquivalentTo(expected);
506+
}
483507
}
484508
}

0 commit comments

Comments
 (0)