public async Task Read_total_players_with_catches_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.ReadTotalPlayersWithCatches(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.Caught && x.DismissedBy != null) || (x.DismissalType == DismissalType.CaughtAndBowled && x.Bowler != null)) .Select(x => x.DismissalType == DismissalType.Caught ? x.DismissedBy.Player.PlayerId : x.Bowler.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }
public async Task Read_total_players_with_catches_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.ReadTotalPlayersWithCatches(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.Caught && x.DismissedBy != null) || (x.DismissalType == DismissalType.CaughtAndBowled && x.Bowler != null)) .Select(x => x.DismissalType == DismissalType.Caught ? x.DismissedBy.Player.PlayerId : x.Bowler.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }
public async Task Read_total_players_with_catches_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.ReadTotalPlayersWithCatches(null).ConfigureAwait(false); var expected = _databaseFixture.TestData.Matches .SelectMany(x => x.MatchInnings) .SelectMany(x => x.PlayerInnings) .Where(x => (x.DismissalType == DismissalType.Caught && x.DismissedBy != null) || (x.DismissalType == DismissalType.CaughtAndBowled && x.Bowler != null)) .Select(x => x.DismissalType == DismissalType.Caught ? x.DismissedBy.Player.PlayerId : x.Bowler.Player.PlayerId) .Distinct() .Count(); Assert.Equal(expected, result); }