public async Task RunOnUIThreadAsync_should_run_on_the_UI_thread() { bool ranOnUIThread = false; bool ranOnBackgroundThread = false; bool ranAction = false; var dispatcher = new ThreadDispatcher( uiThreadInvoker: action => { ranOnUIThread = true; action(); return(Task.CompletedTask); }, backgroundThreadInvoker: action => { ranOnBackgroundThread = true; action(); return(Task.CompletedTask); }); await dispatcher.RunOnUIThreadAsync(() => ranAction = true); ranOnUIThread.Should().BeTrue(); ranOnBackgroundThread.Should().BeFalse(); ranAction.Should().BeTrue(); }