Stumps.Stump.IsMatch C# (CSharp) Метод

IsMatch() публичный Метод

Determines whether the context of the HTTP request is match for the current instance.
public IsMatch ( IStumpsHttpContext context ) : bool
context IStumpsHttpContext The HTTP request.
Результат bool
        public bool IsMatch(IStumpsHttpContext context)
        {
            if (context == null || _response == null || _ruleList.Count == 0)
            {
                return false;
            }

            var match = true;

            foreach (var rule in _ruleList)
            {
                match &= rule.IsMatch(context.Request);

                if (!match)
                {
                    break;
                }
            }

            return match;
        }

Usage Example

Пример #1
0
        public void IsMatch_WithFailingRule_TriesAllRulesReturnsFalse()
        {
            var stump = new Stump("ABC");

            var context = Substitute.For <IStumpsHttpContext>();
            var request = Substitute.For <IStumpsHttpRequest>();

            context.Request.Returns(request);

            var rule1 = Substitute.For <IStumpRule>();

            rule1.IsMatch(request).Returns(true);

            var rule2 = Substitute.For <IStumpRule>();

            rule2.IsMatch(request).Returns(false);

            stump.AddRule(rule1);
            stump.AddRule(rule2);

            stump.Responds();

            var matches = stump.IsMatch(context);

            rule1.Received(1).IsMatch(request);
            rule2.Received(1).IsMatch(request);
            Assert.IsFalse(matches);
        }
All Usage Examples Of Stumps.Stump::IsMatch