diff --git a/SlipItIn.Server.Tests/GameHubTests.cs b/SlipItIn.Server.Tests/GameHubTests.cs index 669a609..7024c35 100644 --- a/SlipItIn.Server.Tests/GameHubTests.cs +++ b/SlipItIn.Server.Tests/GameHubTests.cs @@ -24,6 +24,8 @@ public class GameHubTests private readonly Mock _callerProxy = new(); private readonly Mock _groupProxy = new(); private readonly Mock _clientProxy = new(); + private readonly Mock> _hubContext = new(); + private readonly Mock _hubClients = new(); private readonly GameHub _hub; private const string ConnectionId = "test-connection-id"; @@ -35,7 +37,11 @@ public class GameHubTests _clients.Setup(c => c.Group(It.IsAny())).Returns(_groupProxy.Object); _clients.Setup(c => c.Client(It.IsAny())).Returns(_clientProxy.Object); - _hub = new GameHub(_gameService.Object, _factory, NullLogger.Instance); + _hubClients.Setup(c => c.Group(It.IsAny())).Returns(_groupProxy.Object); + _hubClients.Setup(c => c.Client(It.IsAny())).Returns(_clientProxy.Object); + _hubContext.Setup(c => c.Clients).Returns(_hubClients.Object); + + _hub = new GameHub(_gameService.Object, _factory, NullLogger.Instance, _hubContext.Object); SetupContext(); } diff --git a/SlipItIn.Server/Hubs/GameHub.cs b/SlipItIn.Server/Hubs/GameHub.cs index 9f01a48..bf5e59f 100644 --- a/SlipItIn.Server/Hubs/GameHub.cs +++ b/SlipItIn.Server/Hubs/GameHub.cs @@ -14,12 +14,18 @@ public class GameHub : Hub private readonly IGameService _gameService; private readonly IDbContextFactory _contextFactory; private readonly ILogger _logger; + private readonly IHubContext _hubContext; - public GameHub(IGameService gameService, IDbContextFactory contextFactory, ILogger logger) + public GameHub( + IGameService gameService, + IDbContextFactory contextFactory, + ILogger logger, + IHubContext hubContext) { _gameService = gameService; _contextFactory = contextFactory; _logger = logger; + _hubContext = hubContext; } /// @@ -260,10 +266,10 @@ public class GameHub : Hub var targetP = await db.Players.FindAsync(playerId); if (targetP?.ConnectionId != null) { - await Clients.Client(targetP.ConnectionId).SendAsync("PlayerHandUpdated", updatedHand); + await _hubContext.Clients.Client(targetP.ConnectionId).SendAsync("PlayerHandUpdated", updatedHand); } - await Clients.Group(game.LobbyCode).SendAsync("GameStateUpdated", updatedGameState); + await _hubContext.Clients.Group(game.LobbyCode).SendAsync("GameStateUpdated", updatedGameState); } } catch (Exception ex)