public async Task IntervalAndActionIsTriggered()
{
// Arrange
Mock<IAsynchronousDelay> delay = new Mock<IAsynchronousDelay>();
Mock<ITimerThreadPoolExecuter> executer = new Mock<ITimerThreadPoolExecuter>();
executer.Setup(x => x.Run(It.IsAny<Action>(), It.IsAny<CancellationToken>())).Callback((Action a, CancellationToken c) =>
{
a();
}).Returns(Task.FromResult(0));
AsynchronousRegularTimer timer = new AsynchronousRegularTimer(executer.Object, delay.Object, TimeSpan.FromMilliseconds(PretendDelayInMilliseconds), false);
CancellationTokenSource source = new CancellationTokenSource();
int repeatCount = 0;
// Act
await timer.ExecuteAsync(ct =>
{
repeatCount++;
source.Cancel();
}, source.Token);
// Assert
Assert.AreEqual(1, repeatCount);
executer.Verify(x => x.Run(It.IsAny<Action>(), It.IsAny<CancellationToken>()));
delay.Verify(x => x.Delay(TimeSpan.FromMilliseconds(PretendDelayInMilliseconds), source.Token));
}