diff --git a/MicroRuleEngine.Core.Tests/ExampleUsage.cs b/MicroRuleEngine.Core.Tests/ExampleUsage.cs index 2db1971..918eb92 100644 --- a/MicroRuleEngine.Core.Tests/ExampleUsage.cs +++ b/MicroRuleEngine.Core.Tests/ExampleUsage.cs @@ -422,6 +422,67 @@ public void SerializeThenDeserialize() + MRE engine = new MRE(); + var compiledRule = engine.CompileRule(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 + { + + 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(jsonString); + + + MRE engine = new MRE(); var compiledRule = engine.CompileRule(deserializedRule); bool passes = compiledRule(orderParent);