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

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

private ShutdownActionIsCalled ( ) : Task
Результат Task
        public async Task ShutdownActionIsCalled()
        {
            // Arrange
            bool didCallShutdown = false;
            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();

            // Act
            await timer.ExecuteAsync(ct =>
            {
                source.Cancel();
            }, source.Token, () => didCallShutdown=true);

            // Assert
            Assert.IsTrue(didCallShutdown);
        }
    }