Ejemplo n.º 1
0
        public void LimitsBasedOnTimeBetweenCalls()
        {
            var currentTime  = new DateTime(2015, 10, 10, 13, 6, 0);
            var timeProvider = new ManualTimeProvider(currentTime, TimeZones.Utc);
            var data         = Enumerable.Range(0, 100).Select(x => new Tick {
                Symbol = CreateSymbol(x)
            }).GetEnumerator();
            var rateLimit = new RateLimitEnumerator <BaseData>(data, timeProvider, Time.OneSecond);

            Assert.IsTrue(rateLimit.MoveNext());

            while (rateLimit.MoveNext() && rateLimit.Current == null)
            {
                timeProvider.AdvanceSeconds(0.1);
            }

            var delta = (timeProvider.GetUtcNow() - currentTime).TotalSeconds;

            Assert.AreEqual(1, delta);

            Assert.AreEqual("1", data.Current.Symbol.Value);

            rateLimit.Dispose();
        }