public void LeaveSession() { var session1 = game.CreateNewSession(); var session2 = game.CreateNewSession(); var sessionInfo = game.GetSessionsInfo(); TestHelper.AddPlayers(game, session1, 10); TestHelper.AddPlayers(game, session2, 10); Assert.Equal(10, session1.Players.Count()); Assert.Equal(10, session2.Players.Count()); game.Leave("1"); game.Leave("2"); Assert.Equal(8, session1.Players.Count()); Assert.Equal(18, game.AllPlayers().Count()); Assert.Equal(8, sessionInfo.First().PlayerCount); Assert.Equal(10, sessionInfo.Skip(1).Take(1).First().PlayerCount); var leaveResult = (false, ""); leaveResult = game.Leave("invalid player"); Assert.False(leaveResult.Item1); Assert.Null(leaveResult.Item2); }
public static void AddPlayers(SolidTriviaGame game, GameSession session, int playerCount) { for (var i = 0; i < playerCount; i++) { var count = (game.AllPlayers().Count() + 1).ToString(); game.Join(count, session.Id); } }
public void Test() { Assert.Empty(game.AllPlayers()); SmsResponseMessage response = new SmsResponseMessage(); //successful join response = game.ProcessUserSmsMessage("1", $"join {session.Id}"); Assert.True(response.Success); Assert.True(response.HasMessage); Assert.StartsWith("you have joined the game", response.Body); Assert.Single(game.AllPlayers()); //failed join, already playing response = game.ProcessUserSmsMessage("1", $"join {session.Id}"); Assert.False(response.Success); Assert.StartsWith("you are already registered for a game", response.Body); Assert.Single(game.AllPlayers()); //successful join response = game.ProcessUserSmsMessage("2", $"JOIN {session.Id}"); Assert.StartsWith("you have joined the game", response.Body); Assert.Equal(2, game.AllPlayers().Count()); //failed leave, user is not playing, no response response = game.ProcessUserSmsMessage("3", $"LEAVE"); Assert.False(response.HasMessage); Assert.Equal(2, game.AllPlayers().Count()); //successful leave response = game.ProcessUserSmsMessage("2", $"leave"); Assert.StartsWith("you have left the game", response.Body); Assert.Single(game.AllPlayers()); }