예제 #1
0
        public void IsAllowed_InvalidDate_ReturnsFalse()
        {
            const int maxAllowed    = 2;
            const int windowSeconds = 1;

            var limiter = new LimiterAux(maxAllowed, windowSeconds);

            var totalExecuted = Convert.ToInt32(limiter.IsAllowed("not used", "not used", 0, "not used", "not used")); Console.WriteLine(limiter.WindowCount);

            Assert.AreEqual(1, totalExecuted);
            Assert.AreEqual(1, limiter.WindowCount);

            var oldWindowCount = limiter.WindowCount;

            totalExecuted  = Convert.ToInt32(limiter.IsAllowedAux(DateTime.Now.AddSeconds(-10))); Console.WriteLine(limiter.WindowCount);
            totalExecuted += Convert.ToInt32(limiter.IsAllowedAux(DateTime.Now.AddSeconds(-10))); Console.WriteLine(limiter.WindowCount);


            Assert.AreEqual(0, totalExecuted);
            Assert.AreEqual(oldWindowCount, limiter.WindowCount);
        }
예제 #2
0
        public void IsAllowed_NewWindow_CounterIsReset()
        {
            var       totalExecuted = 0;
            const int maxAllowed    = 2;
            const int windowSeconds = 1;

            var limiter = new LimiterAux(maxAllowed, windowSeconds);

            totalExecuted  = Convert.ToInt32(limiter.IsAllowed("not used", "not used", 0, "not used", "not used"));
            totalExecuted += Convert.ToInt32(limiter.IsAllowed("not used", "not used", 0, "not used", "not used"));
            totalExecuted += Convert.ToInt32(limiter.IsAllowed("not used", "not used", 0, "not used", "not used"));
            totalExecuted += Convert.ToInt32(limiter.IsAllowed("not used", "not used", 0, "not used", "not used"));
            totalExecuted += Convert.ToInt32(limiter.IsAllowed("not used", "not used", 0, "not used", "not used"));

            Assert.AreEqual(maxAllowed, totalExecuted);

            totalExecuted = Convert.ToInt32(limiter.IsAllowedAux(DateTime.Now.AddSeconds(10)));

            Assert.AreEqual(1, totalExecuted);
        }