public async Task When_subject_throws_the_expected_exact_exception_through_ValueTask_it_should_succeed() { // Arrange var asyncObject = new AsyncClass(); // Act / Assert await asyncObject .Awaiting(x => x.ThrowAsyncValueTask <ArgumentNullException>()) .Should().ThrowExactlyAsync <ArgumentNullException>(); }
public async Task When_ValueTask_async_method_of_T_succeeds_and_expected_not_to_throw_particular_exception_it_should_succeed() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(_ => asyncObject.ReturnValueTaskInt()) .Should().NotThrowAsync <InvalidOperationException>(); // Assert await action.Should().NotThrowAsync(); }
public async Task When_async_method_throws_exception_through_ValueTask_and_expected_not_to_throw_another_one_it_should_succeed() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowAsyncValueTask <ArgumentException>()) .Should().NotThrowAsync <InvalidOperationException>(); // Assert await action.Should().NotThrowAsync(); }
public async Task When_async_method_does_not_throw_exception_through_ValueTask_and_that_was_expected_it_should_succeed() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.SucceedAsyncValueTask()) .Should().NotThrowAsync(); // Assert await action.Should().NotThrowAsync(); }
public async Task When_async_method_throws_expected_exception_it_should_succeed() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowAsync <ArgumentException>()) .Should().ThrowAsync <ArgumentException>(); // Assert await action.Should().NotThrowAsync(); }
public async Task When_ValueTask_async_method_of_T_throws_exception_expected_not_to_be_thrown_it_should_fail() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowValueTaskIntAsync <ArgumentException>(true)) .Should().NotThrowAsync <ArgumentException>(); // Assert await action.Should().ThrowAsync <XunitException>() .WithMessage("Did not expect System.ArgumentException, but found System.ArgumentException*"); }
public async Task When_async_method_throws_exception_through_ValueTask_and_no_exception_was_expected_it_should_fail() { // Arrange var asyncObject = new AsyncClass(); // Act Func <Task> action = () => asyncObject .Awaiting(x => x.ThrowAsyncValueTask <ArgumentException>()) .Should().NotThrowAsync(); // Assert await action.Should().ThrowAsync <XunitException>() .WithMessage("Did not expect any exception, but found System.ArgumentException*"); }
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."); }