// <summary> // Adapts any action into a Task (returning AsyncVoid, so that it's usable with Task{T} extension methods). // </summary> static Task <AsyncVoid> ToAsyncVoidTask(Action action) { return(TaskHelpers.RunSynchronously(() => { action(); return DefaultCompleted; })); }
public void RunSynchronously_Executes_Action() { bool wasRun = false; Task t = TaskHelpers.RunSynchronously(() => { wasRun = true; }); t.WaitUntilCompleted(); Assert.True(wasRun); }
public void RunSynchronously_Cancels() { CancellationTokenSource cts = new CancellationTokenSource(); cts.Cancel(); Task t = TaskHelpers.RunSynchronously(() => { throw new InvalidOperationException(); }, cts.Token); Assert.Throws <TaskCanceledException>(() => t.Wait()); }
public void RunSynchronously_Captures_Exception_In_AggregateException() { Task t = TaskHelpers.RunSynchronously(() => { throw new InvalidOperationException(); }); Assert.Throws <InvalidOperationException>(() => t.Wait()); }