1
1
using MediatR ;
2
2
3
- using Moq ;
3
+ using NSubstitute ;
4
4
5
5
using OpenMeteoRemoteApi . Interfaces ;
6
6
@@ -63,22 +63,20 @@ public async Task WaitingForLocationTests_SuccessRegister()
63
63
64
64
var userManageServiceSetupBehavior = ( ) =>
65
65
{
66
- var _userManageService = new Mock < IUserManageService > ( ) ;
67
- _userManageService . Setup (
68
- _ => _ . HandleAsync ( It . IsAny < GetUserQuery > ( ) , It . IsAny < CancellationToken > ( ) ) )
69
- . ReturnsAsync (
66
+ var _userManageService = Substitute . For < IUserManageService > ( ) ;
67
+ _userManageService . HandleAsync ( Arg . Any < GetUserQuery > ( ) , Arg . Any < CancellationToken > ( ) )
68
+ . Returns (
70
69
new Response < UserViewModel ? > ( )
71
70
{
72
71
Error = Core . Domain . Models . Enums . ErrorMessageType . NotFound
73
72
} ) ;
74
- _userManageService . Setup (
75
- _ => _ . HandleAsync ( It . IsAny < RegisterUserCommand > ( ) , It . IsAny < CancellationToken > ( ) ) )
76
- . ReturnsAsync (
73
+ _userManageService . HandleAsync ( Arg . Any < RegisterUserCommand > ( ) , Arg . Any < CancellationToken > ( ) )
74
+ . Returns (
77
75
new Response < Unit > ( )
78
76
{
79
77
Result = new Unit ( )
80
78
} ) ;
81
- return _userManageService . Object ;
79
+ return _userManageService ;
82
80
} ;
83
81
var requestedObjects = SetupRequestedObjects ( userManageServiceSetupBehavior , StateType . WaitingForLocation ) ;
84
82
var response = await requestedObjects . State . Handle ( requestedObjects . Context , _requestMessage ) ;
@@ -96,15 +94,14 @@ public async Task WaitingForLocationTests_FailRegisterWithError()
96
94
97
95
var userManageServiceSetupBehavior = ( ) =>
98
96
{
99
- var _userManageService = new Mock < IUserManageService > ( ) ;
100
- _userManageService . Setup (
101
- _ => _ . HandleAsync ( It . IsAny < GetUserQuery > ( ) , It . IsAny < CancellationToken > ( ) ) )
102
- . ReturnsAsync (
97
+ var _userManageService = Substitute . For < IUserManageService > ( ) ;
98
+ _userManageService . HandleAsync ( Arg . Any < GetUserQuery > ( ) , Arg . Any < CancellationToken > ( ) )
99
+ . Returns (
103
100
new Response < UserViewModel ? > ( )
104
101
{
105
102
Error = Core . Domain . Models . Enums . ErrorMessageType . InternalServerError
106
103
} ) ;
107
- return _userManageService . Object ;
104
+ return _userManageService ;
108
105
} ;
109
106
110
107
var requestedObjects = SetupRequestedObjects ( userManageServiceSetupBehavior , StateType . WaitingForLocation ) ;
@@ -122,15 +119,14 @@ public async Task WaitingForLocationTests_FailRegisterLocationIsNull()
122
119
123
120
var userManageServiceSetupBehavior = ( ) =>
124
121
{
125
- var _userManageService = new Mock < IUserManageService > ( ) ;
126
- _userManageService . Setup (
127
- _ => _ . HandleAsync ( It . IsAny < GetUserQuery > ( ) , It . IsAny < CancellationToken > ( ) ) )
128
- . ReturnsAsync (
122
+ var _userManageService = Substitute . For < IUserManageService > ( ) ;
123
+ _userManageService . HandleAsync ( Arg . Any < GetUserQuery > ( ) , Arg . Any < CancellationToken > ( ) )
124
+ . Returns (
129
125
new Response < UserViewModel ? > ( )
130
126
{
131
127
Error = Core . Domain . Models . Enums . ErrorMessageType . InternalServerError
132
128
} ) ;
133
- return _userManageService . Object ;
129
+ return _userManageService ;
134
130
} ;
135
131
136
132
var requestedObjects = SetupRequestedObjects ( userManageServiceSetupBehavior , StateType . WaitingForLocation ) ;
@@ -155,22 +151,20 @@ public async Task WaitingForLocationTests_UpdateIfUserExists()
155
151
156
152
var userManageServiceSetupBehavior = ( ) =>
157
153
{
158
- var _userManageService = new Mock < IUserManageService > ( ) ;
159
- _userManageService . Setup (
160
- _ => _ . HandleAsync ( It . IsAny < GetUserQuery > ( ) , It . IsAny < CancellationToken > ( ) ) )
161
- . ReturnsAsync (
154
+ var _userManageService = Substitute . For < IUserManageService > ( ) ;
155
+ _userManageService . HandleAsync ( Arg . Any < GetUserQuery > ( ) , Arg . Any < CancellationToken > ( ) )
156
+ . Returns (
162
157
new Response < UserViewModel ? > ( )
163
158
{
164
159
Result = new UserViewModel ( ) { Id = 1 }
165
160
} ) ;
166
- _userManageService . Setup (
167
- _ => _ . HandleAsync ( It . IsAny < UpdateUserCommand > ( ) , It . IsAny < CancellationToken > ( ) ) )
168
- . ReturnsAsync (
161
+ _userManageService . HandleAsync ( Arg . Any < UpdateUserCommand > ( ) , Arg . Any < CancellationToken > ( ) )
162
+ . Returns (
169
163
new Response < Unit > ( )
170
164
{
171
165
Result = new Unit ( )
172
166
} ) ;
173
- return _userManageService . Object ;
167
+ return _userManageService ;
174
168
} ;
175
169
176
170
var requestedObjects = SetupRequestedObjects ( userManageServiceSetupBehavior , StateType . WaitingForLocation ) ;
0 commit comments