public async Task When_async_method_throws_exception_expected_through_ValueTask_not_to_be_thrown_it_should_fail() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowAsyncValueTask <ArgumentException>()) .Should().NotThrowAsync <ArgumentException>(); // Assert await action.Should().ThrowAsync <XunitException>() .WithMessage("Did not expect System.ArgumentException, but found*"); }
public async Task When_async_method_throws_unexpected_exception_through_ValueTask_it_should_fail() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowAsyncValueTask <ArgumentException>()) .Should().ThrowAsync <InvalidOperationException>("because {0} should do that", "IFoo.Do"); // Assert await action.Should().ThrowAsync <XunitException>() .WithMessage("Expected a <System.InvalidOperationException> to be thrown because IFoo.Do should do that, but found <System.ArgumentException>*"); }
public async Task When_async_method_does_not_throw_expected_exception_it_should_fail() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.SucceedAsync()) .Should().ThrowAsync <InvalidOperationException>("because {0} should do that", "IFoo.Do"); // Assert await action.Should().ThrowAsync <XunitException>() .WithMessage("Expected a <System.InvalidOperationException> to be thrown because IFoo.Do should do that, but no exception was thrown."); }
public async Task When_subject_throws_aggregate_exception_and_not_expected_exact_exception_through_ValueTask_it_should_fail() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowAggregateExceptionAsyncValueTask <ArgumentException>()) .Should().ThrowExactlyAsync <ArgumentException>("because {0} should do that", "IFoo.Do"); // Assert await action.Should().ThrowAsync <XunitException>() .WithMessage("Expected type to be System.ArgumentException because IFoo.Do should do that, but found System.AggregateException."); }
public async Task When_poll_interval_is_negative_for_async_func_it_should_throw() { // Arrange var waitTime = 10.Milliseconds(); var pollInterval = -1.Milliseconds(); var asyncObject = new AsyncClass(); Func <Task> someFunc = () => asyncObject.SucceedAsync(); // Act Func <Task> act = () => someFunc.Should().NotThrowAfterAsync(waitTime, pollInterval); // Assert await act.Should().ThrowAsync <ArgumentOutOfRangeException>() .WithMessage("* value of pollInterval must be non-negative*"); }
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(); }