-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to disable auto type registry (#501)
* - added option to disable auto type registry - removed caching from RuleExpressionParser * updated test cases * added test cases
- Loading branch information
Showing
11 changed files
with
194 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using RulesEngine.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace RulesEngine.UnitTest | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class CaseSensitiveTests | ||
{ | ||
[Theory] | ||
[InlineData(true,true,false)] | ||
[InlineData(false,true,true)] | ||
|
||
public async Task CaseSensitiveTest(bool caseSensitive, bool expected1, bool expected2) | ||
{ | ||
var reSettings = new ReSettings { | ||
IsExpressionCaseSensitive = caseSensitive | ||
}; | ||
|
||
|
||
var worflow = new Workflow { | ||
WorkflowName = "CaseSensitivityTest", | ||
Rules = new[] { | ||
new Rule { | ||
RuleName = "check same case1", | ||
Expression = "input1 == \"hello\"" | ||
}, | ||
new Rule { | ||
RuleName = "check same case2", | ||
Expression = "INPUT1 == \"hello\"" | ||
} | ||
} | ||
}; | ||
|
||
var re = new RulesEngine(new[] { worflow }, reSettings); | ||
var result = await re.ExecuteAllRulesAsync("CaseSensitivityTest", "hello"); | ||
|
||
Assert.Equal(expected1, result[0].IsSuccess); | ||
Assert.Equal(expected2, result[1].IsSuccess); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using RulesEngine.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace RulesEngine.UnitTest | ||
{ | ||
[Trait("Category", "Unit")] | ||
[ExcludeFromCodeCoverage] | ||
public class TypedClassTests | ||
{ | ||
public class Transazione | ||
{ | ||
public List<Attore> Attori { get; set; } = new(); | ||
} | ||
public class Attore | ||
{ | ||
public Guid Id { get; internal set; } | ||
public string Nome { get; internal set; } | ||
public RuoloAttore RuoloAttore { get; internal set; } | ||
} | ||
|
||
public enum RuoloAttore | ||
{ | ||
A, | ||
B, | ||
C | ||
} | ||
|
||
[Fact] | ||
public async Task TypedClassTest() | ||
{ | ||
Workflow workflow = new() { | ||
WorkflowName = "Conferimento", | ||
Rules = new Rule[] { | ||
new() { | ||
RuleName = "Attore Da", | ||
Enabled = true, | ||
ErrorMessage = "Attore Da Id must be defined", | ||
SuccessEvent = "10", | ||
RuleExpressionType = RuleExpressionType.LambdaExpression, | ||
Expression = "transazione.Attori.Any(a => a.RuoloAttore == 1)", | ||
}, | ||
new() { | ||
RuleName = "Attore A", | ||
Enabled = true, | ||
ErrorMessage = "Attore A must be defined", | ||
SuccessEvent = "10", | ||
RuleExpressionType = RuleExpressionType.LambdaExpression, | ||
Expression = "transazione.Attori != null", | ||
}, | ||
} | ||
}; | ||
var reSettings = new ReSettings() { | ||
CustomTypes = new Type[] { | ||
}, | ||
AutoRegisterInputType = false | ||
}; | ||
var re = new RulesEngine(reSettings); | ||
re.AddWorkflow(workflow); | ||
|
||
var param = new Transazione { | ||
Attori = new List<Attore>{ | ||
new Attore{ | ||
RuoloAttore = RuoloAttore.B, | ||
|
||
}, | ||
new Attore { | ||
RuoloAttore = RuoloAttore.C | ||
} | ||
} | ||
|
||
}; | ||
|
||
var result = await re.ExecuteAllRulesAsync("Conferimento", new RuleParameter("transazione", param)); | ||
|
||
Assert.All(result, (res) => Assert.True(res.IsSuccess)); | ||
|
||
} | ||
} | ||
} |