Ejemplo n.º 1
0
        private Player ForceFifthAndSixthPlayerInningsToBeTheSame(TestData testData, IBowlingFiguresCalculator bowlingFiguresCalculator)
        {
            // Find any player with at least six innings, and make the sixth best score the same as the fifth so that we can test retrieving a top five + any equal results
            var inningsForPlayerWithAtLeast6Scores = testData.Matches
                                                     .SelectMany(x => x.MatchInnings)                                                                                                                               // for each innings of each match...
                                                     .SelectMany(x => x.PlayerInnings.Where(i => i.DismissalType != DismissalType.DidNotBat && i.DismissalType != DismissalType.TimedOut && i.RunsScored.HasValue)) // get the player innings where the player got to bat...
                                                     .GroupBy(x => x.Batter.Player.PlayerId)                                                                                                                        // separate them into a group of innings for each player...
                                                     .First(x => x.Count() > 5)                                                                                                                                     // get the first player that had more than 5 such innings...
                                                     .Select(x => x)                                                                                                                                                // get those innings out of the IGrouping structure...
                                                     .OrderByDescending(x => x.RunsScored)                                                                                                                          // sort the best scores first, because that's what the query we're testing will do...
                                                     .ToList();                                                                                                                                                     // make it possible to access innings by index

            // Make the sixth innings the same as the fifth, including anything that might affect the out/not out status.
            inningsForPlayerWithAtLeast6Scores[5].DismissalType = inningsForPlayerWithAtLeast6Scores[4].DismissalType;
            inningsForPlayerWithAtLeast6Scores[5].DismissedBy   = null;
            inningsForPlayerWithAtLeast6Scores[5].Bowler        = null;
            inningsForPlayerWithAtLeast6Scores[5].RunsScored    = inningsForPlayerWithAtLeast6Scores[4].RunsScored;
            inningsForPlayerWithAtLeast6Scores[5].BallsFaced    = inningsForPlayerWithAtLeast6Scores[4].BallsFaced;

            // That might've changed bowling figures, so update them
            var matchInningsForPlayerInnings = testData.Matches.SelectMany(x => x.MatchInnings).Single(mi => mi.PlayerInnings.Any(pi => pi.PlayerInningsId == inningsForPlayerWithAtLeast6Scores[5].PlayerInningsId));

            matchInningsForPlayerInnings.BowlingFigures = bowlingFiguresCalculator.CalculateBowlingFigures(matchInningsForPlayerInnings);

            // The assertion expects the fifth and sixth innings to be the same, but to be different that any that come before or after in the
            // result set. So make sure those others are different.

            // Step 1: Make room below if required
            if (inningsForPlayerWithAtLeast6Scores.Count > 6 && inningsForPlayerWithAtLeast6Scores[5].RunsScored == 0)
            {
                inningsForPlayerWithAtLeast6Scores[4].RunsScored++;
                inningsForPlayerWithAtLeast6Scores[5].RunsScored++;
            }

            // Step 2: Ensure earlier scores are higher
            for (var i = 0; i < 4; i++)
            {
                if (inningsForPlayerWithAtLeast6Scores[i].RunsScored == inningsForPlayerWithAtLeast6Scores[4].RunsScored)
                {
                    inningsForPlayerWithAtLeast6Scores[i].RunsScored++;
                }
            }

            // Step 3: Ensure later scores are lower, but not below 0
            for (var i = 6; i < inningsForPlayerWithAtLeast6Scores.Count; i++)
            {
                if (inningsForPlayerWithAtLeast6Scores[i].RunsScored > 0)
                {
                    inningsForPlayerWithAtLeast6Scores[i].RunsScored--;
                }
                else
                {
                    inningsForPlayerWithAtLeast6Scores[i].RunsScored = 0;
                }
            }

            return(inningsForPlayerWithAtLeast6Scores.First().Batter.Player);
        }
 public EditBattingScorecardSurfaceController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory umbracoDatabaseFactory, ServiceContext serviceContext,
                                              AppCaches appCaches, ILogger logger, IProfilingLogger profilingLogger, UmbracoHelper umbracoHelper, IMatchDataSource matchDataSource, IMatchRepository matchRepository,
                                              IAuthorizationPolicy <Stoolball.Matches.Match> authorizationPolicy, IDateTimeFormatter dateTimeFormatter, IMatchInningsUrlParser matchInningsUrlParser,
                                              IPlayerInningsScaffolder playerInningsScaffolder, IBowlingFiguresCalculator bowlingFiguresCalculator)
     : base(umbracoContextAccessor, umbracoDatabaseFactory, serviceContext, appCaches, logger, profilingLogger, umbracoHelper)
 {
     _matchDataSource          = matchDataSource ?? throw new ArgumentNullException(nameof(matchDataSource));
     _matchRepository          = matchRepository ?? throw new ArgumentNullException(nameof(matchRepository));
     _authorizationPolicy      = authorizationPolicy ?? throw new ArgumentNullException(nameof(authorizationPolicy));
     _dateTimeFormatter        = dateTimeFormatter ?? throw new ArgumentNullException(nameof(dateTimeFormatter));
     _matchInningsUrlParser    = matchInningsUrlParser ?? throw new ArgumentNullException(nameof(matchInningsUrlParser));
     _playerInningsScaffolder  = playerInningsScaffolder ?? throw new ArgumentNullException(nameof(playerInningsScaffolder));
     _bowlingFiguresCalculator = bowlingFiguresCalculator ?? throw new ArgumentNullException(nameof(bowlingFiguresCalculator));
 }
 public EditStatisticsSurfaceController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory umbracoDatabaseFactory, ServiceContext serviceContext,
                                        AppCaches appCaches, ILogger logger, IProfilingLogger profilingLogger, UmbracoHelper umbracoHelper, IDatabaseConnectionFactory databaseConnectionFactory,
                                        IBackgroundTaskTracker taskTracker, IMatchListingDataSource matchListingDataSource, IMatchDataSource matchDataSource, IStatisticsRepository statisticsRepository,
                                        IBowlingFiguresCalculator bowlingFiguresCalculator, IPlayerInMatchStatisticsBuilder playerInMatchStatisticsBuilder, IPlayerIdentityFinder playerIdentityFinder)
     : base(umbracoContextAccessor, umbracoDatabaseFactory, serviceContext, appCaches, logger, profilingLogger, umbracoHelper)
 {
     _databaseConnectionFactory = databaseConnectionFactory ?? throw new ArgumentNullException(nameof(databaseConnectionFactory));
     _taskTracker                    = taskTracker ?? throw new ArgumentNullException(nameof(taskTracker));
     _matchListingDataSource         = matchListingDataSource ?? throw new ArgumentNullException(nameof(matchListingDataSource));
     _matchDataSource                = matchDataSource ?? throw new ArgumentNullException(nameof(matchDataSource));
     _statisticsRepository           = statisticsRepository ?? throw new ArgumentNullException(nameof(statisticsRepository));
     _bowlingFiguresCalculator       = bowlingFiguresCalculator ?? throw new ArgumentNullException(nameof(bowlingFiguresCalculator));
     _playerInMatchStatisticsBuilder = playerInMatchStatisticsBuilder ?? throw new ArgumentNullException(nameof(playerInMatchStatisticsBuilder));
     _playerIdentityFinder           = playerIdentityFinder ?? throw new ArgumentNullException(nameof(playerIdentityFinder));
 }