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>(); }
public void When_task_completes_slow_it_should_fail() { // Arrange var timer = new FakeClock(); var taskFactory = new TaskCompletionSource <bool>(); // Act Action action = () => taskFactory.Awaiting(t => (Task)t.Task).Should(timer).CompleteWithin(100.Milliseconds()); timer.RunsIntoTimeout(); // Assert action.Should().Throw <XunitException>(); }
public async Task When_subject_is_null_when_expecting_to_complete_async_it_should_throw() { // Arrange var timer = new FakeClock(); var timeSpan = 0.Milliseconds(); Func <Task> action = null; // Act Func <Task> testAction = () => action.Should().CompleteWithinAsync( timeSpan, "because we want to test the failure {0}", "message"); // Assert await testAction.Should().ThrowAsync <XunitException>() .WithMessage("*because we want to test the failure message*found <null>*"); }
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(); }
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_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(); }
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(); }
public void When_task_completes_fast_it_should_succeed() { // Arrange var timer = new FakeClock(); var taskFactory = new TaskCompletionSource <bool>(); // Act Action action = () => taskFactory.Awaiting(t => (Task)t.Task).Should(timer).CompleteWithin(100.Milliseconds()); taskFactory.SetResult(true); timer.CompletesBeforeTimeout(); // Assert action.Should().NotThrow(); }
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_throws_async_on_UI_thread_it_should_fail() { // Arrange var timer = new FakeClock(); // Act Func <Task> action = () => { Func <Task <int> > func = () => throw new AggregateException(); return(func.Should(timer).NotThrowAsync()); }; // Assert await action.Should().ThrowAsync <XunitException>(); }
public async Task When_poll_interval_is_zero_for_async_func_executed_with_wait_it_should_not_throw() { // Arrange var waitTime = 10.Milliseconds(); var pollInterval = 0.Milliseconds(); var clock = new FakeClock(); var asyncObject = new AsyncClass(); Func <Task> someFunc = () => asyncObject.SucceedAsync(); // Act Func <Task> act = () => someFunc.Should(clock).NotThrowAfterAsync(waitTime, pollInterval); // Assert await act.Should().NotThrowAsync(); }
public void When_task_completes_slow_it_should_fail() { // Arrange var timer = new FakeClock(); var taskFactory = new TaskCompletionSource <int>(); // Act Action action = () => { Func <Task <int> > func = () => taskFactory.Task; func.Should(timer).CompleteWithin(100.Milliseconds()); }; timer.RunsIntoTimeout(); // Assert action.Should().Throw <XunitException>(); }
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 void When_subject_it_null_when_expecting_to_complete_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var timer = new FakeClock(); var timeSpan = 0.Milliseconds(); Func <Task <int> > action = null; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action testAction = () => action.Should().CompleteWithin( timeSpan, "because we want to test the failure {0}", "message"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- testAction.Should().Throw <XunitException>() .WithMessage("*because we want to test the failure message*found <null>*"); }
public void When_task_completes_fast_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).CompleteWithinAsync(100.Milliseconds())) .Which.Should().Be(42); }; taskFactory.SetResult(42); timer.CompletesBeforeTimeout(); // Assert action.Should().NotThrow(); }
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(); }
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(); Action throwShorterThanWaitTime = () => { if (timer.Elapsed <= waitTime.Divide(2)) { throw new ArgumentException("An exception was forced"); } }; // Act Action act = () => throwShorterThanWaitTime.Should(clock).NotThrowAfter(waitTime, pollInterval); // Assert act.Should().NotThrow(); }