From 09bec709414a09fd62ba4403b894918e24419d2c Mon Sep 17 00:00:00 2001 From: "anton.kheystver" Date: Wed, 24 Nov 2021 18:02:14 +0100 Subject: [PATCH 1/2] Add ContainsWorkflow method to check if workflow exists --- src/RulesEngine/RulesEngine.cs | 10 ++++++++ .../BusinessRuleEngineTest.cs | 25 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/RulesEngine/RulesEngine.cs b/src/RulesEngine/RulesEngine.cs index beac63aa..c45ee84b 100644 --- a/src/RulesEngine/RulesEngine.cs +++ b/src/RulesEngine/RulesEngine.cs @@ -209,6 +209,16 @@ public void AddOrUpdateWorkflow(params Workflow[] workflows) public List GetAllRegisteredWorkflowNames() { return _rulesCache.GetAllWorkflowNames(); + } + + /// + /// Checks is workflow exist. + /// + /// The workflow name. + /// true if contains the specified workflow name; otherwise, false. + public bool ContainsWorkflow(string workflowName) + { + return _rulesCache.ContainsWorkflows(workflowName); } /// diff --git a/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs b/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs index 0cd9f104..209c6ba2 100644 --- a/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs +++ b/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs @@ -720,8 +720,31 @@ public async Task ExecuteRule_SpecialCharInWorkflowName_RunsSuccessfully() List result3 = await re.ExecuteAllRulesAsync("Exámple", input1); Assert.True(result3.All(c => c.IsSuccess)); - } + } + + [Fact] + public void ContainsWorkFlowName_ShouldReturn() + { + const string ExistedWorkflowName = "ExistedWorkflowName"; + const string NotExistedWorkflowName = "NotExistedWorkflowName"; + var workflow = new Workflow { + WorkflowName = ExistedWorkflowName, + Rules = new Rule[]{ + new Rule { + RuleName = "Rule", + RuleExpressionType = RuleExpressionType.LambdaExpression, + Expression = "1==1" + } + } + }; + + var re = new RulesEngine(); + re.AddWorkflow(workflow); + + Assert.True(re.ContainsWorkflow(ExistedWorkflowName)); + Assert.False(re.ContainsWorkflow(NotExistedWorkflowName)); + } [Theory] [InlineData(typeof(RulesEngine),typeof(IRulesEngine))] From b00412986b31ec1541bc72e2c63c998ea759c0c4 Mon Sep 17 00:00:00 2001 From: "anton.kheystver" Date: Wed, 24 Nov 2021 18:12:56 +0100 Subject: [PATCH 2/2] Add method to interface --- src/RulesEngine/Interfaces/IRulesEngine.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/RulesEngine/Interfaces/IRulesEngine.cs b/src/RulesEngine/Interfaces/IRulesEngine.cs index 69f0e655..000bdfc3 100644 --- a/src/RulesEngine/Interfaces/IRulesEngine.cs +++ b/src/RulesEngine/Interfaces/IRulesEngine.cs @@ -41,7 +41,14 @@ public interface IRulesEngine /// Removes the workflow from RulesEngine /// /// - void RemoveWorkflow(params string[] workflowNames); + void RemoveWorkflow(params string[] workflowNames); + + /// + /// Checks is workflow exist. + /// + /// The workflow name. + /// true if contains the specified workflow name; otherwise, false. + bool ContainsWorkflow(string workflowName); /// /// Returns the list of all registered workflow names