diff --git a/demo/DemoApp/Demos/Basic.cs b/demo/DemoApp/Demos/Basic.cs index 593a7480..d24f88de 100644 --- a/demo/DemoApp/Demos/Basic.cs +++ b/demo/DemoApp/Demos/Basic.cs @@ -56,7 +56,7 @@ public async Task Run(CancellationToken ct = default) outcome = true; }); - resultList.OnFail((eventName) => { + resultList.OnFail(() => { outcome = false; }); diff --git a/demo/DemoApp/Demos/BasicWithCustomTypes.cs b/demo/DemoApp/Demos/BasicWithCustomTypes.cs index a8bc4354..bd944268 100644 --- a/demo/DemoApp/Demos/BasicWithCustomTypes.cs +++ b/demo/DemoApp/Demos/BasicWithCustomTypes.cs @@ -57,7 +57,7 @@ public async Task Run(CancellationToken ct = default) ruleResultTree.OnSuccess((eventName) => { Console.WriteLine($"Result '{eventName}' is as expected."); }); - ruleResultTree.OnFail((eventName) => { + ruleResultTree.OnFail(() => { Console.WriteLine($"Test outcome: false"); }); @@ -65,7 +65,7 @@ public async Task Run(CancellationToken ct = default) actionRuleResult.Results.OnSuccess((eventName) => { Console.WriteLine($"Result '{eventName}' is as expected."); }); - actionRuleResult.Results.OnFail((eventName) => { + actionRuleResult.Results.OnFail(() => { Console.WriteLine($"Test outcome: false"); }); } diff --git a/demo/DemoApp/Demos/EF.cs b/demo/DemoApp/Demos/EF.cs index 7261ad0c..28a9fbd4 100644 --- a/demo/DemoApp/Demos/EF.cs +++ b/demo/DemoApp/Demos/EF.cs @@ -70,7 +70,7 @@ public async Task Run(CancellationToken ct = default) discountOffered = $"Discount offered is {eventName} % over MRP."; }); - resultList.OnFail((eventName) => { + resultList.OnFail(() => { discountOffered = "The user is not eligible for any discount."; }); diff --git a/demo/DemoApp/Demos/JSON.cs b/demo/DemoApp/Demos/JSON.cs index 583e07c0..a6cd5820 100644 --- a/demo/DemoApp/Demos/JSON.cs +++ b/demo/DemoApp/Demos/JSON.cs @@ -53,7 +53,7 @@ public async Task Run(CancellationToken ct = default) discountOffered = $"Discount offered is {eventName} % over MRP."; }); - resultList.OnFail((eventName) => { + resultList.OnFail(() => { discountOffered = "The user is not eligible for any discount."; }); diff --git a/demo/DemoApp/Demos/NestedInput.cs b/demo/DemoApp/Demos/NestedInput.cs index fe649d5e..2e99bc3d 100644 --- a/demo/DemoApp/Demos/NestedInput.cs +++ b/demo/DemoApp/Demos/NestedInput.cs @@ -59,7 +59,7 @@ public async Task Run(CancellationToken ct = default) resultList.OnSuccess((eventName) => { Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in success - {eventName}"); - }).OnFail((eventName) => { + }).OnFail(() => { Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in failure"); }); } diff --git a/src/RulesEngine/Extensions/ListofRuleResultTreeExtension.cs b/src/RulesEngine/Extensions/ListofRuleResultTreeExtension.cs index b01db3b8..fc571ce8 100644 --- a/src/RulesEngine/Extensions/ListofRuleResultTreeExtension.cs +++ b/src/RulesEngine/Extensions/ListofRuleResultTreeExtension.cs @@ -11,7 +11,7 @@ namespace RulesEngine.Extensions public static class ListofRuleResultTreeExtension { public delegate void OnSuccessFunc(string eventName); - public delegate void OnFailureFunc(string eventName); + public delegate void OnFailureFunc(); /// @@ -40,13 +40,9 @@ public static List OnSuccess(this List ruleResul /// public static List OnFail(this List ruleResultTrees, OnFailureFunc onFailureFunc) { - var allFailure = ruleResultTrees.FirstOrDefault(ruleResult => ruleResult.IsSuccess == false); - if (allFailure != null) - { - var eventName = allFailure.Rule.ErrorMessage ?? allFailure.Rule.RuleName; - onFailureFunc(eventName); - } - + bool allFailure = ruleResultTrees.All(ruleResult => ruleResult.IsSuccess == false); + if (allFailure) + onFailureFunc(); return ruleResultTrees; } } diff --git a/test/RulesEngine.UnitTest/ListofRuleResultTreeExtensionTest.cs b/test/RulesEngine.UnitTest/ListofRuleResultTreeExtensionTest.cs index b2d97d62..f0184cf9 100644 --- a/test/RulesEngine.UnitTest/ListofRuleResultTreeExtensionTest.cs +++ b/test/RulesEngine.UnitTest/ListofRuleResultTreeExtensionTest.cs @@ -164,7 +164,7 @@ public void OnFailWithSuccessTest() var successEventName = true; - rulesResultTree.OnFail((eventName) => { + rulesResultTree.OnFail(() => { successEventName = false; }); @@ -203,7 +203,7 @@ public void OnFailWithoutSuccessTest() var successEventName = true; - rulesResultTree.OnFail((eventName) => { + rulesResultTree.OnFail(() => { successEventName = false; });