コード例 #1
0
        public void ShouldGetVariousScopesAsStrings()
        {
            _valueGetter.Initialize(Scope.OriginalUrl);
            Assert.AreEqual(_request1.OriginalUrlString, _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.OriginalUrlString, _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.OriginalUrlString, _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.Url);
            Assert.AreEqual(_request1.NewUrlString, _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.NewUrlString, _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.NewUrlString, _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalPath);
            Assert.AreEqual(_request1.OriginalPathString, _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.OriginalPathString, _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.OriginalPathString, _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.Path);
            Assert.AreEqual(_request1.NewPathString, _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.NewPathString, _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.NewPathString, _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalQueryString);
            Assert.AreEqual(_request1.OriginalParametersString, _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.OriginalParametersString, _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.OriginalParametersString, _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.QueryString);
            Assert.AreEqual(_request1.NewParametersString, _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.NewParametersString, _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.NewParametersString, _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalPathElement, 1);
            Assert.AreEqual(_request1.OriginalPath[1], _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.OriginalPath[1], _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.OriginalPath[1], _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalPathElement, -1);
            Assert.AreEqual("path2", _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual("path2", _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual("path2", _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.PathElement, 1);
            Assert.AreEqual(_request1.NewPath[1], _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.NewPath[1], _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.NewPath[1], _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.PathElement, -1);
            Assert.AreEqual("path2", _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual("changed2", _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual("changed2", _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalParameter, "param");
            Assert.AreEqual("value", _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual("", _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual("", _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.Parameter, "param");
            Assert.AreEqual("changed", _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual("", _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual("added", _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.Header, "HOST");
            Assert.AreEqual(_request1.GetHeader("HOST"), _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.GetHeader("HOST"), _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.GetHeader("HOST"), _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalHeader, "USER_AGENT");
            Assert.AreEqual(_request1.GetOriginalHeader("USER_AGENT"), _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.GetOriginalHeader("USER_AGENT"), _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.GetOriginalHeader("USER_AGENT"), _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.ServerVariable, "URL");
            Assert.AreEqual(_request1.GetServerVariable("URL"), _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.GetServerVariable("URL"), _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.GetServerVariable("URL"), _valueGetter.GetString(_request3, _ruleResult));

            _valueGetter.Initialize(Scope.OriginalServerVariable, "SERVER_PORT");
            Assert.AreEqual(_request1.GetOriginalServerVariable("SERVER_PORT"), _valueGetter.GetString(_request1, _ruleResult));
            Assert.AreEqual(_request2.GetOriginalServerVariable("SERVER_PORT"), _valueGetter.GetString(_request2, _ruleResult));
            Assert.AreEqual(_request3.GetOriginalServerVariable("SERVER_PORT"), _valueGetter.GetString(_request3, _ruleResult));

            _ruleResult.Properties.Set <IList <string> >(new List <string> {
                "match0", "match1", "match2"
            }, "R");
            _ruleResult.Properties.Set <IList <string> >(new List <string> {
                "condition0", "condition1"
            }, "C");

            _valueGetter.Initialize(Scope.MatchGroup, "0");
            Assert.AreEqual("match0", _valueGetter.GetString(_request1, _ruleResult));

            _valueGetter.Initialize(Scope.MatchGroup, "1");
            Assert.AreEqual("match1", _valueGetter.GetString(_request1, _ruleResult));

            _valueGetter.Initialize(Scope.MatchGroup, "2");
            Assert.AreEqual("match2", _valueGetter.GetString(_request1, _ruleResult));

            _valueGetter.Initialize(Scope.ConditionGroup, "0");
            Assert.AreEqual("condition0", _valueGetter.GetString(_request1, _ruleResult));

            _valueGetter.Initialize(Scope.ConditionGroup, "1");
            Assert.AreEqual("condition1", _valueGetter.GetString(_request1, _ruleResult));

            _valueGetter.Initialize(Scope.ConditionGroup, "2");
            Assert.AreEqual("", _valueGetter.GetString(_request1, _ruleResult));
        }