-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuleValidationTest.cs
79 lines (67 loc) · 2.37 KB
/
RuleValidationTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using RulesEngine.Exceptions;
using RulesEngine.HelperFunctions;
using RulesEngine.Models;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Xunit;
namespace RulesEngine.UnitTest;
[ExcludeFromCodeCoverage]
public class RuleValidationTest
{
[Fact]
public async Task NullExpressionithLambdaExpression_ReturnsExepectedResults()
{
var workflow = GetNullExpressionithLambdaExpressionWorkflow();
var reSettings = new ReSettings();
var action = () => {
_ = new RulesEngine(workflow, reSettings);
return Task.CompletedTask;
};
Exception ex = await Assert.ThrowsAsync<RuleValidationException>(action);
Assert.Contains(Constants.LAMBDA_EXPRESSION_EXPRESSION_NULL_ERRMSG, ex.Message);
}
[Fact]
public async Task NestedRulesWithMissingOperator_ReturnsExepectedResults()
{
var workflow = GetEmptyOperatorWorkflow();
var reSettings = new ReSettings();
var action = () => {
_ = new RulesEngine(workflow, reSettings);
return Task.CompletedTask;
};
Exception ex = await Assert.ThrowsAsync<RuleValidationException>(action);
Assert.Contains(Constants.OPERATOR_RULES_ERRMSG, ex.Message);
}
private Workflow[] GetNullExpressionithLambdaExpressionWorkflow()
{
return new[] {
new Workflow {
WorkflowName = "NestedRulesTest",
Rules = new Rule[] {
new() { RuleName = "TestRule", RuleExpressionType = RuleExpressionType.LambdaExpression }
}
}
};
}
private Workflow[] GetEmptyOperatorWorkflow()
{
return new[] {
new Workflow {
WorkflowName = "NestedRulesTest",
Rules = new Rule[] {
new() {
RuleName = "AndRuleTrueFalse",
Expression = "true == true",
Rules = new Rule[] {
new() { RuleName = "trueRule1", Expression = "input1.TrueValue == true" },
new() { RuleName = "falseRule1", Expression = "input1.TrueValue == false" }
}
}
}
}
};
}
}