File tree 2 files changed +34
-1
lines changed
tests/NSubstitute.Acceptance.Specs
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change
1
+ using System . Threading . Tasks ;
1
2
using NSubstitute . Routing ;
2
3
3
4
// Disable nullability for entry-point API
@@ -35,6 +36,15 @@ public void Do(Action<CallInfo> callbackWithArguments)
35
36
}
36
37
37
38
/// <summary>
39
+ /// Perform this action when called.
40
+ /// </summary>
41
+ /// <param name="callbackWithArguments"></param>
42
+ public void Do ( Func < CallInfo , Task > callbackWithArguments )
43
+ {
44
+ Do ( callInfo => callbackWithArguments ( callInfo ) . GetAwaiter ( ) . GetResult ( ) ) ;
45
+ }
46
+
47
+ /// <summary>
38
48
/// Perform this configured callback when called.
39
49
/// </summary>
40
50
/// <param name="callback"></param>
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Threading ;
3
+ using System . Threading . Tasks ;
1
4
using NSubstitute . Acceptance . Specs . Infrastructure ;
2
5
using NSubstitute . Core ;
3
6
using NUnit . Framework ;
@@ -9,11 +12,31 @@ public class WhenCalledDo
9
12
{
10
13
private ISomething _something ;
11
14
15
+
16
+ [ Test ]
17
+ public void Execute_when_called_async ( )
18
+ {
19
+ var called = false ;
20
+ _something . When ( substitute => substitute . Echo ( 1 ) ) . Do ( async info =>
21
+ {
22
+ await Task . Delay ( 100 ) ;
23
+ called = true ;
24
+ } ) ;
25
+
26
+ Assert . That ( called , Is . False , "Called" ) ;
27
+ _something . Echo ( 1 ) ;
28
+ Assert . That ( called , Is . True , "Called" ) ;
29
+ }
30
+
12
31
[ Test ]
13
32
public void Execute_when_called ( )
14
33
{
15
34
var called = false ;
16
- _something . When ( substitute => substitute . Echo ( 1 ) ) . Do ( info => called = true ) ;
35
+ _something . When ( substitute => substitute . Echo ( 1 ) ) . Do ( info =>
36
+ {
37
+ Thread . Sleep ( 100 ) ;
38
+ called = true ;
39
+ } ) ;
17
40
18
41
Assert . That ( called , Is . False , "Called" ) ;
19
42
_something . Echo ( 1 ) ;
You can’t perform that action at this time.
0 commit comments