public void Eval_OneRuleTest() { var rule = new RuleEval(); rule.Eval(new Rule2_False()); var rslt = rule.Evaluate(new RequestInfo()); Assert.IsFalse(rslt); }
public void AndRule_FalseAndFalse() { var rule = new RuleEval(); rule.Eval(new Rule2_False()); rule.AndRule(new Rule2_False()); var rslt = rule.Evaluate(new RequestInfo()); Assert.IsFalse(rslt); }
public void AndRule_TrueAndTrue() { var rule = new RuleEval(); rule.Eval(new Rule1_True()); rule.AndRule(new Rule1_True()); var rslt = rule.Evaluate(new RequestInfo()); Assert.IsTrue(rslt); }
public void OrRule_TrueAndFalse() { var rule = new RuleEval(); rule.Eval(new Rule1_True()); rule.OrRule(new Rule2_False()); var rslt = rule.Evaluate(new RequestInfo()); Assert.IsTrue(rslt); }
public void Chaining_And() { var orChain = ChainHelper.OrChain(new Rule1_True(), new Rule2_False()); var rule = new RuleEval(); rule.Eval(new Rule2_False()); rule.OrChain(orChain); var rslt = rule.Evaluate(new RequestInfo()); Assert.IsTrue(rslt); }
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); }
public static void ApplyInitialFlows(ProvisionRule rule, CSEntry csentry, MVEntry mventry) { if (rule.InitialFlows == null) { return; } foreach (var initialFlow in rule.InitialFlows) { RuleEval.Execute(initialFlow, mventry, csentry); } }
public void X_Request_Per_Timespan_First_Request() { var access_token = Guid.NewGuid().ToString(); var req = new RequestInfo { Access_Token = access_token }; var rule = new RuleEval(); rule.Eval(new RequestPerElapsedTime(_ruleState, TimeSpan.FromSeconds(10), 3)); var rslt = rule.Evaluate(req); Assert.IsFalse(rslt); }
public void Exceptions_Pathing() { var rule = new RuleEval(); rule.Eval(new Rule2_False()); //back to back evals cannot be called.. Assert.Throws <RateLimiterException>(() => rule.Eval(new Rule2_False())); var rule2 = new RuleEval(); // evaluate a rule without inputs Assert.Throws <RateLimiterException>(() => rule2.Evaluate(null)); var rule3 = new RuleEval(); // evaluate a rule without any rules inputted Assert.Throws <RateLimiterException>(() => rule3.Evaluate(new RequestInfo())); }
public void Combine_Rule_Country_US_And_X_Request_Per_Timespan_GreaterThanCnt_1_UK_Request() { var access_token = Guid.NewGuid().ToString(); var req = new RequestInfo { Access_Token = access_token, Country = "UK" }; var rule = new RuleEval(); rule.Eval(new RequestFromCountry("US")); rule.AndRule(new RequestPerElapsedTime(_ruleState, TimeSpan.FromSeconds(10), 1)); var rslt = rule.Evaluate(req); Assert.IsFalse(rslt); rslt = rule.Evaluate(req); Assert.IsFalse(rslt); }
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); }
public void Test_flowrule_from_file() { CSEntry entry = new MockCsentry(); entry["FirstName"].Value = "Espen"; entry["LastName"].Value = "Askeladd"; var loader = new FileFlowRuleRepo("Samples\\pyFlowRules.json"); List <FlowRule> rules = loader.GetAllRules(); Assert.IsTrue(rules.Any(rule => rule.Name == "UpperCaser")); var upperCaseRule = rules.FirstOrDefault(rule => rule.Name == "UpperCaser"); string uppercasedName = RuleEval.GetValue(upperCaseRule, entry); Assert.AreEqual("ESPEN ASKELADD", uppercasedName); var lowerCaseRule = rules.FirstOrDefault(rule => rule.Name == "LowerCaser"); string lowerCasedName = RuleEval.GetValue(lowerCaseRule, entry); Assert.AreEqual("espen askeladd", lowerCasedName); }