Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static class EvaluationDetailExtensions

/// <summary>
/// Convert an <see cref="EvaluationReasonKind"/> into a string identifier.
/// This string identifier is the same as we would use in a JSON representation.
/// Uses the OpenFeature equivalent where one exists, otherwise the LaunchDarkly identifier.
/// </summary>
/// <param name="value">The value to convert</param>
/// <returns>The value as a string</returns>
Expand All @@ -31,11 +31,11 @@ private static string ToIdentifier(this EvaluationReasonKind value)
switch (value)
{
case EvaluationReasonKind.Off:
return "OFF";
return Reason.Disabled;
case EvaluationReasonKind.Fallthrough:
return "FALLTHROUGH";
case EvaluationReasonKind.TargetMatch:
return "TARGET_MATCH";
return Reason.TargetingMatch;
case EvaluationReasonKind.RuleMatch:
return "RULE_MATCH";
case EvaluationReasonKind.PrerequisiteFailed:
Expand Down Expand Up @@ -115,7 +115,6 @@ private static ImmutableMetadata ToFlagMetadata(this EvaluationReason reason, in
/// <param name="flagKey">The flag key that was evaluated</param>
/// <typeparam name="T">The type of the flag evaluation</typeparam>
/// <returns>The <see cref="EvaluationDetail{T}"/></returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the kind is not valid</exception>
public static ResolutionDetails<T> ToResolutionDetails<T>(this EvaluationDetail<T> detail, string flagKey)
{
if (detail.Reason.Kind != EvaluationReasonKind.Error)
Expand Down Expand Up @@ -145,10 +144,9 @@ public static ResolutionDetails<T> ToResolutionDetails<T>(this EvaluationDetail<
break;
case EvaluationErrorKind.Exception:
case null:
default:
// All general errors.
break;
default:
throw new ArgumentOutOfRangeException();
}

return new ResolutionDetails<T>(flagKey, detail.Value, errorType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public void ItCanHandleSuccessfulEvaluations()
[Fact]
public void ItCanHandleEachOfTheNonErrorEvaluationReasons()
{
Assert.Equal("OFF",
Assert.Equal("DISABLED",
new EvaluationDetail<bool>(true, 10, EvaluationReason.OffReason)
.ToResolutionDetails("test-flag").Reason);

Assert.Equal("FALLTHROUGH",
new EvaluationDetail<bool>(true, 10, EvaluationReason.FallthroughReason)
.ToResolutionDetails("test-flag").Reason);

Assert.Equal("TARGET_MATCH",
Assert.Equal("TARGETING_MATCH",
new EvaluationDetail<bool>(true, 10, EvaluationReason.TargetMatchReason)
.ToResolutionDetails("test-flag").Reason);

Expand Down Expand Up @@ -75,6 +75,20 @@ public void ItCanHandleErrorTypes()
.ToResolutionDetails("test-flag").ErrorType);
}

[Fact]
public void ItMapsUnknownErrorKindsToGeneral()
{
var detail = new EvaluationDetail<bool>(false, null,
EvaluationReason.ErrorReason((EvaluationErrorKind)int.MaxValue));

var resolution = detail.ToResolutionDetails("test-flag");

Assert.False(resolution.Value);
Assert.Equal("ERROR", resolution.Reason);
Assert.Equal(ErrorType.General, resolution.ErrorType);
Assert.Null(resolution.Variant);
}

[Fact]
public void ItIncludesTheVariationIndexInFlagMetadata()
{
Expand Down
Loading