13
13
using Nullinside . Api . Controllers ;
14
14
using Nullinside . Api . Model ;
15
15
using Nullinside . Api . Model . Ddl ;
16
+ using Nullinside . Api . Shared ;
16
17
using Nullinside . Api . Shared . Json ;
17
18
18
19
namespace Nullinside . Api . Tests . Nullinside . Api . Controllers ;
@@ -31,6 +32,11 @@ public class UserControllerTests : UnitTestBase {
31
32
/// </summary>
32
33
private Mock < ITwitchApiProxy > _twitchApi ;
33
34
35
+ /// <summary>
36
+ /// The web socket persister.
37
+ /// </summary>
38
+ private Mock < IWebSocketPersister > _webSocketPersister ;
39
+
34
40
/// <inheritdoc />
35
41
public override void Setup ( ) {
36
42
base . Setup ( ) ;
@@ -45,6 +51,7 @@ public override void Setup() {
45
51
. Build ( ) ;
46
52
47
53
_twitchApi = new Mock < ITwitchApiProxy > ( ) ;
54
+ _webSocketPersister = new Mock < IWebSocketPersister > ( ) ;
48
55
}
49
56
50
57
/// <summary>
@@ -61,7 +68,7 @@ public async Task PerformGoogleLoginExisting() {
61
68
await _db . SaveChangesAsync ( ) ;
62
69
63
70
// Make the call and ensure it's successful.
64
- var controller = new TestableUserController ( _configuration , _db ) ;
71
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
65
72
controller . Email = "hi" ;
66
73
RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
67
74
@@ -81,7 +88,7 @@ public async Task PerformGoogleLoginExisting() {
81
88
[ Test ]
82
89
public async Task PerformGoogleLoginNewUser ( ) {
83
90
// Make the call and ensure it's successful.
84
- var controller = new TestableUserController ( _configuration , _db ) ;
91
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
85
92
controller . Email = "hi" ;
86
93
RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
87
94
@@ -103,7 +110,7 @@ public async Task GoToErrorOnDbException() {
103
110
_db . Users = null ! ;
104
111
105
112
// Make the call and ensure it's successful.
106
- var controller = new TestableUserController ( _configuration , _db ) ;
113
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
107
114
controller . Email = "hi" ;
108
115
RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
109
116
@@ -117,7 +124,7 @@ public async Task GoToErrorOnDbException() {
117
124
[ Test ]
118
125
public async Task GoToErrorOnBadGmailResponse ( ) {
119
126
// Make the call and ensure it's successful.
120
- var controller = new TestableUserController ( _configuration , _db ) ;
127
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
121
128
controller . Email = null ;
122
129
RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
123
130
@@ -147,7 +154,7 @@ public async Task PerformTwitchLoginExisting() {
147
154
await _db . SaveChangesAsync ( ) ;
148
155
149
156
// Make the call and ensure it's successful.
150
- var controller = new TestableUserController ( _configuration , _db ) ;
157
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
151
158
RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
152
159
153
160
// We should have been redirected to the successful route.
@@ -174,7 +181,7 @@ public async Task PerformTwitchLoginNewUser() {
174
181
. Returns ( ( ) => Task . FromResult < string ? > ( "hi" ) ) ;
175
182
176
183
// Make the call and ensure it's successful.
177
- var controller = new TestableUserController ( _configuration , _db ) ;
184
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
178
185
RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
179
186
180
187
// We should have been redirected to the successful route.
@@ -197,7 +204,7 @@ public async Task PerformTwitchLoginBadTwitchResponse() {
197
204
. Returns ( ( ) => Task . FromResult < TwitchAccessToken ? > ( null ) ) ;
198
205
199
206
// Make the call and ensure it's successful.
200
- var controller = new TestableUserController ( _configuration , _db ) ;
207
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
201
208
RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
202
209
203
210
// We should have gone down the bad route
@@ -214,7 +221,7 @@ public async Task PerformTwitchLoginWithNoEmailAccount() {
214
221
. Returns ( ( ) => Task . FromResult < TwitchAccessToken ? > ( new TwitchAccessToken ( ) ) ) ;
215
222
216
223
// Make the call and ensure it's successful.
217
- var controller = new TestableUserController ( _configuration , _db ) ;
224
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
218
225
RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
219
226
220
227
// We should have gone down the bad route because no email was associated with the twitch account.
@@ -237,7 +244,7 @@ public async Task PerformTwitchLoginDbFailure() {
237
244
. Returns ( ( ) => Task . FromResult < string ? > ( "hi" ) ) ;
238
245
239
246
// Make the call and ensure it's successful.
240
- var controller = new TestableUserController ( _configuration , _db ) ;
247
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
241
248
RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
242
249
243
250
// We should have been redirected to the error route because of an exception in DB processing.
@@ -256,7 +263,7 @@ public void GetRoles() {
256
263
var identity = new ClaimsIdentity ( claims , "icecream" ) ;
257
264
258
265
// Make the call and ensure it's successful.
259
- var controller = new TestableUserController ( _configuration , _db ) ;
266
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
260
267
controller . ControllerContext = new ControllerContext ( ) ;
261
268
controller . ControllerContext . HttpContext = new DefaultHttpContext ( ) ;
262
269
controller . ControllerContext . HttpContext . User = new ClaimsPrincipal ( identity ) ;
@@ -279,7 +286,7 @@ public async Task ValidateTokenExists() {
279
286
await _db . SaveChangesAsync ( ) ;
280
287
281
288
// Make the call and ensure it's successful.
282
- var controller = new TestableUserController ( _configuration , _db ) ;
289
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
283
290
IActionResult obj = await controller . Validate ( new AuthToken ( "123" ) ) ;
284
291
Assert . That ( ( obj as IStatusCodeActionResult ) ? . StatusCode , Is . EqualTo ( 200 ) ) ;
285
292
@@ -293,7 +300,7 @@ public async Task ValidateTokenExists() {
293
300
[ Test ]
294
301
public async Task ValidateFailWithoutToken ( ) {
295
302
// Make the call and ensure it fails.
296
- var controller = new TestableUserController ( _configuration , _db ) ;
303
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
297
304
IActionResult obj = await controller . Validate ( new AuthToken ( "123" ) ) ;
298
305
Assert . That ( ( obj as IStatusCodeActionResult ) ? . StatusCode , Is . EqualTo ( 401 ) ) ;
299
306
}
@@ -306,7 +313,7 @@ public async Task ValidateFailOnDbFailure() {
306
313
_db . Users = null ! ;
307
314
308
315
// Make the call and ensure it fails.
309
- var controller = new TestableUserController ( _configuration , _db ) ;
316
+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
310
317
IActionResult obj = await controller . Validate ( new AuthToken ( "123" ) ) ;
311
318
Assert . That ( ( obj as IStatusCodeActionResult ) ? . StatusCode , Is . EqualTo ( 500 ) ) ;
312
319
}
@@ -317,7 +324,7 @@ public async Task ValidateFailOnDbFailure() {
317
324
/// </summary>
318
325
public class TestableUserController : UserController {
319
326
/// <inheritdoc />
320
- public TestableUserController ( IConfiguration configuration , INullinsideContext dbContext ) : base ( configuration , dbContext ) {
327
+ public TestableUserController ( IConfiguration configuration , INullinsideContext dbContext , IWebSocketPersister webSocketPersister ) : base ( configuration , dbContext , webSocketPersister ) {
321
328
}
322
329
323
330
/// <summary>
0 commit comments