public void ShouldThrottle_WhenCalledAtEndOfRollingWindowAndAllows2PerSecond_WillReturnFalse()
{
SystemTime.SetCurrentTimeUtc = () => referenceTime;
var virtualNow = SystemTime.UtcNow;
var throttler = new RollingWindowThrottler(2, TimeSpan.FromSeconds(1));
long waitTimeMillis;
var shouldThrottle = throttler.ShouldThrottle(1, out waitTimeMillis);
shouldThrottle.ShouldBeFalse();
//first rolling window expired, init a new one
SystemTime.SetCurrentTimeUtc = () => virtualNow.AddSeconds(1.2);
shouldThrottle = throttler.ShouldThrottle(1, out waitTimeMillis);
shouldThrottle.ShouldBeFalse();
//inside second rolling window, under threshold
SystemTime.SetCurrentTimeUtc = () => virtualNow.AddSeconds(1.3);
shouldThrottle = throttler.ShouldThrottle(1, out waitTimeMillis);
shouldThrottle.ShouldBeFalse();
//second rolling window expired, beginning third window
SystemTime.SetCurrentTimeUtc = () => virtualNow.AddSeconds(2.2);
shouldThrottle = throttler.ShouldThrottle(1, out waitTimeMillis);
shouldThrottle.ShouldBeFalse();
//third window, under threshold
SystemTime.SetCurrentTimeUtc = () => virtualNow.AddSeconds(2.3);
shouldThrottle = throttler.ShouldThrottle(1, out waitTimeMillis);
shouldThrottle.ShouldBeFalse();
}