[PreventExecutionContextLeaks] // Workaround for https://github.com/nunit/nunit/issues/3283 public static void Passed_synchronization_context_is_used_for_post([Values] PostOverload overload) { using (SynchronizationContextAssert.ExpectSinglePost(postedAction => { })) { var contextToUse = SynchronizationContext.Current !; using (SynchronizationContextAssert.ExpectNoPost()) { switch (overload) { case PostOverload.Action: AmbientTasks.Post(contextToUse, () => { }); break; case PostOverload.SendOrPostCallback: AmbientTasks.Post(contextToUse, state => { }, state: null); break; case PostOverload.AsyncAction: AmbientTasks.Post(contextToUse, () => Task.CompletedTask); break; default: throw new NotImplementedException(); } } } }
[PreventExecutionContextLeaks] // Workaround for https://github.com/nunit/nunit/issues/3283 public static void BeginContext_handler_is_not_executed_using_synchronization_context() { using (SynchronizationContextAssert.ExpectNoPost()) { AmbientTasks.BeginContext(ex => { }); AmbientTasks.Add(Task.FromException(new Exception())); using (Utils.WithTemporarySynchronizationContext(null)) { AmbientTasks.Add(Task.FromException(new Exception())); } } }