public void SwissResetMatchScore_FiresGamesDeletedEvents_WithAllGamesInClearedRound()
        {
            int deletedGames = 0;

            List <IPlayer> pList = new List <IPlayer>();

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

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

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

            b.ResetMatchScore(1);
            // Delete games: 1 from first match, 2 from second round (removed)
            Assert.AreEqual(1 + 2, deletedGames);
        }
        public void SwissResetMatchScore_FiresMatchesModifiedEvent_WithOnlyOneMatchModel()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 9; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList);
            int      matchesPerRound = b.GetRound(1).Count;

            for (int n = 1; n < matchesPerRound; ++n)
            {
                b.SetMatchWinner(n, PlayerSlot.Challenger);
            }

            int matchesModified = 0;

            b.MatchesModified += delegate(object sender, BracketEventArgs e)
            {
                matchesModified += e.UpdatedMatches.Count;
            };
            b.ResetMatchScore(1);
            Assert.AreEqual(1, matchesModified);
        }
        public void SwissResetMatchScore_RecalculatesRankings_IfMatchWinIsReversed()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 33; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList, PairingMethod.Slide, 3);
            int      matchesPerRound = b.GetRound(1).Count;

            for (int n = 1; n <= matchesPerRound; ++n)
            {
                b.SetMatchWinner(n, PlayerSlot.Challenger);
            }
            for (int n = 1; n < matchesPerRound; ++n)
            {
                b.AddGame(n + matchesPerRound, 25, 15, PlayerSlot.Defender);
                b.AddGame(n + matchesPerRound, 25, 15, PlayerSlot.Defender);
            }

            b.ResetMatchScore(matchesPerRound + 1);
            Assert.AreEqual(2, b.Rankings[0].Wins);
        }
        public void SwissResetMatchScore_ClearsAllFutureRounds()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 32; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList, PairingMethod.Slide, 3);
            int      matchesPerRound = b.GetRound(1).Count;

            for (int i = 0; i < 3; ++i)
            {
                for (int n = 1; n <= matchesPerRound; ++n)
                {
                    b.AddGame(n + (i * matchesPerRound), 1, 0, PlayerSlot.Defender);
                    b.AddGame(n + (i * matchesPerRound), 1, 0, PlayerSlot.Defender);
                }
            }

            b.ResetMatchScore(1);
            bool roundTwoHasPlayers = b.GetRound(2)
                                      .Any(m => !(m.Players.Contains(null)));

            Assert.IsFalse(roundTwoHasPlayers);
        }
        public void SwissResetMatchScore_DeletesFollowingRound_IfMatchWinIsReversed()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 32; ++i)
            {
                Mock <IPlayer> moq = new Mock <IPlayer>();
                moq.Setup(p => p.Id).Returns(i + 1);
                pList.Add(moq.Object);
            }
            IBracket b = new SwissBracket(pList, PairingMethod.Slide, 3);
            int      matchesPerRound = b.NumberOfMatches;

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

            b.ResetMatchScore(matchesPerRound);
            Assert.AreEqual(matchesPerRound, b.NumberOfMatches);
        }