public void When_no_exception_should_be_thrown_after_wait_time_and_none_was_it_should_not_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var clock        = new FakeClock();
            var timer        = clock.StartTimer();
            var waitTime     = 100.Milliseconds();
            var pollInterval = 10.Milliseconds();

            Func <int> throwShorterThanWaitTime = () =>
            {
                if (timer.Elapsed <= waitTime.Divide(2))
                {
                    throw new ArgumentException("An exception was forced");
                }

                return(0);
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => throwShorterThanWaitTime.Should(clock).NotThrowAfter(waitTime, pollInterval);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.Should().NotThrow();
        }
        public void When_no_exception_should_be_thrown_after_wait_time_the_func_result_should_be_returned()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var clock        = new FakeClock();
            var timer        = clock.StartTimer();
            var waitTime     = 100.Milliseconds();
            var pollInterval = 10.Milliseconds();

            Func <int> throwShorterThanWaitTime = () =>
            {
                if (timer.Elapsed <= waitTime.Divide(2))
                {
                    throw new ArgumentException("An exception was forced");
                }

                return(42);
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            AndWhichConstraint <FunctionAssertions <int>, int> act =
                throwShorterThanWaitTime.Should(clock).NotThrowAfter(waitTime, pollInterval);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.Subject.Should().Be(42);
        }
        public void When_no_exception_should_be_thrown_after_wait_time_but_it_was_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var clock        = new FakeClock();
            var timer        = clock.StartTimer();
            var waitTime     = 100.Milliseconds();
            var pollInterval = 10.Milliseconds();

            Func <int> throwLongerThanWaitTime = () =>
            {
                if (timer.Elapsed <= waitTime.Multiply(1.5))
                {
                    throw new ArgumentException("An exception was forced");
                }

                return(0);
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                            throwLongerThanWaitTime.Should(clock).NotThrowAfter(waitTime, pollInterval, "we passed valid arguments");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.Should().Throw <XunitException>()
            .WithMessage("Did not expect any exceptions after 0.100s because we passed valid arguments*");
        }
        public async Task When_no_exception_should_be_thrown_async_on_UI_thread_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 <int> > throwShorterThanWaitTime = async() =>
            {
                if (timer.Elapsed <= waitTime.Divide(12))
                {
                    throw new ArgumentException("An exception was forced");
                }

                await Task.Yield();

                return(42);
            };

            // Act
            Func <Task> act = async() =>
            {
                (await throwShorterThanWaitTime.Should(clock).NotThrowAfterAsync(waitTime, pollInterval))
                .Which.Should().Be(42);
            };

            // Assert
            await act.Should().NotThrowAsync();
        }
        public async Task When_no_exception_should_be_thrown_async_on_UI_thread_after_wait_time_but_it_was_it_should_throw()
        {
            // Arrange
            var waitTime     = 2.Seconds();
            var pollInterval = 10.Milliseconds();

            var clock = new FakeClock();
            var timer = clock.StartTimer();

            clock.CompleteAfter(waitTime);

            Func <Task <int> > throwLongerThanWaitTime = async() =>
            {
                if (timer.Elapsed <= waitTime.Multiply(1.5))
                {
                    throw new ArgumentException("An exception was forced");
                }

                await Task.Yield();

                return(42);
            };

            // Act
            Func <Task> action = () => throwLongerThanWaitTime.Should(clock)
                                 .NotThrowAfterAsync(waitTime, pollInterval, "we passed valid arguments");

            // Assert
            await action.Should().ThrowAsync <XunitException>()
            .WithMessage("Did not expect any exceptions after 2s because we passed valid arguments*");
        }
        public void When_no_exception_should_be_thrown_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.Delay(0);
            };

            // Act
            Func <Task> act = () => throwShorterThanWaitTime.Should(clock).NotThrowAfterAsync(waitTime, pollInterval);

            // Assert
            act.Should().NotThrow();
        }
        When_no_exception_should_be_thrown_for_async_func_executed_with_wait_after_wait_time_but_it_was_it_should_throw()
        {
            // Arrange
            var waitTime     = 2.Seconds();
            var pollInterval = 10.Milliseconds();

            var clock = new FakeClock();
            var timer = clock.StartTimer();

            clock.Delay(waitTime);

            Func <Task> throwLongerThanWaitTime = async() =>
            {
                if (timer.Elapsed <= waitTime.Multiply(1.5))
                {
                    throw new ArgumentException("An exception was forced");
                }

                await Task.Delay(0);
            };

            // Act
            Action action = () => throwLongerThanWaitTime.Should(clock)
                            .NotThrowAfter(waitTime, pollInterval, "we passed valid arguments");

            // Assert
            action.Should().Throw <XunitException>()
            .WithMessage("Did not expect any exceptions after 2s because we passed valid arguments*");
        }