-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuleExpressionBuilderFactoryTest.cs
56 lines (47 loc) · 1.87 KB
/
RuleExpressionBuilderFactoryTest.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using RulesEngine.ExpressionBuilders;
using RulesEngine.Models;
using System;
using System.Diagnostics.CodeAnalysis;
using Xunit;
namespace RulesEngine.UnitTest;
[Trait("Category", "Unit")]
[ExcludeFromCodeCoverage]
public class RuleExpressionBuilderFactoryTest
{
[Theory]
[InlineData(RuleExpressionType.LambdaExpression, typeof(LambdaExpressionBuilder))]
public void RuleGetExpressionBuilderTest(RuleExpressionType expressionType, Type expectedExpressionBuilderType)
{
var reSettings = new ReSettings();
var parser = new RuleExpressionParser(reSettings);
var objBuilderFactory = new RuleExpressionBuilderFactory(reSettings, parser);
var builder = objBuilderFactory.RuleGetExpressionBuilder(expressionType);
var builderType = builder.GetType();
Assert.Equal(expectedExpressionBuilderType.ToString(), builderType.ToString());
}
[Fact]
public void SystemLinqDynamicCore_WithLiterals_ParsingCorrectly()
{
var board = new { NumberOfMembers = default(decimal?) };
var parameter = RuleParameter.Create("Board", board);
var parser = new RuleExpressionParser();
try
{
const string expression1 = "Board.NumberOfMembers = 0.2d";
var result1 = parser.Evaluate<bool>(expression1, [parameter]);
Assert.False(result1);
}
catch (Exception)
{
// passing it over.
}
// This will throw an exception even if the expression is valid,
// because the first one executed and cached in the Literals Dictionary.
// This should not throw as it's valid.
const string expression2 = "Board.NumberOfMembers = 0.2";
var result2 = parser.Evaluate<bool>(expression2, [parameter]);
Assert.False(result2);
}
}