Add ContainsWorkflow method to check if workflow exists (#283)

* Add ContainsWorkflow method to check if workflow exists

* Add method to interface

Co-authored-by: anton.kheystver <anton.kheystver@opensoftdev.ru>
pull/284/head
Anton Kheystver 2021-11-25 16:32:21 +01:00 committed by GitHub
parent 108fa91968
commit 53213bf13e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -41,7 +41,14 @@ namespace RulesEngine.Interfaces
/// 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

View File

@ -209,6 +209,16 @@ namespace RulesEngine
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>

View File

@ -720,8 +720,31 @@ namespace RulesEngine.UnitTest
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))]