Esempio n. 1
0
        public async Task AddingSamePlayerToDifferentTeam()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team");
            Assert.IsTrue(teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team");

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam),
                "Couldn't add player to team");

            IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers();

            Assert.AreEqual(1, pairs.Count(), "Unexpected number of players");
            PlayerTeamPair pair = pairs.First();

            Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known");
            Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team");
            Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should have the same display name");

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, SecondTeam),
                "Should be able to add the same player to the same team (as a no-op)");
            pairs = await teamManager.GetKnownPlayers();

            Assert.AreEqual(1, pairs.Count(), "Unexpected number of players after the second add");
            pair = pairs.First();
            Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should still be known");
            Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should still have the same display name");
            Assert.AreEqual(SecondTeam, pair.TeamId, "Player should be on the second team");
        }
Esempio n. 2
0
        public async Task CannotRemovePlayerNotOnTeam()
        {
            ulong  buzzer   = GetExistingNonReaderUserId();
            string nickname = $"User_{buzzer}";

            this.CreateHandler(
                out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore);

            currentGame.ReaderId = DefaultReaderId;
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            currentGame.TeamManager = teamManager;
            Assert.IsTrue(teamManager.TryAddTeam("Alpha", out _), "Team should've been added");

            Mock <IGuildUser> mockUser = new Mock <IGuildUser>();

            mockUser.Setup(user => user.Id).Returns(buzzer);
            mockUser.Setup(user => user.Nickname).Returns(nickname);

            await handler.RemovePlayerAsync(mockUser.Object);

            IEnumerable <PlayerTeamPair> players = await teamManager.GetKnownPlayers();

            Assert.IsFalse(players.Any(), "There should be no players");
            Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of channel messages.");
            string message = messageStore.ChannelMessages.First();

            Assert.IsTrue(
                message.Contains($@"Couldn't remove player ""{nickname}""", StringComparison.InvariantCulture),
                $"Couldn't find failure message in message\n{message}");
        }
Esempio n. 3
0
        public async Task AddMultipleTeams()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the first team");
            Assert.IsTrue(
                teamManager.TryAddTeam(SecondTeam, out _), "Couldn't add the second team");
            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add the first player");
            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(SecondPlayerId, SecondPlayerName, SecondTeam),
                "Couldn't add the second player");

            IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers();

            Assert.AreEqual(2, pairs.Count(), "Unexpected number of known players");

            PlayerTeamPair firstPair = pairs.FirstOrDefault(pair => pair.PlayerId == FirstPlayerId);

            Assert.IsNotNull(firstPair, "Couldn't find the first player");
            Assert.AreEqual(FirstTeam, firstPair.TeamId, "First player has the wrong team");
            Assert.AreEqual(FirstPlayerName, firstPair.PlayerDisplayName, "First player has the wrong name");

            PlayerTeamPair secondPair = pairs.FirstOrDefault(pair => pair.PlayerId == SecondPlayerId);

            Assert.IsNotNull(secondPair, "Couldn't find the second player");
            Assert.AreEqual(SecondTeam, secondPair.TeamId, "First player has the wrong team");
            Assert.AreEqual(SecondPlayerName, secondPair.PlayerDisplayName, "Second player has the wrong name");
        }
Esempio n. 4
0
        public async Task RemovePlayerFromTeam()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team");

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam),
                "Couldn't add player to team");
            Assert.IsTrue(teamManager.TryRemovePlayerFromTeam(FirstPlayerId), "Couldn't remove player from team");

            IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers();

            Assert.IsFalse(pairs.Any(), "There should be no players, but some were found");
        }
Esempio n. 5
0
        public async Task AddingPlayerToTeam()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team");

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam),
                "Couldn't add player to team");
            IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers();

            Assert.AreEqual(1, pairs.Count(), "Unexpected number of players");
            PlayerTeamPair pair = pairs.First();

            Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known");
            Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team");
        }
Esempio n. 6
0
        public async Task RemoveTeamFailsWhenPlayerScored()
        {
            const ulong  playerId   = 2;
            const string playerName = "Alice";
            const string teamName   = "Alpha";

            this.CreateHandler(
                out ReaderCommandHandler handler, out GameState currentGame, out MessageStore messageStore);

            await handler.AddTeamAsync(teamName);

            ByCommandTeamManager teamManager = currentGame.TeamManager as ByCommandTeamManager;

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(playerId, playerName, teamName),
                "Couldn't add the player to the team");
            Assert.IsTrue(await currentGame.AddPlayer(playerId, playerName), "Couldn't buzz in for the player");
            currentGame.ScorePlayer(10);

            Mock <IGuildUser> playerUser = new Mock <IGuildUser>();

            playerUser.Setup(user => user.Id).Returns(playerId);
            await handler.RemovePlayerAsync(playerUser.Object);

            bool hasPlayers = (await teamManager.GetKnownPlayers()).Any();

            Assert.IsFalse(hasPlayers, "Player should've been removed");

            messageStore.Clear();

            await handler.RemoveTeamAsync(teamName);

            IReadOnlyDictionary <string, string> teamIdToNames = await currentGame.TeamManager.GetTeamIdToNames();

            Assert.AreEqual(1, teamIdToNames.Count, "Unexpected number of teams after removal");
            Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of messages");
            string message = messageStore.ChannelMessages.First();

            Assert.AreEqual(
                @$ "Unable to remove the team. **{playerName}** has already been scored, so the player cannot be removed without affecting the score.",
                message,
                "Unexpected message");
        }
Esempio n. 7
0
        public async Task CannotRemoveNonexistentPlayerFromTeam()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team");

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam),
                "Couldn't add player to team");
            Assert.IsFalse(teamManager.TryRemovePlayerFromTeam(SecondPlayerId), "Second player shouldn't be removable");

            IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers();

            Assert.AreEqual(1, pairs.Count(), "Unexpected number of players");
            PlayerTeamPair pair = pairs.First();

            Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known");
            Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team");
            Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should have a name");
        }
Esempio n. 8
0
        public async Task AddingPlayerToRemovedTeam()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add team");

            IReadOnlyDictionary <string, string> teamIdToName = await teamManager.GetTeamIdToNames();

            Assert.IsTrue(teamIdToName.ContainsKey(FirstTeam), "Couldn't find team after adding it");

            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam),
                "Couldn't add player to team");
            IEnumerable <PlayerTeamPair> pairs = await teamManager.GetKnownPlayers();

            Assert.AreEqual(1, pairs.Count(), "Unexpected number of players");
            PlayerTeamPair pair = pairs.First();

            Assert.AreEqual(FirstPlayerId, pair.PlayerId, "Player should be known");
            Assert.AreEqual(FirstTeam, pair.TeamId, "Player should be on the first team");
            Assert.AreEqual(FirstPlayerName, pair.PlayerDisplayName, "Player should have a name");
        }