Пример #1
0
        public async Task TestStartStopCancelDispose()
        {
            var timePipeline            = new DelayPipeline();
            var cancellationTokenSource = new CancellationTokenSource();
            var token = cancellationTokenSource.Token;

            await Assert.ThrowsAsync <PipelineException>(() => timePipeline.StopAsync());

            var startTask       = timePipeline.RunAsync(token);
            var secondStartCall = timePipeline.RunAsync(token);

            Assert.Equal(startTask, secondStartCall);

            var stopSource     = new CancellationTokenSource();
            var stopTask       = timePipeline.StopAsync(stopSource.Token);
            var secondStopCall = timePipeline.StopAsync(stopSource.Token);

            Assert.Equal(stopTask, secondStopCall);

            stopSource.Cancel();

            await Assert.ThrowsAnyAsync <OperationCanceledException>(() => stopTask);

            cancellationTokenSource.Cancel();

            await Assert.ThrowsAnyAsync <OperationCanceledException>(() => startTask);

            await timePipeline.DisposeAsync();

            Assert.Equal(1, timePipeline.ExecutedCleanup);
        }
Пример #2
0
        public async Task TestStart()
        {
            var timePipeline = new DelayPipeline(TimeSpan.Zero);
            await timePipeline.RunAsync(CancellationToken.None);

            Assert.Equal(1, timePipeline.ExecutedCleanup);

            await timePipeline.DisposeAsync();

            Assert.Equal(1, timePipeline.ExecutedCleanup);
        }