Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
        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));
            }
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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));
            }
        }
Beispiel #6
0
        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;
            }
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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));
            }
        }
Beispiel #9
0
        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));
            }
        }
Beispiel #10
0
        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);
            }
        }