Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Should map metadata when converting from ResolutionDetails to FlagEvaluationDetails #282

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OpenFeature/Extension/ResolutionDetailsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class ResolutionDetailsExtensions
public static FlagEvaluationDetails<T> ToFlagEvaluationDetails<T>(this ResolutionDetails<T> details)
{
return new FlagEvaluationDetails<T>(details.FlagKey, details.Value, details.ErrorType, details.Reason,
details.Variant, details.ErrorMessage);
details.Variant, details.ErrorMessage, details.FlagMetadata);
}
}
}
24 changes: 24 additions & 0 deletions test/OpenFeature.Tests/OpenFeatureClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand All @@ -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;
Expand Down Expand Up @@ -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<string>();
var boolValue = fixture.Create<bool>();
var errorType = fixture.Create<ErrorType>();
var reason = fixture.Create<string>();
var variant = fixture.Create<string>();
var errorMessage = fixture.Create<string>();
var flagData = fixture
.CreateMany<KeyValuePair<string, object>>(10)
.ToDictionary(x => x.Key, x => x.Value);
var flagMetadata = new ImmutableMetadata(flagData);

var expected = new ResolutionDetails<bool>(flagName, boolValue, errorType, reason, variant, errorMessage, flagMetadata);
var result = expected.ToFlagEvaluationDetails();

result.Should().BeEquivalentTo(expected);
}
}
}