-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic tests for jobject based inputs (#454)
* added basic tests for jobject based inputs * fixed test case
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
test/RulesEngine.UnitTest/RuleExpressionParserTests/RuleExpressionParserTests.cs
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,63 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Newtonsoft.Json.Linq; | ||
using RulesEngine.ExpressionBuilders; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using System.Text.Json; | ||
|
||
namespace RulesEngine.UnitTest.RuleExpressionParserTests | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class RuleExpressionParserTests | ||
{ | ||
public RuleExpressionParserTests() { | ||
|
||
|
||
} | ||
|
||
|
||
[Fact] | ||
public void TestExpressionWithJObject() | ||
{ | ||
var ruleParser = new RuleExpressionParser(new Models.ReSettings()); | ||
|
||
var inputStr = @"{ | ||
""list"": [ | ||
{ ""item1"": ""hello"", | ||
""item3"": 1 | ||
}, | ||
{ | ||
""item2"": ""world"" | ||
} | ||
] | ||
}"; | ||
|
||
|
||
var input = JObject.Parse(inputStr); | ||
|
||
|
||
var value = ruleParser.Evaluate<object>("input.list[0].item3 == 1", new[] { new Models.RuleParameter("input", input) }); | ||
|
||
Assert.Equal(true, | ||
value); | ||
|
||
|
||
var value2 = ruleParser.Evaluate<object>("input.list[1].item2 == \"world\"", new[] { new Models.RuleParameter("input", input) }); | ||
|
||
Assert.Equal(true, | ||
value2); | ||
|
||
|
||
var value3= ruleParser.Evaluate<object>("string.Concat(input.list[0].item1,input.list[1].item2)", new[] { new Models.RuleParameter("input", input) }); | ||
|
||
Assert.Equal("helloworld", value3); | ||
} | ||
} | ||
} |
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