public void When_task_completes_fast_async_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var timer = new TestingTimer(); var taskFactory = new TaskCompletionSource <int>(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Func <Task> action = async() => { Func <Task <int> > func = () => taskFactory.Task; (await func.Should(timer).CompleteWithinAsync(100.Milliseconds())) .Which.Result.Should().Be(42); }; taskFactory.SetResult(42); timer.CompletesBeforeTimeout(); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.Should().NotThrow(); }
public void When_task_completes_fast_async_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var timer = new TestingTimer(); var taskFactory = new TaskCompletionSource <bool>(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Func <Task> action = () => taskFactory.Awaiting(t => t.Task).Should(timer).CompleteWithinAsync(100.Milliseconds()); taskFactory.SetResult(true); timer.CompletesBeforeTimeout(); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.Should().NotThrow(); }