public async Task Given_function_code_And_configured_to_run_in_ui_thread_When_Minimizing_And_task_is_cancelled_Then_should_throw() { Setup(); var config = new OptimizerConfiguration { Genes = new GeneConfiguration[0], Fitness = new FitnessConfiguration { OptimizerTypeName = Enums.OptimizerTypeOptions.Bayesian.ToString() } }; var source = new CancellationTokenSource(); source.Cancel(); await Assert.ThrowsAsync <TaskCanceledException>(() => _unit.Start(config, source.Token)); }