public void GetGameState_WhenWinerIsRedUser_ShouldReturnGameState() { User redUser = new User() { SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", Id = 1, Nickname = "RedUser", }; User blueUser = new User() { SessionKey = "20043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", Id = 2, Nickname = "BlueUser", }; mock.Setup(g => g.Users.GetAll()).Returns(new User[] { redUser }.AsQueryable()); mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns( new Game() { GameStatus = "InProgress", RedUserId = 1, BlueUserId = 2, RedUser = redUser, BlueUser = blueUser, Title = "Title", Winner = redUser, }); GameService gameService = new GameService(mock.Object); GameState gameState = gameService.GetGameState(1, "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef"); Assert.AreEqual("RedUser",gameState.Winner); }
public void GetGameState_WhenUserInGameIsRedUserAndNoWinner_ShouldReturnGameState() { User redUser=new User() { SessionKey="10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", Id=1, Nickname="RedUser", }; User blueUser = new User() { SessionKey = "20043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", Id = 2, Nickname="BlueUser", }; mock.Setup(g => g.Users.GetAll()).Returns(new User[]{redUser}.AsQueryable()); List<Guess> guesses = new List<Guess>(); guesses.Add(new Guess() { Id=1, Position=1, User=redUser }); guesses.Add(new Guess() { Id = 2, Position = 2, User = redUser }); guesses.Add(new Guess() { Id = 3, Position = 3, User = blueUser }); mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns( new Game() { GameStatus="InProgress", RedUserId=1, BlueUserId=2, RedUser=redUser, BlueUser=blueUser, Guesses=guesses, Title="Title", Winner=null, }); GameService gameService = new GameService(mock.Object); GameState gameState = gameService.GetGameState(1, "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef"); Assert.AreEqual("O",gameState.Symbol); Assert.AreEqual("BlueUser", gameState.Opponent); Assert.AreEqual("InProgress", gameState.State); Assert.AreEqual("Title", gameState.Title); Assert.IsNull(gameState.Winner); Assert.AreEqual(2, gameState.O.Count()); Assert.AreEqual(1, gameState.X.Count()); }