/// <summary> /// Runs the specified function. /// </summary> /// <param name="func">The function.</param> public static void Run(Func <Task> func) { Argument.NotNull(func, nameof(func)); var previousContext = SynchronizationContext.Current; try { var context = new TestSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(context); var task = func(); task.ContinueWith(_ => context.queue.CompleteAdding(), TaskScheduler.Default); context.RunOnCurrentThread(); task.GetAwaiter().GetResult(); } finally { SynchronizationContext.SetSynchronizationContext(previousContext); } }
private static void InvokeTest(string name, Func <Task> test) => InvokeTest(name, () => TestSynchronizationContext.Run(test));