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(); }
public GoGame MakeNewGame(bool withActiveGame, bool withOpenGame, out GoGamePlayer player, out GoGame activeGame) { activeGame = null; player = new GoGamePlayer(); player.Id = 5; var currentPlayer = new Mock<ICurrentPlayer>(); currentPlayer.Setup(x => x.Player).Returns(player); var activeGoGame = new Mock<IActiveGoGame>(); if (withActiveGame) { activeGame = new GoGame(); activeGame.BlackPlayer = player; activeGame.BlackPlayerId = player.Id; activeGame.GameOver = false; } activeGoGame.Setup(x => x.Game).Returns(activeGame); var newGame = new GoGame(); newGame.GameOver = false; newGame.GameState = "".PadLeft(19 * 19, '0'); newGame.BlackPlaysNext = true; GoGame openGame = null; if (withOpenGame) { openGame = new GoGame(); openGame.GameOver = false; openGame.GameState = "".PadLeft(19 * 19, '0'); openGame.BlackPlaysNext = true; openGame.BlackPlayer = new GoGamePlayer(); openGame.BlackPlayer.Id = 9; openGame.BlackPlayerId = openGame.BlackPlayer.Id; } var thePlayer = player; var dataService = new Mock<IDataService>(); dataService.Setup(x => x.CreateNewGame()).Returns(newGame); dataService.Setup(x => x.FindGameWithNoOpponentPlayer(thePlayer)).Returns(openGame); var goService = new GoService(activeGoGame.Object, currentPlayer.Object, null, dataService.Object); return goService.NewGame(); }
public GoGame FindGameWithNoOpponentPlayer(GoGamePlayer currentPlayer) { return (from game in dataContext.GoGames where game.GameOver == false && game.BlackPlayerId != currentPlayer.Id && game.WhitePlayer == null select game).FirstOrDefault(); }