forked from microsoft/RulesEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added demo code to support solution for microsoft#581
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using RulesEngine.Models; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using static RulesEngine.Extensions.ListofRuleResultTreeExtension; | ||
|
||
namespace DemoApp.Demos | ||
{ | ||
public class CustomParameterName | ||
{ | ||
public async Task Run(CancellationToken ct = default) | ||
{ | ||
Console.WriteLine($"Running {nameof(Basic)}...."); | ||
|
||
var workflows = new Workflow[] { | ||
new Workflow { | ||
WorkflowName = "my_workflow", | ||
Rules = [ | ||
new Rule { | ||
RuleName = "MatchesFabrikam", | ||
SuccessMessage = "does match", | ||
ErrorMessage = "does not match", | ||
Expression = "myValue.Value1 == \"Fabrikam\"" | ||
} | ||
] | ||
} | ||
}; | ||
|
||
var bre = new RulesEngine.RulesEngine(workflows); | ||
|
||
var rp = new RuleParameter[] { | ||
new RuleParameter("myValue", new { Value1 = "Fabrikam" }) | ||
}; | ||
|
||
await foreach (var async_rrt in bre.ExecuteAllWorkflows(rp, ct)) | ||
{ | ||
var outcome = false; | ||
|
||
//Different ways to show test results: | ||
outcome = async_rrt.TrueForAll(r => r.IsSuccess); | ||
|
||
async_rrt.OnSuccess((eventName) => { | ||
Console.WriteLine($"Result '{eventName}' is as expected."); | ||
outcome = true; | ||
}); | ||
|
||
async_rrt.OnFail(() => { | ||
outcome = false; | ||
}); | ||
|
||
Console.WriteLine($"Test outcome: {outcome}."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters