AccidentalFish.ApplicationSupport.Core.Tests.Unit.Policies.Implementation.AsynchronousIntervalTimerTests.IntervalOccursBetweenTasksWithCancellationToken C# (CSharp) Метод

IntervalOccursBetweenTasksWithCancellationToken() приватный Метод

private IntervalOccursBetweenTasksWithCancellationToken ( ) : Task
Результат Task
        public async Task IntervalOccursBetweenTasksWithCancellationToken()
        {
            // Arrange
            Mock<IAsynchronousDelay> delay = new Mock<IAsynchronousDelay>();
            AsynchronousIntervalTimer timer = new AsynchronousIntervalTimer(delay.Object, TimeSpan.FromMilliseconds(PretendDelayInMilliseconds), false);
            CancellationTokenSource source = new CancellationTokenSource();
            int repeatCount = 0;
           
            // Act
            await timer.ExecuteAsync(ct =>
            { 
                repeatCount++;
                return Task.FromResult(repeatCount < 2);
            }, source.Token);
            
            // Assert
            Assert.AreEqual(2, repeatCount);
            delay.Verify(x => x.Delay(TimeSpan.FromMilliseconds(PretendDelayInMilliseconds), source.Token));
            source.Dispose();
        }