public async Task LoadLocationsCleansData(int locationId, string locationName, string localAuthorityName, string locationAuthorityDistrict, int expectedNumberOfLocations)
        {
            //Setup
            A.CallTo(() => fakeNationalStatisticsLocationService.GetLocationsAsync()).Returns(GetTestLocations(locationId, locationName, localAuthorityName, locationAuthorityDistrict));
            var loadLocationsService = new LocationsService(fakeLogger, fakeNationalStatisticsLocationService);

            //Act
            var result = await loadLocationsService.GetCleanLocationsAsync().ConfigureAwait(false);

            //Assert
            A.CallTo(() => fakeNationalStatisticsLocationService.GetLocationsAsync()).MustHaveHappenedOnceExactly();
            result.Count().Should().Be(expectedNumberOfLocations);
        }
Exemple #2
0
        public async Task <IEnumerable <LocationResponse?> > GetCleanLocationsAsync()
        {
            logger.LogInformation("Getting data from ONS");

            var locations = await nationalStatisticsLocationService.GetLocationsAsync().ConfigureAwait(false);

            logger.LogInformation($"Got data from ONS {locations.Count()} records");

            var cleanedItems = locations.Where(item => !string.IsNullOrEmpty(item.Location?.LocationName))
                               .Where(item => !string.IsNullOrEmpty(item.Location?.LocalAuthorityName))
                               .Where(item => !string.IsNullOrEmpty(item.Location?.LocationAuthorityDistrict))
                               .GroupBy(c => new { c.Location?.LocalAuthorityName, c.Location?.LocationName, c.Location?.LocationAuthorityDistrict })
                               .Select(item => item.First())
                               .GroupBy(c => new { c.Location?.Id })
                               .Select(item => item.FirstOrDefault())
                               .Select(item => item.Location);

            logger.LogInformation($"After data cleaning there are {locations.Count()} records");

            return(cleanedItems);
        }