public bool Test(IRuleExecutionContext request, IRuleResult ruleResult) { return(_inverted ? !_testFunc(ruleResult, _valueGetter.GetInt(request, ruleResult, _defaultValue)) : _testFunc(ruleResult, _valueGetter.GetInt(request, ruleResult, _defaultValue))); }
public void ShouldGetVariousScopesAsNumbers() { var request = new MockRequestInfo( "/1/2?param1=3¶m2=4¶m1=5", "http", "www.test.com", 80); request.NewPath[1] = "6"; request.PathChanged(); request.NewParameters.Add("param3", new List <string> { "7" }); request.ParametersChanged(); _valueGetter.Initialize(Scope.OriginalPathElement, 1); Assert.AreEqual(1, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.OriginalPathElement, 2); Assert.AreEqual(2, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.PathElement, 1); Assert.AreEqual(6, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.PathElement, 2); Assert.AreEqual(2, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.PathElement, -1); Assert.AreEqual(2, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.PathElement, -2); Assert.AreEqual(6, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.OriginalParameter, "param1"); Assert.AreEqual(3, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.OriginalParameter, "param2"); Assert.AreEqual(4, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.OriginalParameter, "param3"); Assert.AreEqual(0, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.Parameter, "param1"); Assert.AreEqual(3, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.Parameter, "param2"); Assert.AreEqual(4, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.Parameter, "param3"); Assert.AreEqual(7, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.Parameter, "param4"); Assert.AreEqual(0, _valueGetter.GetInt(request, _ruleResult, 0)); _valueGetter.Initialize(Scope.ServerVariable, "SERVER_PORT"); Assert.AreEqual(80, _valueGetter.GetInt(request, _ruleResult, 0)); }