1- #if ! NET_35 && ! SILVERLIGHT
21namespace Ninject . Extensions . Interception
32{
4- using System . Threading ;
53 using System . Threading . Tasks ;
64 using FluentAssertions ;
75 using Ninject . Extensions . Interception . Infrastructure . Language ;
@@ -10,24 +8,23 @@ namespace Ninject.Extensions.Interception
108 public abstract class AsyncInterceptionContext : InterceptionTestContext
119 {
1210 [ Fact ]
13- public void AsyncMethodsCanBeIntercepted ( )
11+ public async Task AsyncMethodsCanBeIntercepted ( )
1412 {
1513 using ( var kernel = this . CreateDefaultInterceptionKernel ( ) )
1614 {
1715 BeforeAfterCallOrderInterceptor . Reset ( ) ;
1816
1917 kernel . Bind < AsyncService > ( ) . ToSelf ( ) . Intercept ( ) . With < BeforeAfterCallOrderInterceptor > ( ) ;
20-
2118 var service = kernel . Get < AsyncService > ( ) ;
22- var task = service . DoAsync ( ) ;
23- task . Wait ( ) ;
19+
20+ await service . DoAsync ( ) ;
2421
2522 BeforeAfterCallOrderInterceptor . Order . Should ( ) . Be ( "Before_Action_AfterCompleted_" ) ;
26- }
23+ }
2724 }
2825
2926 [ Fact ]
30- public void AsyncMethodsWithReturnValueCanBeIntercepted ( )
27+ public async Task AsyncMethodsWithReturnValueCanBeIntercepted ( )
3128 {
3229 using ( var kernel = this . CreateDefaultInterceptionKernel ( ) )
3330 {
@@ -36,16 +33,15 @@ public void AsyncMethodsWithReturnValueCanBeIntercepted()
3633 kernel . Bind < AsyncService > ( ) . ToSelf ( ) . Intercept ( ) . With < BeforeAfterCallOrderInterceptor > ( ) ;
3734 var service = kernel . Get < AsyncService > ( ) ;
3835
39- var task = service . DoAsyncInt ( ) ;
40- task . Wait ( ) ;
41-
36+ var result = await service . DoAsyncInt ( ) ;
37+
4238 BeforeAfterCallOrderInterceptor . Order . Should ( ) . Be ( "Before_Action_AfterCompleted_" ) ;
43- task . Result . Should ( ) . Be ( 42 ) ;
39+ result . Should ( ) . Be ( 42 ) ;
4440 }
4541 }
4642
4743 [ Fact ]
48- public void AsyncMethodsWithReturnValue_InterceptorsCanChangeTheResult ( )
44+ public async Task AsyncMethodsWithReturnValue_InterceptorsCanChangeTheResult ( )
4945 {
5046 using ( var kernel = this . CreateDefaultInterceptionKernel ( ) )
5147 {
@@ -54,39 +50,13 @@ public void AsyncMethodsWithReturnValue_InterceptorsCanChangeTheResult()
5450 kernel . Bind < AsyncService > ( ) . ToSelf ( ) . Intercept ( ) . With < IncreaseResultInterceptor > ( ) ;
5551 var service = kernel . Get < AsyncService > ( ) ;
5652
57- var task = service . DoAsyncInt ( ) ;
58- task . Wait ( ) ;
53+ var result = await service . DoAsyncInt ( ) ;
5954
6055 BeforeAfterCallOrderInterceptor . Order . Should ( ) . Be ( "Before_Action_AfterCompleted_" ) ;
61- task . Result . Should ( ) . Be ( 43 ) ;
56+ result . Should ( ) . Be ( 43 ) ;
6257 }
6358 }
6459
65- #if NET_40
66- public class AsyncService
67- {
68- public virtual Task < int > DoAsyncInt ( )
69- {
70- BeforeAfterCallOrderInterceptor . ActionCalled ( ) ;
71- var result = new Task < int > (
72- ( ) =>
73- {
74- Thread . Sleep ( 100 ) ;
75- return 42 ;
76- } ) ;
77- result . Start ( ) ;
78- return result ;
79- }
80-
81- public virtual Task DoAsync ( )
82- {
83- BeforeAfterCallOrderInterceptor . ActionCalled ( ) ;
84- var result = new Task ( ( ) => Thread . Sleep ( 100 ) ) ;
85- result . Start ( ) ;
86- return result ;
87- }
88- }
89- #else
9060 public class AsyncService
9161 {
9262 public virtual async Task < int > DoAsyncInt ( )
@@ -112,7 +82,6 @@ private Task<int> DoInt()
11282 return Task . Delay ( 100 ) . ContinueWith ( ( t , o ) => 42 , null ) ;
11383 }
11484 }
115- #endif
11685
11786 public class BeforeAfterCallOrderInterceptor : AsyncInterceptor
11887 {
@@ -157,5 +126,4 @@ protected override void AfterInvoke(IInvocation invocation)
157126 }
158127 }
159128 }
160- }
161- #endif
129+ }
0 commit comments