示例#1
0
        public void HubContextService_ChangeUsernameWithActiveGameAndToAlternatePlayerWithActiveGame()
        {
            var session = new Session();
            session.User = new User();
            session.User.Username = "******";
            var requestSession = new Mock<ICurrentRequestSession>();
            requestSession.Setup(x => x.Session).Returns((Session)session);

            var mockHubContext = new MockHubContext("connection #5");

            IActiveGoGame activeGame;
            CreateActiveGame(session.User, null, "adbbdfd999bd4541ba4d742a858dc5f1", out activeGame); var game = new GoGame();

            User newUser = new User();
            newUser.Username = "******";
            newUser.Id = 8;

            GoGamePlayer newPlayer = new GoGamePlayer();
            newPlayer.User = newUser;
            newPlayer.UserId = 8;
            newPlayer.Id = 14;

            var newGame = new GoGame();
            newGame.BlackPlayer = newPlayer;
            newGame.WhitePlayer = null;
            newGame.GameState = "0123400003430400";
            newGame.HubId = "5ad61645b24f4f40b55309c96c1a9b81";
            newGame.Id = 23;

            var dataService = new Mock<IDataService>();
            dataService.Setup(x => x.FindOrCreateUser(It.Is<string>(y => y.Equals("new user")))).Returns(newUser);
            dataService.Setup(x => x.FindGoPlayer(It.Is<int>(y => y == 8))).Returns(newPlayer);
            dataService.Setup(x => x.FindActiveGoGame(It.Is<int>(y => y == 14))).Returns(newGame);

            mockHubContext.Client<IHubClient>("5ad61645b24f4f40b55309c96c1a9b81").Setup(x => x.updateGame(It.Is<object>(y => true))).Verifiable();
            mockHubContext.Groups.Setup(x => x.Remove(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("adbbdfd999bd4541ba4d742a858dc5f1")))).Verifiable();
            mockHubContext.Groups.Setup(x => x.Add(It.Is<string>(y => y.Equals("connection #5")), It.Is<string>(y => y.Equals("5ad61645b24f4f40b55309c96c1a9b81")))).Verifiable();
            mockHubContext.Client<IHubClient>("connection #5").Setup(x => x.setUsername(It.Is<string>(y => y.Equals("new user")))).Verifiable();

            var hubGoService = new GameOfGoHubService(mockHubContext.Object, requestSession.Object, activeGame, null, dataService.Object);
            hubGoService.ChangeUser("new user");
            mockHubContext.VerifyClients();
            mockHubContext.Groups.VerifyAll();
        }
示例#2
0
        private GoGame CreateActiveGame(User whitePlayer, User blackPlayer, string hubId, out IActiveGoGame activeGame)
        {
            var game = new GoGame();
            game.BlackPlayer = new GoGamePlayer();
            game.WhitePlayer = new GoGamePlayer();

            if (whitePlayer != null)
            {
                game.WhitePlayer.User = whitePlayer;
            }
            else
            {
                game.WhitePlayer.User = new User();
                game.WhitePlayer.User.Username = "******";
            }

            if (blackPlayer != null)
            {
                game.BlackPlayer.User = blackPlayer;
            }
            else
            {
                game.BlackPlayer.User = new User();
                game.BlackPlayer.User.Username = "******";
            }

            game.GameState = "012340123401234";
            game.HubId = hubId;
            game.Id = 17;
            var mockActiveGame = new Mock<IActiveGoGame>();
            mockActiveGame.Setup(x => x.Game).Returns((GoGame)game);

            activeGame = mockActiveGame.Object;

            return game;
        }