public void BuildExpressionForRuleTest()
        {
            var objBuilderFactory = new RuleExpressionBuilderFactory(new ReSettings());
            var builder           = objBuilderFactory.RuleGetExpressionBuilder(RuleExpressionType.LambdaExpression);

            var parameterExpressions = new List <ParameterExpression>();

            parameterExpressions.Add(Expression.Parameter(typeof(string), "RequestType"));
            parameterExpressions.Add(Expression.Parameter(typeof(string), "RequestStatus"));
            parameterExpressions.Add(Expression.Parameter(typeof(string), "RegistrationStatus"));

            Rule mainRule = new Rule();

            mainRule.RuleName = "rule1";
            mainRule.Operator = "And";
            mainRule.Rules    = new List <Rule>();

            Rule dummyRule = new Rule();

            dummyRule.RuleName           = "testRule1";
            dummyRule.RuleExpressionType = RuleExpressionType.LambdaExpression;
            dummyRule.Expression         = "RequestType == \"vod\"";

            mainRule.Rules.Add(dummyRule);
            var func = builder.BuildExpressionForRule(dummyRule, parameterExpressions);

            Assert.NotNull(func);
            Assert.Equal(typeof(RuleResultTree), func.Method.ReturnType);
        }
Пример #2
0
        public void BuildExpressionForRuleTest()
        {
            var reSettings        = new ReSettings();
            var objBuilderFactory = new RuleExpressionBuilderFactory(reSettings, new RuleExpressionParser(reSettings));
            var builder           = objBuilderFactory.RuleGetExpressionBuilder(RuleExpressionType.LambdaExpression);

            var ruleParameters = new RuleParameter[] {
                new RuleParameter("RequestType", "Sales"),
                new RuleParameter("RequestStatus", "Active"),
                new RuleParameter("RegistrationStatus", "InProcess")
            };


            Rule mainRule = new Rule();

            mainRule.RuleName = "rule1";
            mainRule.Operator = "And";
            mainRule.Rules    = new List <Rule>();

            Rule dummyRule = new Rule();

            dummyRule.RuleName           = "testRule1";
            dummyRule.RuleExpressionType = RuleExpressionType.LambdaExpression;
            dummyRule.Expression         = "RequestType == \"vod\"";

            mainRule.Rules.Add(dummyRule);
            var func = builder.BuildDelegateForRule(dummyRule, ruleParameters);

            Assert.NotNull(func);
            Assert.Equal(typeof(RuleResultTree), func.Method.ReturnType);
        }
        public void RuleGetExpressionBuilderTest(RuleExpressionType expressionType, Type expectedExpressionBuilderType)
        {
            var objBuilderFactory = new RuleExpressionBuilderFactory(new ReSettings());
            var builder           = objBuilderFactory.RuleGetExpressionBuilder(expressionType);

            var builderType = builder.GetType();

            Assert.Equal(expectedExpressionBuilderType.ToString(), builderType.ToString());
        }