public void AllowMultipleDisposals() { var target = new CancellationSource(); target.Dispose(); Assert.DoesNotThrow(() => target.Dispose()); }
public void IndicatesCancellationWhenImmediate() { using var target = new CancellationSource(); Assert.False(target.IsCancellationRequested); target.RequestImmediateCancellation(); Assert.True(target.IsCancellationRequested); }
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); }