public void ParallelDelayedCancellation(IAsyncWorker worker, int workAmount, Type exceptionType) { var cts = new CancellationTokenSource(); cts.CancelAfter(100); Assert.That(async() => { await Task.Run(async() => await worker.WorkAsync(workAmount, cts.Token), cts.Token); }, CreateExceptionConstraint(exceptionType)); }
public void ParallelImmediateCancellation(IAsyncWorker worker) { var cts = new CancellationTokenSource(); cts.Cancel(); Assert.That(async() => { return(await Task.Factory.StartNew(async() => { await worker.WorkAsync(50, cts.Token); }, cts.Token, TaskCreationOptions.PreferFairness | TaskCreationOptions.HideScheduler, TaskScheduler.Default)); }, Throws.InstanceOf <TaskCanceledException>()); }