Esempio n. 1
0
        public void AllowMultipleDisposals()
        {
            var target = new CancellationSource();

            target.Dispose();

            Assert.DoesNotThrow(() => target.Dispose());
        }
Esempio n. 2
0
        public void IndicatesCancellationWhenImmediate()
        {
            using var target = new CancellationSource();
            Assert.False(target.IsCancellationRequested);

            target.RequestImmediateCancellation();

            Assert.True(target.IsCancellationRequested);
        }
Esempio n. 3
0
        public void IndicatesCancellationWhenAfterAPeriodOfTime()
        {
            using var target = new CancellationSource();
            Assert.False(target.IsCancellationRequested);

            target.RequestCancellationAfter(TimeSpan.FromSeconds(1));

            Thread.Sleep(TimeSpan.FromSeconds(2));

            Assert.True(target.IsCancellationRequested);
        }