Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty RuleParameter is required if there is a rule has undefined identifier in Expression #38

Closed
kamapcrazy opened this issue Aug 18, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@kamapcrazy
Copy link

kamapcrazy commented Aug 18, 2020

Step to reproduce:

  • Here is the workflow rules:
    • Noted that the second rule "AvailableIf" contains two more expression identifiers: productStock and customer
[
  {
    "WorkflowName": "DisplayProductAvailability",
    "WorkflowRulesToInject": null,
    "Rules": [
      {
        "RuleName": "AlwaysAvailable",
        "Operator": null,
        "ErrorMessage": "test",
        "ErrorType": "Warning",
        "RuleExpressionType": "LambdaExpression",
        "WorkflowRulesToInject": null,
        "Rules": null,
        "LocalParams": null,
        "Expression": "input.Name == \"Normal product\"",
        "SuccessEvent": null
      },
      {
        "RuleName": "AvailableIf",
        "Operator": "AndAlso",
        "ErrorMessage": "Not Available",
        "ErrorType": "Warning",
        "RuleExpressionType": null,
        "WorkflowRulesToInject": null,
        "Rules": [
          {
            "RuleName": "InStock",
            "Operator": null,
            "ErrorMessage": "Out of stock",
            "ErrorType": "Warning",
            "RuleExpressionType": "LambdaExpression",
            "WorkflowRulesToInject": null,
            "Rules": null,
            "LocalParams": null,
            "Expression": "input.Quantity < productStock.Quantity",
            "SuccessEvent": null
          },
          {
            "RuleName": "VisibleToCustomer",
            "Operator": null,
            "ErrorMessage": "Product is not available at customer location",
            "ErrorType": "Warning",
            "RuleExpressionType": "LambdaExpression",
            "WorkflowRulesToInject": null,
            "Rules": null,
            "LocalParams": null,
            "Expression": "productStock.Location == customer.Location",
            "SuccessEvent": null
          }
        ],
        "LocalParams": null,
        "Expression": null,
        "SuccessEvent": "In stock and visible to customer"
      }
    ]
  }
]
  • Execute the workflow with one RuleParameter:
dynamic input = new ExpandoObject();
input.Name = "Normal product";
var ruleParameters = new[]
   {
      new RuleParameter( nameof( input ), input )
   };
RulesEngine.ExecuteRule("DisplayProductAvailability", ruleParameters );

Result: An exception is thrown: "Target object is not an ExpandoObject"
My expection is that the RulesEngine run successfully and the RuleResult should be success for rule name "AlwaysAvailable"

  • Execute the workflow with two RuleParameters:
dynamic input = new ExpandoObject();
input.Name = "Normal product";
var ruleParameters = new[]
   {
      new RuleParameter( "empty", "" ), // empty rule parameter and not related to any rules expressions
      new RuleParameter( nameof( input ), input )
   };
RulesEngine.ExecuteRule("DisplayProductAvailability", ruleParameters );

Result: RulesEngine execute successfully, the first rule name is returned "AlwaysAvailable"

@abbasc52 abbasc52 self-assigned this Aug 22, 2020
@abbasc52 abbasc52 added the bug Something isn't working label Aug 22, 2020
@abbasc52
Copy link
Contributor

abbasc52 commented Sep 1, 2020

@kamapcrazy Can you try v2.1.1 and see if this issue still persists?

@abbasc52
Copy link
Contributor

this issue is fixed as a part of 2.1.1, you can refer this test case

[Theory]
[InlineData("rules2.json")]
public void ExecuteRule_ReturnsProperErrorOnMissingRuleParameter(string ruleFileName)
{
var re = GetRulesEngine(ruleFileName);
var input1 = new RuleParameter("customName",GetInput1());
var input2 = new RuleParameter("input2",GetInput2());
var input3 = new RuleParameter("input3",GetInput3());
List<RuleResultTree> result = re.ExecuteRule("inputWorkflow", input1,input2, input3);
Assert.NotNull(result);
Assert.IsType<List<RuleResultTree>>(result);
Assert.Contains(result.First().ChildResults, c => c.ExceptionMessage.Contains("Unknown identifier 'input1'"));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants