Skip to content

Commit

Permalink
Add additional Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
joursler-Sunset committed May 18, 2021
1 parent dbb2d5e commit 2952490
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions MicroRuleEngine.Core.Tests/ExampleUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,67 @@ public void SerializeThenDeserialize()



MRE engine = new MRE();
var compiledRule = engine.CompileRule<OrderParent>(deserializedRule);
bool passes = compiledRule(orderParent);
Assert.IsFalse(passes);

order.Items.Add(new Item());
order.Items.Add(new Item());

passes = compiledRule(orderParent);

Assert.IsTrue(passes);
}

[TestMethod]
public void SerializeThenDeserializeComplexRules()
{



Order order = GetOrder();

var orderParent = new OrderParent() {PlacedOrder = order};


Rule rule = new Rule
{
Operator = "AndAlso",
Rules = new List<Rule>
{

new Rule
{
MemberName = "PlacedOrder.Items",
EnumerableValueExpression = new Selector
{
Operator = "Count"
},
Operator = "GreaterThan",
TargetValue = 3
},

new Rule
{
MemberName = "PlacedOrder.Items",
EnumerableValueExpression = new Selector
{
MemberName = "Cost",
Operator = "Sum"
},
Operator = "GreaterThan",
TargetValue = 5
}
}
};

var jsonString = JsonConvert.SerializeObject(rule);

var deserializedRule = JsonConvert.DeserializeObject<Rule>(jsonString);



MRE engine = new MRE();
var compiledRule = engine.CompileRule<OrderParent>(deserializedRule);
bool passes = compiledRule(orderParent);
Expand Down

0 comments on commit 2952490

Please sign in to comment.