public async Task When_no_exception_should_be_thrown_on_UI_thread_for_async_func_after_wait_time_and_none_was_it_should_not_throw() { // Arrange var waitTime = 6.Seconds(); var pollInterval = 10.Milliseconds(); var clock = new FakeClock(); var timer = clock.StartTimer(); clock.Delay(waitTime); Func <Task> throwShorterThanWaitTime = async() => { if (timer.Elapsed <= waitTime.Divide(12)) { throw new ArgumentException("An exception was forced"); } await Task.Yield(); }; // Act Func <Task> act = () => throwShorterThanWaitTime.Should(clock).NotThrowAfterAsync(waitTime, pollInterval); // Assert await act.Should().NotThrowAsync(); }
public async Task Sync_work_in_async_method_is_taken_into_account() { // Arrange var timer = new FakeClock(); var taskFactory = new TaskCompletionSource <bool>(); // Act Func <Task> action = () => taskFactory .Awaiting(t => { timer.Delay(101.Milliseconds()); return((Task)t.Task); }) .Should(timer) .CompleteWithinAsync(100.Milliseconds()); taskFactory.SetResult(true); timer.Complete(); // Assert await action.Should().ThrowAsync <XunitException>(); }