コード例 #1
0
        public async Task Start_should_run_the_action_only_once_when_the_delay_is_infinite()
        {
            int count = 0;
            await AsyncBackgroundTask.Start(
                ct =>
            {
                count++;
                return(Task.FromResult(true));
            },
                Timeout.InfiniteTimeSpan,
                CancellationToken.None);

            count.Should().Be(1);
        }
コード例 #2
0
        public async Task Start_should_run_the_action_on_the_specified_interval()
        {
            var cancellationTokenSource = new CancellationTokenSource();
            int count = 0;
            await AsyncBackgroundTask.Start(
                ct =>
            {
                count++;
                if (count == 5)
                {
                    cancellationTokenSource.Cancel();
                }
                return(Task.FromResult(true));
            },
                TimeSpan.FromMilliseconds(5),
                cancellationTokenSource.Token);

            count.Should().Be(5);
        }
コード例 #3
0
        public void Start_should_throw_ArgumentNullException_when_action_is_null()
        {
            Action act = () => AsyncBackgroundTask.Start(null, Timeout.InfiniteTimeSpan, CancellationToken.None).Wait();

            act.ShouldThrow <ArgumentNullException>();
        }