コード例 #1
0
        public void SimpleDelayLoopTest()
        {
            var counter   = 0;
            var scheduler = new TestScheduler();

            Task.Run(async() =>
            {
                while (true)
                {
                    await scheduler.Delay(TimeSpan.FromSeconds(2));
                    counter++;
                }
            });

            Thread.Sleep(100);
            scheduler.AdvanceBy(TimeSpan.FromSeconds(2.5));
            Thread.Sleep(100);
            scheduler.AdvanceBy(TimeSpan.FromSeconds(.1));
            Thread.Sleep(100);
            counter.ShouldBe(1);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(2));
            Thread.Sleep(100);
            counter.ShouldBe(2);
        }
コード例 #2
0
        public void SimpleDelayTest()
        {
            var testScheduler = new TestScheduler();
            var hasCompleted  = false;

            Task.Run(async() =>
            {
                await testScheduler.Delay(TimeSpan.FromHours(1));
                hasCompleted = true;
            });

            Thread.Sleep(100);

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(40));
            Thread.Sleep(100);
            hasCompleted.ShouldBeFalse();

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(40));
            Thread.Sleep(100);
            hasCompleted.ShouldBeTrue();
        }