Ejemplo n.º 1
0
        public void Chaining_Or()
        {
            var andChain = ChainHelper.AndChain(new Rule1_True(), new Rule2_False());
            var rule     = new RuleEval();

            rule.Eval(new Rule2_False());
            rule.AndChain(andChain);
            var rslt = rule.Evaluate(new RequestInfo());

            Assert.IsFalse(rslt);
        }
Ejemplo n.º 2
0
        public void Complex_Rule_Combination_And_Or()
        {
            var access_token = Guid.NewGuid().ToString();

            var req = new RequestInfo {
                Access_Token = access_token, Country = "EU"
            };
            var rule = new RuleEval();

            var usaRule = ChainHelper.AndChain(new RequestFromCountry("US"), new RequestPerElapsedTime(_ruleState, TimeSpan.FromSeconds(10), 1));
            var euRule  = ChainHelper.AndChain(new RequestFromCountry("EU"), new RequestElapsedTime(_ruleState, TimeSpan.FromSeconds(5)));

            rule.AndChain(usaRule);
            rule.OrChain(euRule);

            var rslt = rule.Evaluate(req);

            Assert.IsFalse(rslt);

            //Should match a rule EU and 2nd request inside elapsed time

            rslt = rule.Evaluate(req);
            Assert.IsTrue(rslt);


            // Request from US
            var us_access_token = Guid.NewGuid().ToString();

            var us_req = new RequestInfo {
                Access_Token = us_access_token, Country = "US"
            };

            rslt = rule.Evaluate(us_req);
            Assert.IsFalse(rslt);

            // 2nd request
            rslt = rule.Evaluate(us_req);
            Assert.IsTrue(rslt);
        }