예제 #1
0
 private void Call(Limiter limiter, DateTime time, TimeSpan?expectedWaitTime)
 {
     TimeProvider.Instance = new StaticTimeProvider(time);
     delay.ResetCalls();
     if (expectedWaitTime == null)
     {
         delay.Setup(delay => delay(It.IsAny <TimeSpan>()));
     }
     else
     {
         delay.Setup(delay => delay(It.Is <TimeSpan>(waitTime => waitTime == expectedWaitTime.Value)))
         .Returns <TimeSpan>(x =>
         {
             var b = new StaticTimeProvider(TimeProvider.UtcNow + x);
             TimeProvider.Instance = b;
             return(Task.Delay(0));
         });
     }
     limiter.DoAsync(Do).Wait();
     delay.Verify();
     if (expectedWaitTime == null)
     {
         Assert.Equal(time, TimeProvider.UtcNow);
     }
     else
     {
         Assert.Equal(time + expectedWaitTime, TimeProvider.UtcNow);
     }
 }
예제 #2
0
        public async Task FirstCallIsPerformed()
        {
            TimeProvider.Instance = new StaticTimeProvider(new DateTime(2018, 6, 20, 1, 32, 14));
            var value = limiter.DoAsync(Do);

            Assert.True(value.IsCompleted);
        }