public async Task Read_total_players_with_runouts_supports_filter_by_team_id() { var filter = new StatisticsFilter { Team = _databaseFixture.TestData.TeamWithFullDetails }; var queryBuilder = new Mock <IStatisticsQueryBuilder>(); queryBuilder.Setup(x => x.BuildWhereClause(filter)).Returns((" AND TeamId = @TeamId", new Dictionary <string, object> { { "TeamId", _databaseFixture.TestData.TeamWithFullDetails.TeamId } })); var dataSource = new SqlServerBestPlayerTotalStatisticsDataSource(_databaseFixture.ConnectionFactory, queryBuilder.Object, Mock.Of <IPlayerDataSource>()); var result = await dataSource.ReadTotalPlayersWithRunOuts(filter).ConfigureAwait(false); var expected = _databaseFixture.TestData.Matches .Where(x => x.Teams.Select(t => t.Team.TeamId).Contains(_databaseFixture.TestData.TeamWithFullDetails.TeamId.Value)) .SelectMany(x => x.MatchInnings) .Where(i => i.BowlingTeam.Team.TeamId == _databaseFixture.TestData.TeamWithFullDetails.TeamId.Value) .SelectMany(x => x.PlayerInnings) .Where(x => x.DismissalType == DismissalType.RunOut && x.DismissedBy != null) .Select(x => x.DismissedBy.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }
public async Task Read_total_players_with_runouts_supports_filter_by_date() { var dateRangeGenerator = new DateRangeGenerator(); var(fromDate, untilDate) = dateRangeGenerator.SelectDateRangeToTest(_databaseFixture.TestData.Matches); var filter = new StatisticsFilter { FromDate = fromDate, UntilDate = untilDate }; var queryBuilder = new Mock <IStatisticsQueryBuilder>(); queryBuilder.Setup(x => x.BuildWhereClause(filter)).Returns((" AND MatchStartTime >= @FromDate AND MatchStartTime <= @UntilDate", new Dictionary <string, object> { { "FromDate", filter.FromDate }, { "UntilDate", filter.UntilDate } })); var dataSource = new SqlServerBestPlayerTotalStatisticsDataSource(_databaseFixture.ConnectionFactory, queryBuilder.Object, Mock.Of <IPlayerDataSource>()); var result = await dataSource.ReadTotalPlayersWithRunOuts(filter).ConfigureAwait(false); var expected = _databaseFixture.TestData.Matches .Where(x => x.StartTime >= filter.FromDate && x.StartTime <= filter.UntilDate) .SelectMany(x => x.MatchInnings) .SelectMany(x => x.PlayerInnings) .Where(x => x.DismissalType == DismissalType.RunOut && x.DismissedBy != null) .Select(x => x.DismissedBy.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }
public async Task Read_total_players_with_runouts_supports_filter_by_season_id() { var filter = new StatisticsFilter { Season = _databaseFixture.TestData.Competitions.First().Seasons.First() }; var queryBuilder = new Mock <IStatisticsQueryBuilder>(); queryBuilder.Setup(x => x.BuildWhereClause(filter)).Returns((" AND SeasonId = @SeasonId", new Dictionary <string, object> { { "SeasonId", _databaseFixture.TestData.Competitions.First().Seasons.First().SeasonId } })); var dataSource = new SqlServerBestPlayerTotalStatisticsDataSource(_databaseFixture.ConnectionFactory, queryBuilder.Object, Mock.Of <IPlayerDataSource>()); var result = await dataSource.ReadTotalPlayersWithRunOuts(filter).ConfigureAwait(false); var expected = _databaseFixture.TestData.Matches .Where(x => x.Season?.SeasonId == _databaseFixture.TestData.Competitions.First().Seasons.First().SeasonId) .SelectMany(x => x.MatchInnings) .SelectMany(x => x.PlayerInnings) .Where(x => x.DismissalType == DismissalType.RunOut && x.DismissedBy != null) .Select(x => x.DismissedBy.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }
public async Task Read_total_players_with_runouts_supports_no_filter() { var queryBuilder = new Mock <IStatisticsQueryBuilder>(); queryBuilder.Setup(x => x.BuildWhereClause(It.IsAny <StatisticsFilter>())).Returns((string.Empty, new Dictionary <string, object>())); var dataSource = new SqlServerBestPlayerTotalStatisticsDataSource(_databaseFixture.ConnectionFactory, queryBuilder.Object, Mock.Of <IPlayerDataSource>()); var result = await dataSource.ReadTotalPlayersWithRunOuts(null).ConfigureAwait(false); var expected = _databaseFixture.TestData.Matches .SelectMany(x => x.MatchInnings) .SelectMany(x => x.PlayerInnings) .Where(x => x.DismissalType == DismissalType.RunOut && x.DismissedBy != null) .Select(x => x.DismissedBy.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }