Example #1
0
        public async Task CanRemovePlayer()
        {
            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");
            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(buzzer, nickname, "Alpha"), "Should've been able to add the player");
            Assert.IsNotNull(teamManager.GetTeamIdOrNull(buzzer), "Player should have a team");

            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 left");
            Assert.AreEqual(1, messageStore.ChannelMessages.Count, "Unexpected number of channel messages.");
            string message = messageStore.ChannelMessages.First();

            Assert.IsTrue(
                message.Contains(nickname, StringComparison.InvariantCulture),
                $"Couldn't find username in message\n{message}");
        }
Example #2
0
        public async Task GetTeamIdOfNonexistentPlayer()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team");
            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add the player");
            Assert.IsNull(await teamManager.GetTeamIdOrNull(SecondPlayerId), "Unexpected team ID");
        }
Example #3
0
        public async Task GetTeamIdOfPlayerAfterRemoval()
        {
            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team");
            Assert.IsTrue(
                teamManager.TryAddPlayerToTeam(FirstPlayerId, FirstPlayerName, FirstTeam), "Couldn't add the player");
            Assert.IsTrue(
                teamManager.TryRemovePlayerFromTeam(FirstPlayerId), "Couldn't remove the player");
            Assert.IsNull(await teamManager.GetTeamIdOrNull(FirstPlayerId), "Unexpected team ID");
        }
Example #4
0
        public async Task CannotRemoveTeamWithPlayerOnIt()
        {
            const string playerName = "Alice";

            ByCommandTeamManager teamManager = new ByCommandTeamManager();

            Assert.IsTrue(teamManager.TryAddTeam(FirstTeam, out _), "Couldn't add the team");
            Assert.IsTrue(teamManager.TryAddPlayerToTeam(1, playerName, FirstTeam), "Couldn't add the player");
            Assert.IsFalse(
                teamManager.TryRemoveTeam(FirstTeam, out string message),
                "We shouldn't have been able to remove the team");
            Assert.IsNotNull(message, "We should have an error message");

            string playersTeamName = await teamManager.GetTeamIdOrNull(1);

            Assert.AreEqual(FirstTeam, playersTeamName, "Player should still be on the team");

            string teamNameFromId = await teamManager.GetTeamNameOrNull(FirstTeam);

            Assert.IsNotNull(teamNameFromId, "Team should still be there");
        }