Skip to content

Commit

Permalink
added demo code to support solution for microsoft#581
Browse files Browse the repository at this point in the history
  • Loading branch information
asulwer committed Jun 27, 2024
1 parent 6bf1b7a commit 87bed71
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions DemoApp/Demos/CustomParameterName.cs
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}.");
}
}
}
}
1 change: 1 addition & 0 deletions DemoApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static async Task Main(string[] args)
await new Demos.EF().Run(cts.Token);
await new Demos.UseFastExpressionCompiler().Run(cts.Token);
await new Demos.MultipleWorkflows().Run(cts.Token);
await new Demos.CustomParameterName().Run(cts.Token);
}

DateTime end = DateTime.Now;
Expand Down

0 comments on commit 87bed71

Please sign in to comment.