Ejemplo n.º 1
0
        public async Task ScheduleLongTaskWillCompensateTimeToZero()
        {
            // ARRANGE

            var mockTimeManager = new TimeManagerMock();

            await using (IScheduler scheduler = new Scheduler(mockTimeManager.Object))
            {
                // ACT
                var runTask = scheduler.RunEvery(20, async() =>
                {
                    await Task.Delay(50);
                });

                await Task.WhenAny(runTask.Task, Task.Delay(500));
            }
            // ASSERT
            mockTimeManager.Verify(n => n.Delay(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()), Times.Never);
        }
Ejemplo n.º 2
0
        public async Task ScheduleLongTaskWillCompensateTime()
        {
            // ARRANGE

            var mockTimeManager = new TimeManagerMock();

            await using (IScheduler scheduler = new Scheduler(mockTimeManager.Object))
            {
                // ACT
                var runTask = scheduler.RunEvery(20, async() =>
                {
                    await Task.Delay(1);
                });

                await Task.WhenAny(runTask.Task, Task.Delay(100));
            }

            // ASSERT
            // Make it less times due to slow cloud CI build engines (4->2)
            mockTimeManager.Verify(n => n.Delay(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>()), Times.AtLeast(2));
        }