Beispiel #1
0
        public void Rule_WithElseThenClauses_ElseThenClausesAreCallable()
        {
            var customer = new Customer ();
            var ruleEngineContext = new RuleEngineContext<Customer> ( customer );

            var rule = new Rule ( "Name" );

            Action<IRuleEngineContext> elseThenClause1 = e => ( ( Customer )e.Subject ).Age = 20;
            rule.AddElseThenClause ( elseThenClause1 );

            Action<IRuleEngineContext> elseThenClause2 = e => ( ( Customer )e.Subject ).Age++;
            rule.AddElseThenClause ( elseThenClause2 );

            foreach ( var clause in rule.ElseThenClauses )
            {
                clause ( ruleEngineContext );
            }

            Assert.AreEqual ( 21, customer.Age );
        }
Beispiel #2
0
        /// <inheritdoc/>
        public IRuleBuilder <TContext, TSubject> ElseThen(Action <TSubject> elseThenClause)
        {
            _rule.AddElseThenClause(ruleContext => elseThenClause(( TSubject )ruleContext.Subject));

            return(this);
        }