public async Task When_task_completes_on_UI_thread_slow_async_it_should_fail()
        {
            // Arrange
            var timer       = new FakeClock();
            var taskFactory = new TaskCompletionSource <bool>();

            // Act
            Func <Task> action = () => taskFactory.Awaiting(t => (Task)t.Task).Should(timer).CompleteWithinAsync(100.Milliseconds());

            timer.Complete();

            // Assert
            await action.Should().ThrowAsync <XunitException>();
        }
Exemple #2
0
        public async Task When_TCS_did_not_complete_in_time_it_should_fail()
        {
            // Arrange
            var subject = new TaskCompletionSource <bool>();
            var timer   = new FakeClock();

            // Act
            Func <Task> action = () => subject.Should(timer).CompleteWithinAsync(1.Seconds(), "test {0}", "testArg");

            timer.Complete();

            // Assert
            await action.Should().ThrowAsync <XunitException>()
            .WithMessage("Expected subject to complete within 1s because test testArg.");
        }
        public async Task When_task_completes_fast_async_it_should_succeed()
        {
            // Arrange
            var timer       = new FakeClock();
            var taskFactory = new TaskCompletionSource <bool>();

            // Act
            Func <Task> action = () => taskFactory.Awaiting(t => (Task)t.Task).Should(timer).CompleteWithinAsync(100.Milliseconds());

            taskFactory.SetResult(true);
            timer.Complete();

            // Assert
            await action.Should().NotThrowAsync();
        }
Exemple #4
0
        public async Task When_TCS_completes_in_time_and_result_is_expected_it_should_succeed()
        {
            // Arrange
            var subject = new TaskCompletionSource <int>();
            var timer   = new FakeClock();

            // Act
            Func <Task> action = async() => (await subject.Should(timer).CompleteWithinAsync(1.Seconds())).Which.Should().Be(42);

            subject.SetResult(42);
            timer.Complete();

            // Assert
            await action.Should().NotThrowAsync();
        }
Exemple #5
0
        public async Task When_TCS_completes_in_time_it_should_succeed()
        {
            // Arrange
            var subject = new TaskCompletionSource <bool>();
            var timer   = new FakeClock();

            // Act
            Func <Task> action = () => subject.Should(timer).CompleteWithinAsync(1.Seconds());

            subject.SetResult(true);
            timer.Complete();

            // Assert
            await action.Should().NotThrowAsync();
        }
Exemple #6
0
        public async Task When_TCS_completes_in_time_and_result_is_not_expected_it_should_fail()
        {
            // Arrange
            var subject = new TaskCompletionSource <int>();
            var timer   = new FakeClock();

            // Act
            Func <Task> action = async() => (await subject.Should(timer).CompleteWithinAsync(1.Seconds())).Which.Should().Be(42);

            subject.SetResult(99);
            timer.Complete();

            // Assert
            await action.Should().ThrowAsync <XunitException>()
            .WithMessage("Expected * to be 42, but found 99.");
        }
        public async Task When_task_completes_slow_async_it_should_fail()
        {
            // Arrange
            var timer       = new FakeClock();
            var taskFactory = new TaskCompletionSource <int>();

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

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

            timer.Complete();

            // Assert
            await action.Should().ThrowAsync <XunitException>();
        }
        public async Task When_task_does_not_throw_async_it_should_succeed()
        {
            // Arrange
            var timer       = new FakeClock();
            var taskFactory = new TaskCompletionSource <int>();

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

                (await func.Should(timer).NotThrowAsync())
                .Which.Should().Be(42);
            };

            taskFactory.SetResult(42);
            timer.Complete();

            // Assert
            await action.Should().NotThrowAsync();
        }