Skip to content

Commit

Permalink
fix: add operators for less than, greater than, less than equal, grea…
Browse files Browse the repository at this point in the history
…ter than equal, equal, not equal to ImplicitOperator to assist with empty arrays
  • Loading branch information
JasonBoggsAtHMSdotCom committed Nov 18, 2024
1 parent 3636edb commit f9b27da
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 19 deletions.
52 changes: 40 additions & 12 deletions src/RulesEngine/Models/ImplicitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,61 @@
// Licensed under the MIT License.
// https://github.com/asulwer/RulesEngine/issues/75

using System;
using System.Diagnostics.CodeAnalysis;

namespace RulesEngine.Models
{
[ExcludeFromCodeCoverage]
public class ImplicitObject
public class ImplicitObject : IEquatable<ImplicitObject>
{
public static implicit operator ImplicitObject(bool value) => default;
public static implicit operator ImplicitObject(bool _) => default;

public static implicit operator ImplicitObject(bool? value) => default;
public static implicit operator ImplicitObject(bool? _) => default;

public static implicit operator ImplicitObject(char value) => default;
public static implicit operator ImplicitObject(char _) => default;

public static implicit operator ImplicitObject(char? value) => default;
public static implicit operator ImplicitObject(char? _) => default;

public static implicit operator ImplicitObject(string value) => default;
public static implicit operator ImplicitObject(string _) => default;

public static implicit operator ImplicitObject(int value) => default;
public static implicit operator ImplicitObject(int _) => default;

public static implicit operator ImplicitObject(int? value) => default;
public static implicit operator ImplicitObject(int? _) => default;

public static implicit operator ImplicitObject(decimal value) => default;
public static implicit operator ImplicitObject(decimal _) => default;

public static implicit operator ImplicitObject(decimal? value) => default;
public static implicit operator ImplicitObject(decimal? _) => default;

public static implicit operator ImplicitObject(float value) => default;
public static implicit operator ImplicitObject(float _) => default;

public static implicit operator ImplicitObject(float? value) => default;
public static implicit operator ImplicitObject(float? _) => default;

public static bool operator <(ImplicitObject l, ImplicitObject r) => default;

public static bool operator >(ImplicitObject l, ImplicitObject r) => default;

public static bool operator <=(ImplicitObject l, ImplicitObject r) => default;

public static bool operator >=(ImplicitObject l, ImplicitObject r) => default;

public static bool operator ==(ImplicitObject l, ImplicitObject r) => default;

public static bool operator !=(ImplicitObject l, ImplicitObject r) => default;

public bool Equals(ImplicitObject other)
{
return default;
}

public override bool Equals(object obj)
{
return default;
}

public override int GetHashCode()
{
return default;
}
}
}
39 changes: 32 additions & 7 deletions test/RulesEngine.UnitTest/EmptyArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,32 @@ private async Task EmptyArray_ReturnsExepectedResults()
WorkflowName = "Workflow",
Rules = [
new() {
RuleName = "empty array",
Expression = "not things.Any(a == 3)",
RuleExpressionType = RuleExpressionType.LambdaExpression
RuleName = "equal string",
Expression = "not things.Any(a == \"widget\")"
},
new() {
RuleName = "equal integer",
Expression = "not things.Any(a == 3)"
},
new() {
RuleName = "not equal integer",
Expression = "not things.Any(a != 3)"
},
new() {
RuleName = "greater than integer",
Expression = "not things.Any(a > 3)"
},
new() {
RuleName = "less than integer",
Expression = "not things.Any(a < 3)"
},
new() {
RuleName = "greater than equal to integer",
Expression = "not things.Any(a >= 3)"
},
new() {
RuleName = "less than equal to integer",
Expression = "not things.Any(a <= 3)"
}
]
}
Expand All @@ -50,12 +73,14 @@ private async Task EmptyArray_ReturnsExepectedResults()
CancellationTokenSource cancellationTokenSource = new();
List<RuleResultTree> results = await rulesEngine.ExecuteAllRulesAsync("Workflow", cancellationTokenSource.Token, target);

Assert.Single(results);
Assert.True(results.TrueForAll(r => r.IsSuccess));

var result = results[0];
foreach (var result in results)
{
Assert.Equal(result.ExceptionMessage, string.Empty);
Assert.True(result.IsSuccess);
}

Assert.Equal(result.ExceptionMessage, string.Empty);
Assert.True(result.IsSuccess);

}

Expand Down

0 comments on commit f9b27da

Please sign in to comment.