public async Task Read_match_locations_returns_teams() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var results = await matchLocationDataSource.ReadMatchLocations(new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count } }).ConfigureAwait(false); foreach (var location in _databaseFixture.MatchLocations) { var result = results.SingleOrDefault(x => x.MatchLocationId == location.MatchLocationId); Assert.NotNull(result); foreach (var team in location.Teams) { var resultTeam = result.Teams.SingleOrDefault(x => x.TeamId == team.TeamId); Assert.NotNull(resultTeam); Assert.Equal(team.TeamName, resultTeam.TeamName); Assert.Equal(team.TeamType, resultTeam.TeamType); Assert.Equal(team.PlayerType, resultTeam.PlayerType); Assert.Equal(team.TeamRoute, resultTeam.TeamRoute); Assert.Equal(team.UntilYear, resultTeam.UntilYear); } } }
public async Task Read_match_locations_supports_filter_by_season() { var routeNormaliser = new Mock <IRouteNormaliser>(); var season = _databaseFixture.Seasons.First(x => x.Teams.Any(t => t.Team.MatchLocations.Any())); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var query = new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count }, SeasonIds = new List <Guid> { season.SeasonId.Value } }; var results = await matchLocationDataSource.ReadMatchLocations(query).ConfigureAwait(false); var teamIdsInSeason = season.Teams.Select(st => st.Team.TeamId.Value); Assert.Equal(_databaseFixture.MatchLocations.Count(x => x.Teams.Any(t => teamIdsInSeason.Contains(t.TeamId.Value))), results.Count); foreach (var result in results) { Assert.NotEmpty(result.Teams); foreach (var team in result.Teams) { Assert.Contains(team.TeamId.Value, teamIdsInSeason); } } }
public async Task Read_minimal_location_by_route_with_related_returns_basic_fields() { var routeNormaliser = new Mock <IRouteNormaliser>(); routeNormaliser.Setup(x => x.NormaliseRouteToEntity(_databaseFixture.MatchLocationWithMinimalDetails.MatchLocationRoute, "locations")).Returns(_databaseFixture.MatchLocationWithMinimalDetails.MatchLocationRoute); var locationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await locationDataSource.ReadMatchLocationByRoute(_databaseFixture.MatchLocationWithMinimalDetails.MatchLocationRoute, true).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.MatchLocationId, result.MatchLocationId); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.MatchLocationRoute, result.MatchLocationRoute); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.SecondaryAddressableObjectName, result.SecondaryAddressableObjectName); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.PrimaryAddressableObjectName, result.PrimaryAddressableObjectName); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.StreetDescription, result.StreetDescription); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.Locality, result.Locality); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.Town, result.Town); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.AdministrativeArea, result.AdministrativeArea); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.Postcode, result.Postcode); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.Latitude, result.Latitude); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.Longitude, result.Longitude); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.GeoPrecision, result.GeoPrecision); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.MatchLocationNotes, result.MatchLocationNotes); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.MemberGroupKey, result.MemberGroupKey); Assert.Equal(_databaseFixture.MatchLocationWithMinimalDetails.MemberGroupName, result.MemberGroupName); }
public async Task Read_total_locations_supports_excluding_locations_with_no_active_teams() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await matchLocationDataSource.ReadTotalMatchLocations(new MatchLocationFilter { HasActiveTeams = true }).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count(x => x.Teams.Any(t => !t.UntilYear.HasValue)), result); }
public async Task Read_total_locations_supports_no_filter() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await matchLocationDataSource.ReadTotalMatchLocations(null).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count, result); }
public async Task Read_total_locations_supports_filter_by_team_type() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await matchLocationDataSource.ReadTotalMatchLocations(new MatchLocationFilter { TeamTypes = new List <TeamType> { TeamType.Regular } }).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count(x => x.Teams.Any(t => t.TeamType == TeamType.Regular)), result); }
public async Task Read_total_locations_supports_excluding_locations_by_id() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await matchLocationDataSource.ReadTotalMatchLocations(new MatchLocationFilter { ExcludeMatchLocationIds = new List <Guid> { _databaseFixture.MatchLocationWithMinimalDetails.MatchLocationId.Value } }).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count - 1, result); }
public async Task Read_total_locations_supports_case_insensitive_filter_town() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var query = new MatchLocationFilter { Query = "ToWn" }; var result = await matchLocationDataSource.ReadTotalMatchLocations(query).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count(x => x.Town.Contains(query.Query, StringComparison.OrdinalIgnoreCase)), result); }
public async Task Read_location_by_route_excludes_transient_teams() { var routeNormaliser = new Mock <IRouteNormaliser>(); routeNormaliser.Setup(x => x.NormaliseRouteToEntity(_databaseFixture.MatchLocationWithFullDetails.MatchLocationRoute, "locations")).Returns(_databaseFixture.MatchLocationWithFullDetails.MatchLocationRoute); var locationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await locationDataSource.ReadMatchLocationByRoute(_databaseFixture.MatchLocationWithFullDetails.MatchLocationRoute, true).ConfigureAwait(false); foreach (var team in _databaseFixture.MatchLocationWithFullDetails.Teams.Where(x => x.TeamType == TeamType.Transient)) { Assert.Null(result.Teams.SingleOrDefault(x => x.TeamId == team.TeamId)); } }
public async Task Read_match_locations_supports_no_filter() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await matchLocationDataSource.ReadMatchLocations(new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count } }).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count, result.Count); foreach (var location in _databaseFixture.MatchLocations) { Assert.NotNull(result.SingleOrDefault(x => x.MatchLocationId == location.MatchLocationId)); } }
public async Task Read_match_locations_supports_excluding_locations_by_id() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var query = new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count }, ExcludeMatchLocationIds = new List <Guid> { _databaseFixture.MatchLocationWithMinimalDetails.MatchLocationId.Value } }; var result = await matchLocationDataSource.ReadMatchLocations(query).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count - 1, result.Count); Assert.Null(result.SingleOrDefault(x => x.MatchLocationId == _databaseFixture.MatchLocationWithMinimalDetails.MatchLocationId)); }
public async Task Read_match_locations_supports_case_insensitive_filter_town() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var query = new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count }, Query = "ToWn" }; var result = await matchLocationDataSource.ReadMatchLocations(query).ConfigureAwait(false); var expected = _databaseFixture.MatchLocations.Where(x => x.Town.Contains("town", StringComparison.OrdinalIgnoreCase)); Assert.Equal(expected.Count(), result.Count); foreach (var location in expected) { Assert.NotNull(result.SingleOrDefault(x => x.MatchLocationId == location.MatchLocationId)); } }
public async Task Read_location_by_route_sorts_active_teams_first() { var routeNormaliser = new Mock <IRouteNormaliser>(); routeNormaliser.Setup(x => x.NormaliseRouteToEntity(_databaseFixture.MatchLocationWithFullDetails.MatchLocationRoute, "locations")).Returns(_databaseFixture.MatchLocationWithFullDetails.MatchLocationRoute); var locationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var result = await locationDataSource.ReadMatchLocationByRoute(_databaseFixture.MatchLocationWithFullDetails.MatchLocationRoute, true).ConfigureAwait(false); var expectedActiveStatus = true; foreach (var team in result.Teams) { // The first time an inactive team is seen, set a flag to say they must all be inactive if (expectedActiveStatus && team.UntilYear.HasValue) { expectedActiveStatus = false; } Assert.Equal(expectedActiveStatus, !team.UntilYear.HasValue); } Assert.False(expectedActiveStatus); }
public async Task Read_match_locations_pages_results() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); const int pageSize = 10; var pageNumber = 1; var remaining = _databaseFixture.MatchLocations.Count; while (remaining > 0) { var result = await matchLocationDataSource.ReadMatchLocations(new MatchLocationFilter { Paging = new Paging { PageNumber = pageNumber, PageSize = pageSize } }).ConfigureAwait(false); var expected = pageSize > remaining ? remaining : pageSize; Assert.Equal(expected, result.Count); pageNumber++; remaining -= pageSize; } }
public async Task Read_match_locations_returns_locations_with_active_teams_first() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var results = await matchLocationDataSource.ReadMatchLocations(new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count } }).ConfigureAwait(false); var expectedActiveStatus = true; foreach (var matchLocation in results) { // The first time no active team is seen, set a flag to say they must all be inactive if (expectedActiveStatus && !matchLocation.Teams.Any(x => !x.UntilYear.HasValue)) { expectedActiveStatus = false; } Assert.Equal(expectedActiveStatus, matchLocation.Teams.Any(x => !x.UntilYear.HasValue)); } Assert.False(expectedActiveStatus); }
public async Task Read_match_locations_returns_basic_fields() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var results = await matchLocationDataSource.ReadMatchLocations(new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count } }).ConfigureAwait(false); foreach (var location in _databaseFixture.MatchLocations) { var result = results.SingleOrDefault(x => x.MatchLocationId == location.MatchLocationId); Assert.NotNull(result); Assert.Equal(location.MatchLocationRoute, result.MatchLocationRoute); Assert.Equal(location.Latitude, result.Latitude); Assert.Equal(location.Longitude, result.Longitude); Assert.Equal(location.SecondaryAddressableObjectName, result.SecondaryAddressableObjectName); Assert.Equal(location.PrimaryAddressableObjectName, result.PrimaryAddressableObjectName); Assert.Equal(location.Locality, result.Locality); Assert.Equal(location.Town, result.Town); } }
public async Task Read_match_locations_supports_filter_by_team_type() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var query = new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count }, TeamTypes = new List <TeamType> { TeamType.Regular } }; var results = await matchLocationDataSource.ReadMatchLocations(query).ConfigureAwait(false); Assert.Equal(_databaseFixture.MatchLocations.Count(x => x.Teams.Any(t => t.TeamType == TeamType.Regular)), results.Count); foreach (var result in results) { Assert.Empty(result.Teams.Where(x => x.TeamType != TeamType.Regular)); } }
public async Task Read_match_locations_supports_excluding_locations_with_no_active_teams() { var routeNormaliser = new Mock <IRouteNormaliser>(); var matchLocationDataSource = new SqlServerMatchLocationDataSource(_databaseFixture.ConnectionFactory, routeNormaliser.Object); var query = new MatchLocationFilter { Paging = new Paging { PageSize = _databaseFixture.MatchLocations.Count }, HasActiveTeams = true }; var result = await matchLocationDataSource.ReadMatchLocations(query).ConfigureAwait(false); var expected = _databaseFixture.MatchLocations.Where(x => x.Teams.Any(t => !t.UntilYear.HasValue)); Assert.Equal(expected.Count(), result.Count); foreach (var location in expected) { Assert.NotNull(result.SingleOrDefault(x => x.MatchLocationId == location.MatchLocationId)); } }