* fix for ruleparameter name changes against cached rules * fixed indentation to match rest of code * suggested change implementedpull/391/head
parent
77750ae0b4
commit
a74f73a44e
|
@ -101,7 +101,9 @@ namespace RulesEngine
|
|||
/// <returns>List of rule results</returns>
|
||||
public async ValueTask<List<RuleResultTree>> ExecuteAllRulesAsync(string workflowName, params RuleParameter[] ruleParams)
|
||||
{
|
||||
var ruleResultList = ValidateWorkflowAndExecuteRule(workflowName, ruleParams);
|
||||
var sortedRuleParams = ruleParams.ToList();
|
||||
sortedRuleParams.Sort((RuleParameter a, RuleParameter b) => string.Compare(a.Name, b.Name));
|
||||
var ruleResultList = ValidateWorkflowAndExecuteRule(workflowName, sortedRuleParams.ToArray());
|
||||
await ExecuteActionAsync(ruleResultList);
|
||||
return ruleResultList;
|
||||
}
|
||||
|
@ -343,7 +345,8 @@ namespace RulesEngine
|
|||
|
||||
private string GetCompiledRulesKey(string workflowName, RuleParameter[] ruleParams)
|
||||
{
|
||||
var key = $"{workflowName}-" + string.Join("-", ruleParams.Select(c => c.Type.Name));
|
||||
var ruleParamsHash = string.Join("-", ruleParams.Select(c => $"{c.Name}_{c.Type.Name}")).GetHashCode();
|
||||
var key = $"{workflowName}-" + ruleParamsHash;
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using RulesEngine.Models;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace RulesEngine.UnitTest
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ParameterNameChangeTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task RunTwiceTest_ReturnsExpectedResults()
|
||||
{
|
||||
var workflow = new Workflow {
|
||||
WorkflowName = "ParameterNameChangeWorkflow",
|
||||
Rules = new Rule[] {
|
||||
new Rule {
|
||||
RuleName = "ParameterNameChangeRule",
|
||||
RuleExpressionType = RuleExpressionType.LambdaExpression,
|
||||
Expression = "test.blah == 1"
|
||||
}
|
||||
}
|
||||
};
|
||||
var engine = new RulesEngine();
|
||||
engine.AddOrUpdateWorkflow(workflow);
|
||||
|
||||
dynamic dynamicBlah = new ExpandoObject();
|
||||
dynamicBlah.blah = (Int64)1;
|
||||
var input_pass = new RuleParameter("test", dynamicBlah);
|
||||
var input_fail = new RuleParameter("SOME_OTHER_NAME", dynamicBlah);
|
||||
// RuleParameter name matches expression, so should pass.
|
||||
var pass_results = await engine.ExecuteAllRulesAsync("ParameterNameChangeWorkflow", input_pass);
|
||||
// RuleParameter name DOES NOT MATCH expression, so should fail.
|
||||
var fail_results = await engine.ExecuteAllRulesAsync("ParameterNameChangeWorkflow", input_fail);
|
||||
Assert.True(pass_results.First().IsSuccess);
|
||||
Assert.False(fail_results.First().IsSuccess);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue