Пример #1
0
        private async Task CacheLocation(string postcode, Point coordinate)
        {
            var location = new Location(postcode, coordinate, Location.SourceType.Google);
            await _dbContext.Locations.AddAsync(location);

            await _dbContext.SaveChangesAsync();
        }
Пример #2
0
        private void SeedMockLocations()
        {
            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: DbConfiguration.Wgs84Srid);
            var locations       = new Location[]
            {
                new Location()
                {
                    Postcode = "ky119yu", Coordinate = geometryFactory.CreatePoint(new Coordinate(-3.35870, 56.02748))
                },
                new Location()
                {
                    Postcode = "ca48le", Coordinate = geometryFactory.CreatePoint(new Coordinate(-2.84000, 54.89014))
                },
                new Location()
                {
                    Postcode = "ky62nj", Coordinate = geometryFactory.CreatePoint(new Coordinate(-3.178240, 56.182790))
                },
                new Location()
                {
                    Postcode = "kw14yl", Coordinate = geometryFactory.CreatePoint(new Coordinate(-3.10075, 58.64102))
                },
                new Location()
                {
                    Postcode = "tr182ab", Coordinate = geometryFactory.CreatePoint(new Coordinate(-5.53987, 50.12279))
                },
                new Location()
                {
                    Postcode = "ky6", Coordinate = geometryFactory.CreatePoint(new Coordinate(-3.224217, 56.217468))
                },
            };

            DbContext.Locations.AddRange(locations);
            DbContext.SaveChanges();
        }
Пример #3
0
        private async Task <Point> CoordinateForPostcode(string postcode)
        {
            var sanitizedPostcode = Location.SanitizePostcode(postcode);

            var coordinate = await GeocodePostcodeWithLocalLookup(sanitizedPostcode);

            if (coordinate != null)
            {
                return(coordinate);
            }

            coordinate = await _geocodeClient.GeocodePostcodeAsync(sanitizedPostcode);

            if (coordinate != null)
            {
                await CacheLocation(postcode, coordinate);
            }

            return(coordinate);
        }
Пример #4
0
        public async void SyncAsync_FallbackToGeocodeClient_PopulatesTeachingEventBuildingCoordinatesAndCachesLocation()
        {
            await SeedMockTeachingEventBuildingsAsync();

            SeedMockLocations();
            _mockCrm.Setup(m => m.GetTeachingEvents(It.Is <DateTime>(d => CheckGetTeachingEventsAfterDate(d)))).Returns(MockTeachingEvents);
            var postcode          = "TE7 9IN";
            var coordinate        = new Point(1, 2);
            var sanitizedPostcode = Location.SanitizePostcode(postcode);

            _mockGeocodeClient.Setup(m => m.GeocodePostcodeAsync(sanitizedPostcode))
            .ReturnsAsync(coordinate);
            DbContext.Locations.FirstOrDefault(l => l.Postcode == sanitizedPostcode).Should().BeNull();

            await _store.SyncAsync();

            var teachingEvent = DbContext.TeachingEvents.Include(te => te.Building)
                                .First(te => te.Building.AddressPostcode == postcode);

            teachingEvent.Building.Coordinate.Should().Be(coordinate);
            DbContext.Locations.FirstOrDefault(l => (l.Postcode == sanitizedPostcode) &&
                                               (l.Source == Location.SourceType.Google)).Should().NotBeNull();
        }
Пример #5
0
        private static bool BatchLocationMatchesExistingLocation(dynamic batchLocation, GetIntoTeachingApi.Models.Location existingLocation)
        {
            var postcodeMatch   = batchLocation.Postcode == existingLocation.Postcode;
            var batchCoordinate = Coordinate(batchLocation.Latitude, batchLocation.Longitude);
            var coordinateMatch = batchCoordinate == existingLocation.Coordinate;

            return(postcodeMatch && coordinateMatch);
        }