shujaat siddiqui
shujaat siddiqui

Reputation: 1577

Microsoft Json Rule Engine Custom Error Message

I am using the following library for json base rule engine. https://github.com/microsoft/RulesEngine

I want to concatenate property value into error message. I have a list of collection and I want to concatenate what item in the list satisfy the expression criteria.

{
        "RuleName": "CheckforVTPumpSelectionErrors121-03",
        "ErrorMessage": "WARNING: 121 - VT PUMP Manual Pick Required for {0} HP {1} pump!",
         "Expression": "ProductFamily.PumpConfigurations.Any(r => r.PumpDescription == \"Water Feature\" || r.PumpDescription == \"Transfer\") && Flag1 == false"
}

I want to replace {0} with horse power value.

My DTO:

public class ProductFamily
    {
        public int SCCR = 30;
        public List<PumpConfiguration> PumpConfigurations { get; set; }
    }

 public class PumpConfiguration
    {
        public PumpConfiguration()
        {
        }
        public string PumpDescription { get; internal set; }
        public int HP { get; internal set; }
    }

Upvotes: 1

Views: 739

Answers (1)

Prasad Ramireddy
Prasad Ramireddy

Reputation: 297

For custom error message:

Please find an unit test at https://github.com/microsoft/RulesEngine/blob/main/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs ( Line number: 325)

To Define rule: https://github.com/microsoft/RulesEngine/blob/main/test/RulesEngine.UnitTest/TestData/rules4.json

Example: "ErrorMessage": "One or more adjust rules failed, with loyaltyFactor : $(model1.loyaltyFactor), country : $(model1.country), totalPurchasesToDate : $(model1.totalPurchasesToDate), model2 : $(model2)"

Upvotes: 1

Related Questions