Ejemplo n.º 1
0
        public async Task Read_team_listings_supports_case_insensitive_filter_by_team_name_where_the_club_name_is_different()
        {
            var team           = _databaseFixture.Clubs.Where(x => x.Teams.Count > 1).SelectMany(x => x.Teams).First(x => !x.Club.ClubName.Contains(x.TeamName, StringComparison.OrdinalIgnoreCase));
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);
            var query          = new TeamListingFilter {
                Query = team.TeamName.ToUpperInvariant()
            };

            var results = await teamDataSource.ReadTeamListings(query).ConfigureAwait(false);

            foreach (var result in results)
            {
                var club = _databaseFixture.Clubs.SingleOrDefault(x => x.ClubId == result.TeamListingId);
                if (club != null)
                {
                    var clubNameMatches = club.ClubName.Contains(team.TeamName, StringComparison.OrdinalIgnoreCase);
                    var teamNameMatches = club.Teams.Any(x => x.TeamName.Contains(team.TeamName, StringComparison.OrdinalIgnoreCase));
                    Assert.True(clubNameMatches || teamNameMatches);
                }
                else
                {
                    var resultTeam = _databaseFixture.Teams.SingleOrDefault(x => x.TeamId == result.TeamListingId);
                    Assert.Contains(team.TeamName, result.ClubOrTeamName, StringComparison.OrdinalIgnoreCase);
                }
            }
            if (team.Club.Teams.Count > 1)
            {
                Assert.NotNull(results.SingleOrDefault(x => x.TeamListingId == team.Club.ClubId));
            }
            else
            {
                Assert.NotNull(results.SingleOrDefault(x => x.TeamListingId == team.TeamId));
            }
        }
Ejemplo n.º 2
0
        public async Task Read_team_listings_returns_team_for_club_with_one_team()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            var results = await teamDataSource.ReadTeamListings(null).ConfigureAwait(false);

            Assert.NotNull(results.SingleOrDefault(x => x.TeamListingId == _databaseFixture.ClubWithOneTeam.Teams.First().TeamId));
            Assert.Null(results.SingleOrDefault(x => x.TeamListingId == _databaseFixture.ClubWithOneTeam.ClubId));
        }
Ejemplo n.º 3
0
        public async Task Read_team_listings_supports_no_filter()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            var result = await teamDataSource.ReadTeamListings(null).ConfigureAwait(false);

            Assert.Equal(_databaseFixture.TeamListings.Count, result.Count);
            foreach (var team in _databaseFixture.TeamListings)
            {
                Assert.NotNull(result.SingleOrDefault(x => x.TeamListingId == team.TeamListingId));
            }
        }
Ejemplo n.º 4
0
        public async Task Read_team_listings_supports_case_insensitive_filter_by_club_name()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);
            var query          = new TeamListingFilter {
                Query = "ClUB MiNiMaL"
            };

            var result = await teamDataSource.ReadTeamListings(query).ConfigureAwait(false);

            Assert.Equal(_databaseFixture.TeamListings.Count(x => x.ClubOrTeamName.Contains(query.Query, StringComparison.OrdinalIgnoreCase)), result.Count);
            foreach (var listing in _databaseFixture.TeamListings.Where(x => x.ClubOrTeamName.Contains(query.Query, StringComparison.OrdinalIgnoreCase)))
            {
                Assert.NotNull(result.SingleOrDefault(x => x.TeamListingId == listing.TeamListingId));
            }
        }
Ejemplo n.º 5
0
        public async Task Read_team_listings_supports_case_insensitive_filter_by_club_with_administrative_area()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);
            var query          = new TeamListingFilter {
                Query = _databaseFixture.MatchLocationForClub.AdministrativeArea.ToUpperInvariant()
            };

            var result = await teamDataSource.ReadTeamListings(query).ConfigureAwait(false);

            var expected = _databaseFixture.TeamListings.Where(x => x.MatchLocations.Any(ml => ml.AdministrativeArea.Contains(query.Query, StringComparison.OrdinalIgnoreCase)));

            Assert.Equal(expected.Count(), result.Count);
            foreach (var team in expected)
            {
                Assert.NotNull(result.SingleOrDefault(x => x.TeamListingId == team.TeamListingId));
            }
        }
Ejemplo n.º 6
0
        public async Task Read_team_listings_returns_basic_fields_for_teams()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            var results = await teamDataSource.ReadTeamListings(null).ConfigureAwait(false);

            foreach (var team in _databaseFixture.Teams.Where(x => x.Club == null))
            {
                var result = results.SingleOrDefault(x => x.TeamListingId == team.TeamId);

                Assert.NotNull(result);
                Assert.Equal(team.TeamName, result.ClubOrTeamName);
                Assert.Equal(team.TeamRoute, result.ClubOrTeamRoute);
                Assert.Equal(team.TeamType, result.TeamType);
                Assert.Equal(!team.UntilYear.HasValue, result.Active);
                Assert.Equal(team.PlayerType, result.PlayerTypes.SingleOrDefault());
            }
        }
Ejemplo n.º 7
0
        public async Task Read_team_listings_supports_filter_by_team_type_for_club_with_no_teams()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);
            var query          = new TeamListingFilter {
                TeamTypes = new List <TeamType?> {
                    null
                }
            };

            var result = await teamDataSource.ReadTeamListings(query).ConfigureAwait(false);

            var expected = _databaseFixture.Clubs.Where(x => !x.Teams.Any());

            Assert.Equal(expected.Count(), result.Count);
            foreach (var listing in expected)
            {
                Assert.NotNull(result.SingleOrDefault(x => x.TeamListingId == listing.ClubId));
            }
        }
Ejemplo n.º 8
0
        public async Task Read_team_listings_sorts_inactive_last()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            var results = await teamDataSource.ReadTeamListings(null).ConfigureAwait(false);

            var expectedActiveStatus = true;

            foreach (var team in results)
            {
                // The first time an inactive team is seen, set a flag to say they must all be inactive
                if (expectedActiveStatus && !team.Active)
                {
                    expectedActiveStatus = false;
                }
                Assert.Equal(expectedActiveStatus, team.Active);
            }
            Assert.False(expectedActiveStatus);
        }
Ejemplo n.º 9
0
        public async Task Read_team_listings_returns_match_locations_for_clubs()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            var results = await teamDataSource.ReadTeamListings(null).ConfigureAwait(false);

            var result = results.SingleOrDefault(x => x.TeamListingId == _databaseFixture.ClubWithTeamsAndMatchLocation.ClubId);

            Assert.NotNull(result);

            foreach (var matchLocation in _databaseFixture.ClubWithTeamsAndMatchLocation.Teams.SelectMany(x => x.MatchLocations))
            {
                var resultMatchLocation = result.MatchLocations.SingleOrDefault(x => x.MatchLocationId == matchLocation.MatchLocationId);
                Assert.NotNull(resultMatchLocation);
                Assert.Equal(matchLocation.SecondaryAddressableObjectName, resultMatchLocation.SecondaryAddressableObjectName);
                Assert.Equal(matchLocation.PrimaryAddressableObjectName, resultMatchLocation.PrimaryAddressableObjectName);
                Assert.Equal(matchLocation.Locality, resultMatchLocation.Locality);
                Assert.Equal(matchLocation.Town, resultMatchLocation.Town);
            }
        }
Ejemplo n.º 10
0
        public async Task Read_team_listings_pages_results()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            const int pageSize   = 10;
            var       pageNumber = 1;
            var       remaining  = _databaseFixture.TeamListings.Count;

            while (remaining > 0)
            {
                var result = await teamDataSource.ReadTeamListings(new TeamListingFilter { Paging = new Paging {
                                                                                               PageNumber = pageNumber, PageSize = pageSize
                                                                                           } }).ConfigureAwait(false);

                var expected = pageSize > remaining ? remaining : pageSize;
                Assert.Equal(expected, result.Count);

                pageNumber++;
                remaining -= pageSize;
            }
        }
Ejemplo n.º 11
0
        public async Task Read_team_listings_supports_filter_by_team_type()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);
            var query          = new TeamListingFilter {
                TeamTypes = new List <TeamType?> {
                    TeamType.Representative
                }
            };

            var result = await teamDataSource.ReadTeamListings(query).ConfigureAwait(false);

            var expected = _databaseFixture.TeamListings
                           .Where(x => _databaseFixture.Teams.Where(t => t.TeamType == TeamType.Representative).Select(t => t.TeamId.Value).Contains(x.TeamListingId.Value) ||
                                  _databaseFixture.Clubs.Where(c => c.Teams.Any(t => t.TeamType == TeamType.Representative)).Select(c => c.ClubId.Value).Contains(x.TeamListingId.Value));

            Assert.Equal(expected.Count(), result.Count);
            foreach (var team in expected)
            {
                Assert.NotNull(result.SingleOrDefault(x => x.TeamListingId == team.TeamListingId));
            }
        }
Ejemplo n.º 12
0
        public async Task Read_team_listings_returns_basic_fields_for_clubs()
        {
            var teamDataSource = new SqlServerTeamListingDataSource(_databaseFixture.ConnectionFactory);

            var results = await teamDataSource.ReadTeamListings(null).ConfigureAwait(false);

            foreach (var club in _databaseFixture.TeamListings.Where(x => _databaseFixture.Clubs.Select(c => c.ClubId.Value).ToList().Contains(x.TeamListingId.Value)))
            {
                var result = results.SingleOrDefault(x => x.TeamListingId == club.TeamListingId);

                Assert.NotNull(result);
                Assert.Equal(club.ClubOrTeamName, result.ClubOrTeamName);
                Assert.Equal(club.ClubOrTeamRoute, result.ClubOrTeamRoute);
                Assert.Equal(club.Active, result.Active);

                Assert.Equal(club.PlayerTypes.Count, result.PlayerTypes.Count);
                foreach (var playerType in club.PlayerTypes)
                {
                    Assert.Contains(playerType, result.PlayerTypes);
                }
            }
        }