@@ -6,29 +6,41 @@ public sealed class AsyncActionAssertionsTests
66 public async Task ThrowAsync ( )
77 {
88 Func < Task > doesNotThrow = ( ) => Task . CompletedTask ;
9+ Func < Task > doesNotThrowAsync = async ( ) => await Task . Yield ( ) ;
910
1011 var exception = new InvalidOperationException ( "Test" ) ;
1112 Func < Task > throws = ( ) => throw exception ;
13+ Func < Task > throwsAsync = async ( ) => { await Task . Yield ( ) ; throw exception ; } ;
1214
1315 Func < Task > throwsWrongException = ( ) => throw new NotSupportedException ( "Wrong" ) ;
16+ Func < Task > throwsWrongExceptionAsync = async ( ) => { await Task . Yield ( ) ; throw new NotSupportedException ( "Wrong" ) ; } ;
1417
1518 await Assert . That ( ( ) => throws . Should ( ) . ThrowAsync < InvalidOperationException > ( ) ) . ThrowsNothing ( ) ;
19+ await Assert . That ( ( ) => throwsAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( ) ) . ThrowsNothing ( ) ;
1620
1721 await Assert . That ( ( ) => doesNotThrow . Should ( ) . ThrowAsync < InvalidOperationException > ( ) )
1822 . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException." ) ;
23+ await Assert . That ( ( ) => doesNotThrowAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( ) )
24+ . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException." ) ;
1925
2026 await Assert . That ( ( ) => throwsWrongException . Should ( ) . ThrowAsync < InvalidOperationException > ( ) )
2127 . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException but threw a NotSupportedException with message \" Wrong\" ." ) ;
28+ await Assert . That ( ( ) => throwsWrongExceptionAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( ) )
29+ . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException but threw a NotSupportedException with message \" Wrong\" ." ) ;
2230 }
2331
2432 [ Test ]
2533 public async Task ThrowAsync_Chain ( )
2634 {
2735 var exception = new InvalidOperationException ( "Test" ) ;
2836 Func < Task > throws = ( ) => throw exception ;
37+ Func < Task > throwsAsync = async ( ) => { await Task . Yield ( ) ; throw exception ; } ;
2938
3039 var chain = await throws . Should ( ) . ThrowAsync < InvalidOperationException > ( ) . ConfigureAwait ( false ) ;
40+ await Assert . That ( chain . Exception ) . IsSameReferenceAs ( exception ) ;
41+ await Assert . That ( chain . That ) . IsSameReferenceAs ( exception ) ;
3142
43+ chain = await throwsAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( ) . ConfigureAwait ( false ) ;
3244 await Assert . That ( chain . Exception ) . IsSameReferenceAs ( exception ) ;
3345 await Assert . That ( chain . That ) . IsSameReferenceAs ( exception ) ;
3446 }
@@ -37,32 +49,46 @@ public async Task ThrowAsync_Chain()
3749 public async Task ThrowAsync_String ( )
3850 {
3951 Func < Task > doesNotThrow = ( ) => Task . CompletedTask ;
52+ Func < Task > doesNotThrowAsync = async ( ) => await Task . Yield ( ) ;
4053
4154 var exception = new InvalidOperationException ( "Test" ) ;
4255 Func < Task > throws = ( ) => throw exception ;
56+ Func < Task > throwsAsync = async ( ) => { await Task . Yield ( ) ; throw exception ; } ;
4357
4458 Func < Task > throwsWrongException = ( ) => throw new NotSupportedException ( "Wrong" ) ;
59+ Func < Task > throwsWrongExceptionAsync = async ( ) => { await Task . Yield ( ) ; throw new NotSupportedException ( "Wrong" ) ; } ;
4560
4661 await Assert . That ( ( ) => throws . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) ) . ThrowsNothing ( ) ;
62+ await Assert . That ( ( ) => throwsAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) ) . ThrowsNothing ( ) ;
4763
4864 await Assert . That ( ( ) => throws . Should ( ) . ThrowAsync < InvalidOperationException > ( "Wrong Message" ) )
4965 . Throws < AssertionException > ( ) . WithMessage ( "Value should have Message \" Wrong Message\" but was \" Test\" ." ) ;
66+ await Assert . That ( ( ) => throwsAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( "Wrong Message" ) )
67+ . Throws < AssertionException > ( ) . WithMessage ( "Value should have Message \" Wrong Message\" but was \" Test\" ." ) ;
5068
5169 await Assert . That ( ( ) => doesNotThrow . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) )
5270 . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException." ) ;
71+ await Assert . That ( ( ) => doesNotThrowAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) )
72+ . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException." ) ;
5373
5474 await Assert . That ( ( ) => throwsWrongException . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) )
5575 . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException but threw a NotSupportedException with message \" Wrong\" ." ) ;
76+ await Assert . That ( ( ) => throwsWrongExceptionAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) )
77+ . Throws < AssertionException > ( ) . WithMessage ( "Function should throw an InvalidOperationException but threw a NotSupportedException with message \" Wrong\" ." ) ;
5678 }
5779
5880 [ Test ]
5981 public async Task ThrowAsync_String_Chain ( )
6082 {
6183 var exception = new InvalidOperationException ( "Test" ) ;
6284 Func < Task > throws = ( ) => throw exception ;
85+ Func < Task > throwsAsync = async ( ) => { await Task . Yield ( ) ; throw exception ; } ;
6386
6487 var chain = await throws . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) . ConfigureAwait ( false ) ;
88+ await Assert . That ( chain . Exception ) . IsSameReferenceAs ( exception ) ;
89+ await Assert . That ( chain . That ) . IsSameReferenceAs ( exception ) ;
6590
91+ chain = await throwsAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( "Test" ) . ConfigureAwait ( false ) ;
6692 await Assert . That ( chain . Exception ) . IsSameReferenceAs ( exception ) ;
6793 await Assert . That ( chain . That ) . IsSameReferenceAs ( exception ) ;
6894 }
@@ -71,38 +97,24 @@ public async Task ThrowAsync_String_Chain()
7197 public async Task NotThrowAsync ( )
7298 {
7399 Func < Task > doesNotThrow = ( ) => Task . CompletedTask ;
100+ Func < Task > doesNotThrowAsync = async ( ) => await Task . Yield ( ) ;
74101
75102 var exception = new InvalidOperationException ( "Test" ) ;
76103 Func < Task > throws = ( ) => throw exception ;
104+ Func < Task > throwsAsync = async ( ) => { await Task . Yield ( ) ; throw exception ; } ;
77105
78106 await Assert . That ( ( ) => doesNotThrow . Should ( ) . NotThrowAsync ( ) ) . ThrowsNothing ( ) ;
107+ await Assert . That ( ( ) => doesNotThrowAsync . Should ( ) . NotThrowAsync ( ) ) . ThrowsNothing ( ) ;
79108
80109 var actualException = await Assert . That ( ( ) => throws . Should ( ) . NotThrowAsync ( ) )
81110 . Throws < AssertionException > ( )
82111 . WithMessage ( "Function should not throw but threw an InvalidOperationException with message \" Test\" ." ) ;
83112 await Assert . That ( actualException ! . InnerException ) . IsSameReferenceAs ( exception ) ;
84- }
85-
86- [ Test ]
87- public async Task ThrowAsync_ActuallyAsync ( )
88- {
89- var exception = new InvalidOperationException ( "AsyncTest" ) ;
90- Func < Task > throwsAsync = async ( ) =>
91- {
92- await Task . Yield ( ) ;
93- throw exception ;
94- } ;
95-
96- var chain = await throwsAsync . Should ( ) . ThrowAsync < InvalidOperationException > ( "AsyncTest" ) . ConfigureAwait ( false ) ;
97- await Assert . That ( chain . Exception ) . IsSameReferenceAs ( exception ) ;
98- }
99113
100- [ Test ]
101- public async Task NotThrowAsync_ActuallyAsync ( )
102- {
103- Func < Task > doesNotThrow = async ( ) => await Task . Yield ( ) ;
104-
105- await Assert . That ( ( ) => doesNotThrow . Should ( ) . NotThrowAsync ( ) ) . ThrowsNothing ( ) ;
114+ actualException = await Assert . That ( ( ) => throwsAsync . Should ( ) . NotThrowAsync ( ) )
115+ . Throws < AssertionException > ( )
116+ . WithMessage ( "Function should not throw but threw an InvalidOperationException with message \" Test\" ." ) ;
117+ await Assert . That ( actualException ! . InnerException ) . IsSameReferenceAs ( exception ) ;
106118 }
107119
108120 [ Test ]
0 commit comments