Ejemplo n.º 1
0
        public void OnGameFinish(long gameLobbyID)
        {
            var gameLobby = gameLobbyService.GetGameLobby(gameLobbyID);

            if (gameLobby == null)
            {
                return;
            }
            gameLobby.UseLobbyLock(() =>
            {
                var result = gameLobby.GameLogicController.GetGameResult();
                //gameUserRepository.UpdateGameScores(result.UsersRanking.Select((v) => v.UserPrincipal).ToList(), result.RankingScores);

                foreach (var gameUser in gameLobby.GetUsers())
                {
                    gameUser.SetCurrentGameLobbyID(null);
                    var gameState  = gameLobby.GameLogicController.GetGameState(gameUser);
                    var connection = userConnectionsService.GameConnectionService.GetConnection(gameUser);

                    var apiObject = new HubApi.GameFinish
                    {
                        GameResult = new GetGameResult(result)
                    };
                    gameHubContext.Clients.Client(connection).GameFinish(apiObject);
                }

                gameLobbyService.RemoveGameLobby(gameLobbyID);
            });
        }
Ejemplo n.º 2
0
        public async Task RemoveGameLobby_Succeeds_RemovesExistingGameLobby()
        {
            var gameLobby = new GameLobby();
            var mock      = new Mock <IGameLobbyRepository>();

            mock.Setup(m => m.GetGameLobbyByLobbyCode(It.IsAny <string>()))
            .ReturnsAsync(() => gameLobby);
            var service = new GameLobbyService(mock.Object);

            var success = await service.RemoveGameLobby("");

            Assert.IsTrue(success);
            mock.Verify(m => m.RemoveGameLobby(It.IsAny <string>()), Times.Once());
            mock.VerifyAll();
        }
Ejemplo n.º 3
0
        public async Task RemoveGameLobby_DoesntRemoveAnyLobby_IfLobbyDoesntExists()
        {
            var gameLobby = new GameLobby();
            var mock      = new Mock <IGameLobbyRepository>();

            mock.Setup(m => m.GetGameLobbyByLobbyCode(It.IsAny <string>()))
            .ReturnsAsync(() => null);
            var service = new GameLobbyService(mock.Object);

            var success = await service.RemoveGameLobby("");

            Assert.IsFalse(success);
            mock.Verify(m => m.RemoveGameLobby(It.IsAny <string>()), Times.Never());
            mock.VerifyAll();
        }