1
+ using System ;
2
+ using System . Threading ;
3
+ using System . Threading . Tasks ;
4
+ using FluentAssertions ;
5
+ using NSubstitute ;
6
+ using Revo . Core . Commands . Lambda ;
7
+ using Revo . Core . Core ;
8
+ using Xunit ;
9
+
10
+ namespace Revo . Core . Tests . Commands . Lambda
11
+ {
12
+ public class LambdaQueryHandlerTests
13
+ {
14
+ private IServiceLocator serviceLocator ;
15
+ private IDummyService1 dummyService1 ;
16
+ private IDummyService2 dummyService2 ;
17
+ private LambdaQueryHandler sut ;
18
+
19
+ public LambdaQueryHandlerTests ( )
20
+ {
21
+ serviceLocator = Substitute . For < IServiceLocator > ( ) ;
22
+ sut = new LambdaQueryHandler ( serviceLocator ) ;
23
+
24
+ dummyService1 = Substitute . For < IDummyService1 > ( ) ;
25
+ serviceLocator . Get ( typeof ( IDummyService1 ) ) . Returns ( dummyService1 ) ;
26
+
27
+ dummyService2 = Substitute . For < IDummyService2 > ( ) ;
28
+ serviceLocator . Get ( typeof ( IDummyService2 ) ) . Returns ( dummyService2 ) ;
29
+ }
30
+
31
+ [ Fact ]
32
+ public async Task SendLambda_Query ( )
33
+ {
34
+ var lambda = Substitute . For < Func < int > > ( ) ;
35
+ lambda . Invoke ( ) . Returns ( 1 ) ;
36
+ var result = await sut . HandleAsync ( new LambdaQuery ( lambda , typeof ( int ) ) , CancellationToken . None ) ;
37
+ lambda . Received ( 1 ) . Invoke ( ) ;
38
+ result . Should ( ) . Be ( 1 ) ;
39
+ }
40
+
41
+ [ Fact ]
42
+ public async Task SendLambda_Query_Params1 ( )
43
+ {
44
+ var lambda = Substitute . For < Func < IDummyService1 , int > > ( ) ;
45
+ lambda . Invoke ( dummyService1 ) . Returns ( 1 ) ;
46
+ var result = await sut . HandleAsync ( new LambdaQuery ( lambda , typeof ( int ) ) , CancellationToken . None ) ;
47
+ result . Should ( ) . Be ( 1 ) ;
48
+ }
49
+
50
+ [ Fact ]
51
+ public async Task SendLambda_Query_Params2 ( )
52
+ {
53
+ var lambda = Substitute . For < Func < IDummyService1 , IDummyService2 , int > > ( ) ;
54
+ lambda . Invoke ( dummyService1 , dummyService2 ) . Returns ( 1 ) ;
55
+ var result = await sut . HandleAsync ( new LambdaQuery ( lambda , typeof ( int ) ) , CancellationToken . None ) ;
56
+ result . Should ( ) . Be ( 1 ) ;
57
+ }
58
+
59
+ [ Fact ]
60
+ public async Task SendLambda_Query_Task ( )
61
+ {
62
+ var lambda = Substitute . For < Func < Task < int > > > ( ) ;
63
+ lambda . Invoke ( ) . Returns ( 1 ) ;
64
+ var result = await sut . HandleAsync ( new LambdaQuery ( lambda , typeof ( int ) ) , CancellationToken . None ) ;
65
+ lambda . Received ( 1 ) . Invoke ( ) ;
66
+ result . Should ( ) . Be ( 1 ) ;
67
+ }
68
+
69
+ [ Fact ]
70
+ public async Task SendLambda_Query_Task_Params1 ( )
71
+ {
72
+ var lambda = Substitute . For < Func < IDummyService1 , Task < int > > > ( ) ;
73
+ lambda . Invoke ( dummyService1 ) . Returns ( 1 ) ;
74
+ var result = await sut . HandleAsync ( new LambdaQuery ( lambda , typeof ( int ) ) , CancellationToken . None ) ;
75
+ result . Should ( ) . Be ( 1 ) ;
76
+ }
77
+
78
+ [ Fact ]
79
+ public async Task SendLambda_Query_Task_Params2 ( )
80
+ {
81
+ var lambda = Substitute . For < Func < IDummyService1 , IDummyService2 , Task < int > > > ( ) ;
82
+ lambda . Invoke ( dummyService1 , dummyService2 ) . Returns ( 1 ) ;
83
+ var result = await sut . HandleAsync ( new LambdaQuery ( lambda , typeof ( int ) ) , CancellationToken . None ) ;
84
+ result . Should ( ) . Be ( 1 ) ;
85
+ }
86
+
87
+ public interface IDummyService1
88
+ {
89
+ }
90
+
91
+ public interface IDummyService2
92
+ {
93
+ }
94
+ }
95
+ }
0 commit comments