예제 #1
0
        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>();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        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*");
        }
예제 #7
0
        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*");
        }
예제 #8
0
        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>*");
        }
예제 #9
0
        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.");
        }
예제 #10
0
        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.");
        }