/// <summary>
        /// Gets pivot standings of the tournament specified by identifier.
        /// </summary>
        /// <param name="tournamentId">Identifier of the tournament.</param>
        /// <returns>Pivot standings of the tournament with specified identifier.</returns>
        public TournamentStandings <PivotStandingsDto> GetPivotStandings(int tournamentId)
        {
            var tournament  = _tournamentByIdQuery.Execute(new FindByIdCriteria(tournamentId));
            var gameResults = _tournamentGameResultsQuery.Execute(new TournamentGameResultsCriteria {
                TournamentId = tournamentId
            });
            Dictionary <(int divisionId, string divisionName), List <TeamTournamentDto> > teamsInTournamentByDivisions = GetTeamsInTournamentByDivisions(tournamentId);

            var pivotStandings = new TournamentStandings <PivotStandingsDto>();

            foreach (var groupedTeams in teamsInTournamentByDivisions)
            {
                var gameResultsForDivision = GetGamesResultsForDivision(gameResults, groupedTeams.Value);

                var teamStandingsInDivision = CalculateStandingsForDivision(groupedTeams.Value, gameResultsForDivision)
                                              .Select(MapToTeamStandingsDto())
                                              .ToList();

                var shortGameResults = gameResultsForDivision.Where(g => g.AwayTeamId != null)
                                       .Select(MapToShortGameResult())
                                       .ToList();

                pivotStandings.Divisions.Add(new PivotStandingsDto(teamStandingsInDivision, shortGameResults)
                {
                    DivisionId     = groupedTeams.Key.divisionId,
                    DivisionName   = groupedTeams.Key.divisionName,
                    LastUpdateTime = tournament.LastTimeUpdated
                });
            }

            return(pivotStandings);
        }
Esempio n. 2
0
        private static void AssertBallsAreEqual(TournamentStandings <StandingsDto> expected, TournamentStandings <StandingsDto> actual, string message)
        {
            StandingsEntryComparer standingsComparer = new StandingsEntryComparer();

            standingsComparer.WithBallsComparer();
            AssertTournamentStandingsAreEqual(expected, actual, message, new StandingsDtoComparer(standingsComparer));
        }
        /// <summary>
        /// Gets standings of the tournament specified by identifier.
        /// </summary>
        /// <param name="tournamentId">Identifier of the tournament.</param>
        /// <returns>Standings of the tournament with specified identifier.</returns>
        public TournamentStandings <StandingsDto> GetStandings(int tournamentId)
        {
            var result = new TournamentStandings <StandingsDto>();

            var tournament  = _tournamentByIdQuery.Execute(new FindByIdCriteria(tournamentId));
            var gameResults = _tournamentGameResultsQuery.Execute(new TournamentGameResultsCriteria {
                TournamentId = tournamentId
            });
            Dictionary <(int divisionId, string divisionName), List <TeamTournamentDto> > teamsInTournamentByDivisions = GetTeamsInTournamentByDivisions(tournamentId);

            foreach (var groupedTeams in teamsInTournamentByDivisions)
            {
                var standings = CalculateStandingsForDivision(groupedTeams.Value, gameResults);

                var standingsDto = new StandingsDto
                {
                    DivisionId     = groupedTeams.Key.divisionId,
                    DivisionName   = groupedTeams.Key.divisionName,
                    LastUpdateTime = tournament.LastTimeUpdated,
                    Standings      = standings
                };
                result.Divisions.Add(standingsDto);
            }

            return(result);
        }
 private void AssertPivotStandingsAreEqual(
     TournamentStandings <PivotStandingsDto> expected,
     TournamentStandings <PivotStandingsDto> actual,
     string message)
 {
     AssertTournamentStandingsAreEqual(expected, actual, message, new PivotStandingsComparer());
 }
        public int Compare(TournamentStandings <T> x, TournamentStandings <T> y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            if (x == null || y == null)
            {
                throw new AssertFailedException("One instance is null");
            }

            if (x.Divisions.Count == y.Divisions.Count)
            {
                for (var i = 0; i < x.Divisions.Count; i++)
                {
                    if (_groupItemComparer.Compare(x.Divisions[i], y.Divisions[i]) != 0)
                    {
                        return(1);
                    }
                }
            }
            else
            {
                throw new AssertFailedException("Number of divisions do not match.");
            }

            return(0);
        }
        private void AssertGameStatusAreEqual(
            TournamentStandings <PivotStandingsDto> expected,
            TournamentStandings <PivotStandingsDto> actual,
            string message)
        {
            var comparer = new PivotStandingsComparer();

            comparer.WithGamesComparer();
            AssertTournamentStandingsAreEqual(expected, actual, message, comparer);
        }
        protected static void AssertTournamentStandingsAreEqual <T>(
            TournamentStandings <T> expected,
            TournamentStandings <T> actual,
            string message,
            IEqualityComparer <T> comparer)
        {
            var errorDetails = string.Empty;

            var compareResult = new TournamentStandingsComparer <T>(comparer)
                                .Compare(expected, actual);

            Assert.True(compareResult == 0, $"{message}{errorDetails}");
        }
Esempio n. 8
0
        public int Compare(TournamentStandings <T> x, TournamentStandings <T> y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            x.Should().NotBeNull("One instance is null");
            y.Should().NotBeNull("One instance is null");

            Assert.Equal(x.Divisions, y.Divisions, _groupItemComparer);

            return(0);
        }
Esempio n. 9
0
        public int Compare(TournamentStandings <T> x, TournamentStandings <T> y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            if (x == null || y == null)
            {
                throw new AssertFailedException("One instance is null");
            }

            TestHelper.AreEqual(x.Divisions, y.Divisions, _groupItemComparer);

            return(0);
        }
Esempio n. 10
0
        protected static void AssertTournamentStandingsAreEqual <T>(
            TournamentStandings <T> expected,
            TournamentStandings <T> actual,
            string message,
            IComparer <T> comparer)
        {
            int compareResult;
            var errorDetails = string.Empty;

            try
            {
                compareResult = new TournamentStandingsComparer <T>(comparer)
                                .Compare(expected, actual);
            }
            catch (AssertFailedException e)
            {
                compareResult = -1;
                errorDetails  = $" Error Details: {e.Message}";
            }

            Assert.IsTrue(compareResult == 0, $"{message}{errorDetails}");
        }
Esempio n. 11
0
 private void SetupGameReportGetPivotStandings(int tournamentId, TournamentStandings <PivotStandingsDto> testData)
 {
     _gameReportServiceMock
     .Setup(m => m.GetPivotStandings(It.Is <int>(id => id == tournamentId))).Returns(testData);
 }
Esempio n. 12
0
 public int GetHashCode(TournamentStandings <T> obj)
 {
     return(obj.Divisions.First().GetHashCode());
 }
Esempio n. 13
0
 public bool Equals(TournamentStandings <T> x, TournamentStandings <T> y)
 {
     return(Compare(x, y) == 0);
 }
 private void MockGetPivotStandings(int tournamentId, TournamentStandings <PivotStandingsDto> testData)
 {
     _gameReportServiceMock.Setup(gr => gr.GetPivotStandings(tournamentId)).Returns(testData);
 }