Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContainsWorkflow method to check if workflow exists #283

Merged
merged 2 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/RulesEngine/Interfaces/IRulesEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ public interface IRulesEngine
/// Removes the workflow from RulesEngine
/// </summary>
/// <param name="workflowNames"></param>
void RemoveWorkflow(params string[] workflowNames);
void RemoveWorkflow(params string[] workflowNames);

/// <summary>
/// Checks is workflow exist.
/// </summary>
/// <param name="workflowName">The workflow name.</param>
/// <returns> <c>true</c> if contains the specified workflow name; otherwise, <c>false</c>.</returns>
bool ContainsWorkflow(string workflowName);

/// <summary>
/// Returns the list of all registered workflow names
Expand Down
10 changes: 10 additions & 0 deletions src/RulesEngine/RulesEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ public void AddOrUpdateWorkflow(params Workflow[] workflows)
public List<string> GetAllRegisteredWorkflowNames()
{
return _rulesCache.GetAllWorkflowNames();
}

/// <summary>
/// Checks is workflow exist.
/// </summary>
/// <param name="workflowName">The workflow name.</param>
/// <returns> <c>true</c> if contains the specified workflow name; otherwise, <c>false</c>.</returns>
public bool ContainsWorkflow(string workflowName)
{
return _rulesCache.ContainsWorkflows(workflowName);
}

/// <summary>
Expand Down
25 changes: 24 additions & 1 deletion test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,31 @@ public async Task ExecuteRule_SpecialCharInWorkflowName_RunsSuccessfully()
List<RuleResultTree> 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))]
Expand Down