Esempio n. 1
0
        public void Rule_WithWhenClause_WhenClauseIsCallable()
        {
            var customer = new Customer ();
            var ruleEngineContext = new RuleEngineContext<Customer> ( customer );
            Predicate<IRuleEngineContext> whenClause = e => string.IsNullOrWhiteSpace ( ( ( RuleEngineContext<Customer> )e ).Subject.FirstName );

            var rule = new Rule ( "Name" ) { WhenClause = whenClause };
            var isNullOrWhiteSpace = rule.WhenClause ( ruleEngineContext );

            Assert.IsTrue ( isNullOrWhiteSpace );
        }
Esempio n. 2
0
        public void When_WithAWhenFunction_AssignsWhenFunctionToRule()
        {
            var rule = new Rule ( "Rule1" );
            var ruleBuilder = new RuleBuilder<RuleEngineContext<Customer>, Customer> ( rule );
            ruleBuilder.When ( ( cust, ctxt ) => cust.Age < 20 );

            var customer = new Customer { Age = 10 };
            var context = new RuleEngineContext<Customer> ( customer );

            var lessThan20 = rule.WhenClause ( context );

            Assert.IsTrue ( lessThan20 );
        }
Esempio n. 3
0
        public void When_GivenAWhenPredicate_AssignsWhenPredicateToRule()
        {
            var rule = new Rule ( "Rule1" );
            var ruleBuilder = new RuleBuilder<RuleEngineContext<Customer>, Customer> ( rule );
            ruleBuilder.When ( c => c.Age < 20 );

            var customer = new Customer { Age = 10 };
            var context = new RuleEngineContext<Customer> ( customer );

            var lessThan20 = rule.WhenClause ( context );

            Assert.IsTrue ( lessThan20 );
        }