public void DEBRemoveLastGame_FiresEvents_ForAllDeletedGames()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList, 3);

            b.AddGame(1, 1, 0, PlayerSlot.Defender);
            b.AddGame(1, 1, 0, PlayerSlot.Defender);             // Targeted Delete
            b.AddGame(2, 1, 0, PlayerSlot.Defender);
            b.AddGame(2, 1, 0, PlayerSlot.Defender);
            b.AddGame(3, 1, 0, PlayerSlot.Defender);             // Should Delete
            b.AddGame(4, 1, 0, PlayerSlot.Defender);             // Should Delete

            int expectedAffected = 3;
            int deletedGames     = 0;

            b.GamesDeleted += delegate(object sender, BracketEventArgs e)
            {
                deletedGames += e.DeletedGameIDs.Count;
            };
            b.MatchesModified += delegate(object sender, BracketEventArgs e)
            {
                deletedGames += e.DeletedGameIDs.Count;
            };

            b.RemoveLastGame(1);
            Assert.AreEqual(expectedAffected, deletedGames);
        }
        public void DEBRemoveLastGame_ThrowsNotFound_WithBadMatchNumberInput()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList);

            b.RemoveLastGame(b.NumberOfMatches + 1);
            Assert.AreEqual(1, 2);
        }
        public void DEB_RPFFM_RemovesPlayerFromLowerBracket()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList);

            b.AddGame(1, 1, 0, PlayerSlot.Defender);
            b.RemoveLastGame(1);
            Assert.IsNull(b.GetLowerRound(1)[0].Players[(int)PlayerSlot.Defender]);
        }
        public void DEBRemoveLastGame_RemovesFromGrandFinal()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList);

            for (int n = 1; n <= b.NumberOfMatches; ++n)
            {
                b.AddGame(n, 1, 0, PlayerSlot.Defender);
            }

            b.RemoveLastGame(b.GrandFinal.MatchNumber);
            Assert.AreEqual(0, b.GrandFinal.Score[(int)PlayerSlot.Defender]);
        }
        public void DEBRemoveLastGame_UpdatesALLRankings_WhenMatchWinIsReversed()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList);

            for (int n = 1; n <= b.NumberOfMatches; ++n)
            {
                b.AddGame(n, 1, 0, PlayerSlot.Defender);
            }

            b.RemoveLastGame(b.GetLowerRound(1)[0].MatchNumber);
            Assert.AreEqual(0, b.Rankings.Count);
        }
        public void DEBRemoveLastGame_CorrectlyRemovesPriorLoserFromRankingsList()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList);

            for (int n = 1; n <= 4; ++n)
            {
                b.AddGame(n, 1, 0, PlayerSlot.Defender);
            }

            b.RemoveLastGame(4);
            Assert.AreEqual(0, b.Rankings.Count);
        }
        public void DEBRemoveLastGame_RemovesFromLowerBracket()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 4; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i);
                pList.Add(moq.Object);
            }
            IBracket b = new DoubleElimBracket(pList);

            b.AddGame(1, 1, 0, PlayerSlot.Defender);
            b.AddGame(2, 1, 0, PlayerSlot.Defender);
            b.SetMaxGamesForWholeLowerRound(1, 3);
            int mNum = b.GetLowerRound(1)[0].MatchNumber;

            b.AddGame(mNum, 1, 0, PlayerSlot.Defender);

            b.RemoveLastGame(mNum);
            Assert.AreEqual(0, b.GetMatch(mNum).Score[(int)PlayerSlot.Defender]);
        }