示例#1
0
        public void LimitProviderIntervalReject()
        {
            var limitProvider = new SlidingWindowWithInterval();

            var timeStamp = _dateTimeService.Timestamp;

            var evaluationContext = new EvaluationContext
            {
                RequestContext = new RequestContext
                {
                    ClientContext = new ClientContext {
                        Token = "test"
                    },
                    TimeStamp = _dateTimeService.Timestamp
                },
                RuleSet = new List <LimitRule>
                {
                    new LimitRule {
                        Threshold = 1, TimeSpan = 10
                    }                                             // a request per 10 seconds
                }
            };

            var visitContext = new VisitContext
            {
                Counter     = 1,
                LastAccess  = timeStamp - 5,
                WindowStart = timeStamp - 5
            };

            Assert.IsTrue(visitContext.Equals(limitProvider.Evaluate(evaluationContext, visitContext)));

            evaluationContext.RequestContext.TimeStamp += 6;
            visitContext = limitProvider.Evaluate(evaluationContext, visitContext);

            Assert.IsTrue(visitContext.LastAccess == evaluationContext.RequestContext.TimeStamp);
        }