public async Task When_async_method_does_not_throw_the_expected_exception_it_should_fail() { // Arrange Func <Task> task = () => Throw.Async <ArgumentException>(); // Act Func <Task> action = () => task .Should().ThrowAsync <InvalidOperationException>(); // Assert await action.Should().ThrowAsync <XunitException>().WithMessage("*InvalidOperation*Argument*"); }
public async Task When_async_method_throws_the_expected_exception_it_should_succeed() { // Arrange Func <Task> task = () => Throw.Async <InvalidOperationException>(); // Act Func <Task> action = () => task .Should().ThrowAsync <InvalidOperationException>(); // Assert await action.Should().NotThrowAsync(); }
When_async_method_does_not_throw_the_expected_inner_exception_exactly_defined_in_arguments_it_should_fail() { // Arrange Func <Task> task = () => Throw.Async(new AggregateException(new ArgumentNullException())); // Act Func <Task> action = () => task .Should().ThrowAsync <AggregateException>() .WithInnerExceptionExactly(typeof(ArgumentException)); // Assert await action.Should().ThrowAsync <XunitException>().WithMessage("*ArgumentException*ArgumentNullException*"); }
public async Task When_async_method_does_not_throw_the_expected_inner_exception_from_argument_it_should_fail() { // Arrange Func <Task> task = () => Throw.Async(new AggregateException(new ArgumentException())); // Act Func <Task> action = () => task .Should().ThrowAsync <AggregateException>() .WithInnerException(typeof(InvalidOperationException)); // Assert await action.Should().ThrowAsync <XunitException>().WithMessage("*InvalidOperation*Argument*"); }
public async Task When_async_method_throws_the_expected_inner_exception_exactly_defined_in_arguments_it_should_succeed() { // Arrange Func <Task> task = () => Throw.Async(new AggregateException(new ArgumentException())); // Act Func <Task> action = () => task .Should().ThrowAsync <AggregateException>() .WithInnerExceptionExactly(typeof(ArgumentException)); // Assert await action.Should().NotThrowAsync(); }
public async Task When_async_method_throws_the_expected_inner_exception_it_should_succeed() { // Arrange Func <Task> task = () => Throw.Async(new AggregateException(new InvalidOperationException())); // Act Func <Task> action = () => task .Should().ThrowAsync <AggregateException>() .WithInnerException <AggregateException, InvalidOperationException>(); // Assert await action.Should().NotThrowAsync(); }
public Task ThrowAggregateExceptionAsync <TException>() where TException : Exception, new() => Throw.Async(new AggregateException(new TException()));
public Task ThrowAsync(Exception exception) => Throw.Async(exception);