public void JoinGame_WhenUserIsCreator_ShouldThrowException() { JoinGameModel joinGameModel = new JoinGameModel() { GameId = 1, Password = null, SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", }; mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns( new Game() { Password = null, GameStatus = "Open", RedUserId = 1 }); mock.Setup(g => g.Users.GetAll()).Returns(new User[] { new User { Id = 1, Nickname = "creatorNickname", Username = "******", SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", }, }.AsQueryable()); GameService gameService = new GameService(mock.Object); gameService.JoinGame(joinGameModel); }
public void JoinGame_WhenPasswordIsNotSame_ShouldThrowException() { JoinGameModel joinGameModel = new JoinGameModel() { GameId = 1, Password = "******", SessionKey = "100448Sitruv4IfYOGRSp6PqmxNFYr11vvZKQpCcLzmWThbTI3" }; mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns( new Game() { Password = "******", GameStatus = "Open", }); GameService gameService = new GameService(mock.Object); gameService.JoinGame(joinGameModel); }
public void JoinGame_WhenGameIsNotOpen_ShouldThrowException() { JoinGameModel joinGameModel = new JoinGameModel() { GameId = 1, }; mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns( new Game() { GameStatus = "InProgress", }); GameService gameService = new GameService(mock.Object); gameService.JoinGame(joinGameModel); }
public void JoinGame_WhenJoinGameModelIsNull_ShouldThrowException() { GameService gameService = new GameService(mock.Object); gameService.JoinGame(null); }
public void JoinGame_WhenDataIsValid_ShouldUpdateGameState() { Game updatedGame = new Game(); JoinGameModel joinGameModel = new JoinGameModel() { GameId = 1, Password = null, SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", }; mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns( new Game() { Password = null, GameStatus = "Open", RedUserId = 1 }); mock.Setup(g => g.Users.GetAll()).Returns(new User[] { new User { Id = 2, Nickname = "creatorNickname", Username = "******", SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", }, }.AsQueryable()); mock.Setup(u => u.Games.Update(It.IsAny<Game>())).Callback((Game game) => updatedGame = game); GameService gameService = new GameService(mock.Object); gameService.JoinGame(joinGameModel); Assert.AreEqual("Full", updatedGame.GameStatus); Assert.AreEqual(2, updatedGame.BlueUser.Id); }