public void When_task_completes_slow_async_it_should_fail()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var timer       = new TestingTimer();
            var taskFactory = new TaskCompletionSource <int>();

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Func <Task> action = () =>
            {
                Func <Task <int> > func = () => taskFactory.Task;

                return(func.Should(timer).CompleteWithinAsync(100.Milliseconds()));
            };

            timer.RunsIntoTimeout();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.Should().Throw <XunitException>();
        }
        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_slow_it_should_fail()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var timer       = new TestingTimer();
            var taskFactory = new TaskCompletionSource <bool>();

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => taskFactory.Awaiting(t => t.Task).Should(timer).CompleteWithin(100.Milliseconds());

            timer.RunsIntoTimeout();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.Should().Throw <XunitException>();
        }
        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();
        }