diff --git a/src/ConfigCat.Client.Tests/UserTests.cs b/src/ConfigCat.Client.Tests/UserTests.cs index 2d2fdd0d..d4495e02 100644 --- a/src/ConfigCat.Client.Tests/UserTests.cs +++ b/src/ConfigCat.Client.Tests/UserTests.cs @@ -126,7 +126,6 @@ public void CreateUser_ShouldSetIdentifier(string identifier, string expectedVal Assert.AreEqual(expectedValue, user.GetAllAttributes()[nameof(User.Identifier)]); } - [DataTestMethod] [DataRow("datetime", "2023-09-19T11:01:35.0000000+00:00", "1695121295")] [DataRow("datetime", "2023-09-19T13:01:35.0000000+02:00", "1695121295")] diff --git a/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs b/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs index 30a90c8c..584cad75 100644 --- a/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs +++ b/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs @@ -203,11 +203,10 @@ private static IndentedTextBuilder AppendPercentageOptions(this IndentedTextBuil private static IndentedTextBuilder AppendTargetingRuleThenPart(this IndentedTextBuilder builder, TargetingRule targetingRule, bool newLine, bool appendPercentageOptions = false, string? percentageOptionsAttribute = null) { - var percentageOptions = targetingRule.PercentageOptions; - (newLine ? builder.NewLine() : builder.Append(" ")) .Append("THEN"); + var percentageOptions = targetingRule.PercentageOptions; if (percentageOptions is not { Length: > 0 }) { return builder.Append($" '{targetingRule.SimpleValue?.Value ?? default}'"); @@ -304,22 +303,16 @@ public static string ToDisplayText(this UserComparator comparator) { return comparator switch { - UserComparator.IsOneOf or UserComparator.SensitiveIsOneOf => "IS ONE OF", - UserComparator.IsNotOneOf or UserComparator.SensitiveIsNotOneOf => "IS NOT ONE OF", + UserComparator.IsOneOf or UserComparator.SensitiveIsOneOf or UserComparator.SemVerIsOneOf => "IS ONE OF", + UserComparator.IsNotOneOf or UserComparator.SensitiveIsNotOneOf or UserComparator.SemVerIsNotOneOf => "IS NOT ONE OF", UserComparator.ContainsAnyOf => "CONTAINS ANY OF", UserComparator.NotContainsAnyOf => "NOT CONTAINS ANY OF", - UserComparator.SemVerIsOneOf => "IS ONE OF", - UserComparator.SemVerIsNotOneOf => "IS NOT ONE OF", - UserComparator.SemVerLess => "<", - UserComparator.SemVerLessOrEquals => "<=", - UserComparator.SemVerGreater => ">", - UserComparator.SemVerGreaterOrEquals => ">=", + UserComparator.SemVerLess or UserComparator.NumberLess => "<", + UserComparator.SemVerLessOrEquals or UserComparator.NumberLessOrEquals => "<=", + UserComparator.SemVerGreater or UserComparator.NumberGreater => ">", + UserComparator.SemVerGreaterOrEquals or UserComparator.NumberGreaterOrEquals => ">=", UserComparator.NumberEquals => "=", UserComparator.NumberNotEquals => "!=", - UserComparator.NumberLess => "<", - UserComparator.NumberLessOrEquals => "<=", - UserComparator.NumberGreater => ">", - UserComparator.NumberGreaterOrEquals => ">=", UserComparator.DateTimeBefore => "BEFORE", UserComparator.DateTimeAfter => "AFTER", UserComparator.TextEquals or UserComparator.SensitiveTextEquals => "EQUALS", diff --git a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs index 7dcb62de..60e0d233 100644 --- a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs +++ b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs @@ -62,7 +62,7 @@ public EvaluateResult Evaluate(T defaultValue, ref EvaluateContext context, [ if (context.Setting.SettingType != Setting.UnknownType && context.Setting.SettingType != expectedSettingType) { throw new InvalidOperationException( - "The type of a setting must match the type of the specified default value " + "The type of a setting must match the type of the specified default value. " + $"Setting's type was {context.Setting.SettingType} but the default value's type was {typeof(T)}. " + $"Please use a default value which corresponds to the setting type {context.Setting.SettingType}."); } @@ -159,13 +159,10 @@ private bool TryEvaluateTargetingRules(TargetingRule[] targetingRules, ref Evalu logBuilder?.DecreaseIndent(); return true; } - else - { - logBuilder? - .NewLine(TargetingRuleIgnoredMessage) - .DecreaseIndent(); - continue; - } + + logBuilder? + .NewLine(TargetingRuleIgnoredMessage) + .DecreaseIndent(); } result = default; @@ -237,14 +234,14 @@ private bool TryEvaluatePercentageOptions(PercentageOption[] percentageOptions, continue; } - var percentageOptionValue = percentageOption.Value.GetValue(context.Setting.SettingType, throwIfInvalid: false); + var percentageOptionValue = percentageOption.Value.GetValue(throwIfInvalid: false); logBuilder?.NewLine().Append($"- Hash value {hashValue} selects % option {i + 1} ({percentageOption.Percentage}%), '{percentageOptionValue ?? EvaluateLogHelper.InvalidValuePlaceholder}'."); result = new EvaluateResult(percentageOption, matchedTargetingRule: targetingRule, matchedPercentageOption: percentageOption); return true; } - throw new InvalidOperationException("Sum of percentage option percentages are less than 100)."); + throw new InvalidOperationException("Sum of percentage option percentages are less than 100."); } private bool EvaluateConditions(TCondition[] conditions, TargetingRule? targetingRule, string contextSalt, ref EvaluateContext context, out string? error) @@ -301,12 +298,15 @@ private bool EvaluateConditions(TCondition[] conditions, TargetingRu throw new InvalidOperationException(); // execution should never get here } - if (targetingRule is null || conditions.Length > 1) + if (logBuilder is not null) { - logBuilder?.AppendConditionConsequence(conditionResult); - } + if (targetingRule is null || conditions.Length > 1) + { + logBuilder.AppendConditionConsequence(conditionResult); + } - logBuilder?.DecreaseIndent(); + logBuilder.DecreaseIndent(); + } if (!conditionResult) { @@ -429,7 +429,7 @@ private bool EvaluateUserCondition(UserCondition condition, string contextSalt, error = HandleInvalidUserAttribute(condition, context.Key, userAttributeName, $"'{userAttributeValue}' is not a valid decimal number"); return false; } - return EvaluateNumberRelation(number, condition.Comparator, condition.DoubleValue); + return EvaluateNumberRelation(number, comparator, condition.DoubleValue); case UserComparator.DateTimeBefore: case UserComparator.DateTimeAfter: @@ -620,7 +620,7 @@ private static bool EvaluateSemVerIsOneOf(SemVersion version, string[]? comparis if (!result && version.PrecedenceMatches(version2)) { // NOTE: Previous versions of the evaluation algorithm require that - // all the comparison values are empty or valid, that is, we can't stop when finding a match. + // none of the comparison values are empty or invalid, that is, we can't stop when finding a match. // We keep this behavior for backward compatibility. result = true; }