forked from microsoft/RulesEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue573Test.cs
More file actions
68 lines (64 loc) · 2.74 KB
/
Issue573Test.cs
File metadata and controls
68 lines (64 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using RulesEngine.Models;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Xunit;
namespace RulesEngine.UnitTest
{
[ExcludeFromCodeCoverage]
public class Issue573Test
{
// Demonstrates the correct way to pass computed additionalInputs into an EvaluateRule
// action. The target rule can reference the additionalInput by its Name. The key detail
// (the source of the "Unknown identifier" confusion in #573) is that the additionalInput
// Name must match the identifier used in the target rule's expression.
[Fact]
public async Task EvaluateRuleAction_AdditionalInputs_AreAvailableToTargetRule()
{
var workflow = new Workflow
{
WorkflowName = "wf",
Rules = new[]
{
new Rule
{
RuleName = "Parent",
Expression = "input1.Value > 0",
Actions = new RuleActions
{
OnSuccess = new ActionInfo
{
Name = "EvaluateRule",
Context = new Dictionary<string, object>
{
{ "workflowName", "wf" },
{ "ruleName", "Child" },
// Compute a new input named "doubled" from input1 and pass it on.
{ "additionalInputs", new List<ScopedParam>
{
new ScopedParam { Name = "doubled", Expression = "input1.Value * 2" }
}
}
}
}
}
},
new Rule
{
RuleName = "Child",
// References the additionalInput by name.
Expression = "doubled == 20"
}
}
};
var engine = new RulesEngine(new[] { workflow });
var result = await engine.ExecuteActionWorkflowAsync("wf", "Parent",
new[] { RuleParameter.Create("input1", new { Value = 10 }) });
// Child rule succeeded because "doubled" (10*2=20) was available to it.
Assert.NotNull(result.Results);
Assert.Contains(result.Results, r => r.Rule.RuleName == "Child" && r.IsSuccess);
}
}
}