1313using Nullinside . Api . Controllers ;
1414using Nullinside . Api . Model ;
1515using Nullinside . Api . Model . Ddl ;
16+ using Nullinside . Api . Shared ;
1617using Nullinside . Api . Shared . Json ;
1718
1819namespace Nullinside . Api . Tests . Nullinside . Api . Controllers ;
@@ -31,6 +32,11 @@ public class UserControllerTests : UnitTestBase {
3132 /// </summary>
3233 private Mock < ITwitchApiProxy > _twitchApi ;
3334
35+ /// <summary>
36+ /// The web socket persister.
37+ /// </summary>
38+ private Mock < IWebSocketPersister > _webSocketPersister ;
39+
3440 /// <inheritdoc />
3541 public override void Setup ( ) {
3642 base . Setup ( ) ;
@@ -45,6 +51,7 @@ public override void Setup() {
4551 . Build ( ) ;
4652
4753 _twitchApi = new Mock < ITwitchApiProxy > ( ) ;
54+ _webSocketPersister = new Mock < IWebSocketPersister > ( ) ;
4855 }
4956
5057 /// <summary>
@@ -61,7 +68,7 @@ public async Task PerformGoogleLoginExisting() {
6168 await _db . SaveChangesAsync ( ) ;
6269
6370 // Make the call and ensure it's successful.
64- var controller = new TestableUserController ( _configuration , _db ) ;
71+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
6572 controller . Email = "hi" ;
6673 RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
6774
@@ -81,7 +88,7 @@ public async Task PerformGoogleLoginExisting() {
8188 [ Test ]
8289 public async Task PerformGoogleLoginNewUser ( ) {
8390 // Make the call and ensure it's successful.
84- var controller = new TestableUserController ( _configuration , _db ) ;
91+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
8592 controller . Email = "hi" ;
8693 RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
8794
@@ -103,7 +110,7 @@ public async Task GoToErrorOnDbException() {
103110 _db . Users = null ! ;
104111
105112 // Make the call and ensure it's successful.
106- var controller = new TestableUserController ( _configuration , _db ) ;
113+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
107114 controller . Email = "hi" ;
108115 RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
109116
@@ -117,7 +124,7 @@ public async Task GoToErrorOnDbException() {
117124 [ Test ]
118125 public async Task GoToErrorOnBadGmailResponse ( ) {
119126 // Make the call and ensure it's successful.
120- var controller = new TestableUserController ( _configuration , _db ) ;
127+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
121128 controller . Email = null ;
122129 RedirectResult obj = await controller . Login ( new GoogleOpenIdToken { credential = "stuff" } ) ;
123130
@@ -147,7 +154,7 @@ public async Task PerformTwitchLoginExisting() {
147154 await _db . SaveChangesAsync ( ) ;
148155
149156 // Make the call and ensure it's successful.
150- var controller = new TestableUserController ( _configuration , _db ) ;
157+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
151158 RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
152159
153160 // We should have been redirected to the successful route.
@@ -174,7 +181,7 @@ public async Task PerformTwitchLoginNewUser() {
174181 . Returns ( ( ) => Task . FromResult < string ? > ( "hi" ) ) ;
175182
176183 // Make the call and ensure it's successful.
177- var controller = new TestableUserController ( _configuration , _db ) ;
184+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
178185 RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
179186
180187 // We should have been redirected to the successful route.
@@ -197,7 +204,7 @@ public async Task PerformTwitchLoginBadTwitchResponse() {
197204 . Returns ( ( ) => Task . FromResult < TwitchAccessToken ? > ( null ) ) ;
198205
199206 // Make the call and ensure it's successful.
200- var controller = new TestableUserController ( _configuration , _db ) ;
207+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
201208 RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
202209
203210 // We should have gone down the bad route
@@ -214,7 +221,7 @@ public async Task PerformTwitchLoginWithNoEmailAccount() {
214221 . Returns ( ( ) => Task . FromResult < TwitchAccessToken ? > ( new TwitchAccessToken ( ) ) ) ;
215222
216223 // Make the call and ensure it's successful.
217- var controller = new TestableUserController ( _configuration , _db ) ;
224+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
218225 RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
219226
220227 // 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() {
237244 . Returns ( ( ) => Task . FromResult < string ? > ( "hi" ) ) ;
238245
239246 // Make the call and ensure it's successful.
240- var controller = new TestableUserController ( _configuration , _db ) ;
247+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
241248 RedirectResult obj = await controller . TwitchLogin ( "things" , _twitchApi . Object ) ;
242249
243250 // We should have been redirected to the error route because of an exception in DB processing.
@@ -256,7 +263,7 @@ public void GetRoles() {
256263 var identity = new ClaimsIdentity ( claims , "icecream" ) ;
257264
258265 // Make the call and ensure it's successful.
259- var controller = new TestableUserController ( _configuration , _db ) ;
266+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
260267 controller . ControllerContext = new ControllerContext ( ) ;
261268 controller . ControllerContext . HttpContext = new DefaultHttpContext ( ) ;
262269 controller . ControllerContext . HttpContext . User = new ClaimsPrincipal ( identity ) ;
@@ -279,7 +286,7 @@ public async Task ValidateTokenExists() {
279286 await _db . SaveChangesAsync ( ) ;
280287
281288 // Make the call and ensure it's successful.
282- var controller = new TestableUserController ( _configuration , _db ) ;
289+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
283290 IActionResult obj = await controller . Validate ( new AuthToken ( "123" ) ) ;
284291 Assert . That ( ( obj as IStatusCodeActionResult ) ? . StatusCode , Is . EqualTo ( 200 ) ) ;
285292
@@ -293,7 +300,7 @@ public async Task ValidateTokenExists() {
293300 [ Test ]
294301 public async Task ValidateFailWithoutToken ( ) {
295302 // Make the call and ensure it fails.
296- var controller = new TestableUserController ( _configuration , _db ) ;
303+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
297304 IActionResult obj = await controller . Validate ( new AuthToken ( "123" ) ) ;
298305 Assert . That ( ( obj as IStatusCodeActionResult ) ? . StatusCode , Is . EqualTo ( 401 ) ) ;
299306 }
@@ -306,7 +313,7 @@ public async Task ValidateFailOnDbFailure() {
306313 _db . Users = null ! ;
307314
308315 // Make the call and ensure it fails.
309- var controller = new TestableUserController ( _configuration , _db ) ;
316+ var controller = new TestableUserController ( _configuration , _db , _webSocketPersister . Object ) ;
310317 IActionResult obj = await controller . Validate ( new AuthToken ( "123" ) ) ;
311318 Assert . That ( ( obj as IStatusCodeActionResult ) ? . StatusCode , Is . EqualTo ( 500 ) ) ;
312319 }
@@ -317,7 +324,7 @@ public async Task ValidateFailOnDbFailure() {
317324/// </summary>
318325public class TestableUserController : UserController {
319326 /// <inheritdoc />
320- public TestableUserController ( IConfiguration configuration , INullinsideContext dbContext ) : base ( configuration , dbContext ) {
327+ public TestableUserController ( IConfiguration configuration , INullinsideContext dbContext , IWebSocketPersister webSocketPersister ) : base ( configuration , dbContext , webSocketPersister ) {
321328 }
322329
323330 /// <summary>
0 commit comments