public async Task ExecuteRule_RuleWithMemberAccessExpression_ReturnsSucess(string ruleFileName)
        {
            var re = GetRulesEngine(ruleFileName);

            dynamic input1 = new ExpandoObject();
            input1.Boolean = false;

            var utils = new TestInstanceUtils();

            List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new RuleParameter("input1", input1));
            Assert.NotNull(result);
            Assert.IsType<List<RuleResultTree>>(result);
            Assert.All(result, c => Assert.False(c.IsSuccess));
        }
        public async Task ExecuteRule_MissingMethodInExpression_DefaultParameter(string ruleFileName)
        {
            var re = GetRulesEngine(ruleFileName);

            dynamic input1 = new ExpandoObject();
            input1.Data = new { TestProperty = "" };
            input1.Boolean = false;

            var utils = new TestInstanceUtils();

            List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new RuleParameter("input1", input1));
            Assert.NotNull(result);
            Assert.IsType<List<RuleResultTree>>(result);
            Assert.All(result, c => Assert.False(c.IsSuccess));
        }
        public async Task ExecuteRule_MissingMethodInExpression_ReturnsException(string ruleFileName)
        {
            var re = GetRulesEngine(ruleFileName, new ReSettings() { EnableExceptionAsErrorMessage = false });

            dynamic input1 = new ExpandoObject();
            input1.Data = new { TestProperty = "" };
            input1.Boolean = false;

            var utils = new TestInstanceUtils();

            await Assert.ThrowsAsync<System.Linq.Dynamic.Core.Exceptions.ParseException>(async()=>
            {
                List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new RuleParameter("input1", input1));
            });
        }
Example #4
0
        public async Task ExecuteRuleWithIgnoreException_CompilationException_DoesNotReturnsAsErrorMessage(string ruleFileName)
        {
            var re = GetRulesEngine(ruleFileName, new ReSettings()
            {
                EnableExceptionAsErrorMessage = true, IgnoreException = true
            });

            dynamic input1 = new ExpandoObject();

            input1.Data    = new { TestProperty = "" };
            input1.Boolean = false;

            var utils  = new TestInstanceUtils();
            var result = await re.ExecuteAllRulesAsync("inputWorkflow", new RuleParameter("input1", input1));

            Assert.NotNull(result);
            Assert.False(result[1].ExceptionMessage.StartsWith("Exception while parsing expression"));
        }
        public async Task ExecuteRule_RuleWithMethodExpression_ReturnsSucess(string ruleFileName)
        {
            var re = GetRulesEngine(ruleFileName);

            Func<bool> func = () => true;

            dynamic input1 = new ExpandoObject();
            input1.Property1 = "hello";
            input1.Boolean = false;
            input1.Method = func;

            var utils = new TestInstanceUtils();

            List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new RuleParameter("input1", input1));
            Assert.NotNull(result);
            Assert.IsType<List<RuleResultTree>>(result);
            Assert.All(result, c => Assert.True(c.IsSuccess));
        }
        public async Task ExecuteRule_WithInjectedUtils_ReturnsListOfRuleResultTree(string ruleFileName,string propValue,bool expectedResult)
        {
            var re = GetRulesEngine(ruleFileName);

            dynamic input1 = new ExpandoObject();
            if(propValue != null)
            input1.Property1 = propValue;

            if(propValue == null)
            input1.Property1 = null;

            var utils = new TestInstanceUtils();

            List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new RuleParameter("input1",input1),new RuleParameter("utils",utils));
            Assert.NotNull(result);
            Assert.IsType<List<RuleResultTree>>(result);
            Assert.All(result,c => Assert.Equal(expectedResult,c.IsSuccess));
        }