public static void AsyncDelegatesAreExecutedOnStaThread(AsyncExecutionApiAdapter apiAdapter) { var thread = Thread.CurrentThread; apiAdapter.Execute(() => { Assert.That(Thread.CurrentThread, Is.SameAs(thread)); return(Task.FromResult <object>(null)); }); }
public static void ContinuationStaysOnStaThread(AsyncExecutionApiAdapter apiAdapter) { var thread = Thread.CurrentThread; apiAdapter.Execute(async() => { await Task.Yield(); Assert.That(Thread.CurrentThread, Is.SameAs(thread)); }); }
public static void ContinuationDoesNotDeadlockOnKnownSynchronizationContext( [ValueSource(nameof(KnownSynchronizationContextTypes))] Type knownSynchronizationContextType, [ValueSource(nameof(ApiAdapters))] AsyncExecutionApiAdapter apiAdapter) { var createdOnThisThread = CreateSynchronizationContext(knownSynchronizationContextType); using (TestUtils.TemporarySynchronizationContext(createdOnThisThread)) { apiAdapter.Execute(async() => await TaskEx.Yield()); } }
public static void ExecutesAsyncUserCode(AsyncExecutionApiAdapter adapter) { var didExecute = false; adapter.Execute(async() => { await Task.Yield(); didExecute = true; }); Assert.That(didExecute); }
public static void AwaitingContinuationDoesNotAlterSynchronizationContext( [ValueSource(nameof(KnownSynchronizationContextTypes))] Type knownSynchronizationContextType, [ValueSource(nameof(ApiAdapters))] AsyncExecutionApiAdapter apiAdapter) { var createdOnThisThread = CreateSynchronizationContext(knownSynchronizationContextType); using (TestUtils.TemporarySynchronizationContext(createdOnThisThread)) { apiAdapter.Execute(async() => await TaskEx.Yield()); Assert.That(SynchronizationContext.Current, Is.TypeOf(knownSynchronizationContextType)); } }
public static void AsyncDelegatesAreExecutedUnderTheCurrentSynchronizationContext( [ValueSource(nameof(KnownSynchronizationContextTypes))] Type knownSynchronizationContextType, [ValueSource(nameof(ApiAdapters))] AsyncExecutionApiAdapter apiAdapter) { var createdOnThisThread = CreateSynchronizationContext(knownSynchronizationContextType); using (TestUtils.TemporarySynchronizationContext(createdOnThisThread)) { apiAdapter.Execute(() => { Assert.That(SynchronizationContext.Current, Is.TypeOf(knownSynchronizationContextType)); return(TaskEx.FromResult <object>(null)); }); } }