Exemple #1
0
        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*");
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        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*");
        }
Exemple #4
0
        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*");
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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();
        }
Exemple #7
0
 public Task ThrowAggregateExceptionAsync <TException>()
     where TException : Exception, new() =>
 Throw.Async(new AggregateException(new TException()));
Exemple #8
0
 public Task ThrowAsync(Exception exception) =>
 Throw.Async(exception);