public async Task ExecuteRule_RuntimeError_IgnoreException_DoesNotReturnException() { var workflow = new WorkflowRules { WorkflowName = "TestWorkflow", Rules = new[] { new Rule { RuleName = "ruleWithRuntimeError", Expression = "input1.Country.ToLower() == \"india\"" } } }; var re = new RulesEngine(new[] { workflow }, null, new ReSettings { IgnoreException = true }); var input = new RuleTestClass { Country = null }; var result = await re.ExecuteAllRulesAsync("TestWorkflow", input); Assert.NotNull(result); Assert.All(result, rule => Assert.False(rule.IsSuccess)); Assert.All(result, rule => Assert.Empty(rule.ExceptionMessage)); }
public async Task RuntimeErrorInScopedParam_ShouldAppearAsErrorMessage(string workflowName) { var workflows = GetWorkflowRulesList(); var engine = new RulesEngine(new string[] { }, null); engine.AddWorkflow(workflows); var input = new RuleTestClass(); var result = await engine.ExecuteAllRulesAsync(workflowName, input); Assert.All(result, c => { Assert.False(c.IsSuccess); Assert.StartsWith("Error while executing scoped params for rule", c.ExceptionMessage); }); }
public async Task ExecuteRule_RuntimeError_ThrowsException() { var workflow = new WorkflowRules { WorkflowName = "TestWorkflow", Rules = new[] { new Rule { RuleName = "ruleWithRuntimeError", Expression = "input1.Country.ToLower() == \"india\"" } } }; var re = new RulesEngine(new[] { workflow }, null, new ReSettings { EnableExceptionAsErrorMessage = false }); var input = new RuleTestClass { Country = null }; _ = await Assert.ThrowsAsync <RuleException>(async() => await re.ExecuteAllRulesAsync("TestWorkflow", input)); }
public async Task ExecuteRule_RuntimeError_ShouldReturnAsErrorMessage() { var workflow = new WorkflowRules { WorkflowName = "TestWorkflow", Rules = new[] { new Rule { RuleName = "ruleWithRuntimeError", Expression = "input1.Country.ToLower() == \"india\"" } } }; var re = new RulesEngine(new[] { workflow }, null, null); var input = new RuleTestClass { Country = null }; var result = await re.ExecuteAllRulesAsync("TestWorkflow", input); Assert.NotNull(result); Assert.All(result, rule => Assert.False(rule.IsSuccess)); Assert.All(result, rule => Assert.StartsWith("Error while executing rule :", rule.ExceptionMessage)); }