コード例 #1
0
        public async Task WebAPI_LocationService_GetLocationByAddress_Should_Fetch_Locations_By_Address()
        {
            #region Arrange

            ILocationService service = new LocationService();

            string city    = "קרית ביאליק";
            string address = "דרך עכו";

            #endregion

            #region Act

            ForwardGeocodingResponse response = await service.GetLocationByAddress(city, address);

            #endregion

            #region Assert

            Assert.IsTrue(response != null &&
                          !response.Results.IsNullOrEmpty() &&
                          response.Results.Count > 0);

            #endregion
        }
コード例 #2
0
        public async Task WebAPI_StoreRepository_UpdateStoreLocation_Should_Update_For_Each_Store()
        {
            #region Arrange

            IEnumerable <Store> allStores = await _storeRepository.GetStoresAsync();

            ILocationService locationService = new LocationService();

            #endregion

            #region Act

            // Validate stores exists
            if (allStores.IsNullOrEmpty())
            {
                throw new Exception("Stores are empty");
            }

            foreach (Store store in allStores)
            {
                // Continue when store already has location
                if (store.Location != null)
                {
                    continue;
                }

                // Continue when city or address are empty
                if (string.IsNullOrWhiteSpace(store.City) ||
                    string.IsNullOrWhiteSpace(store.Address))
                {
                    continue;
                }

                // Fetch location for store
                ForwardGeocodingResponse locationResponse =
                    await locationService.GetLocationByAddress(store.City, store.Address);

                // Continue when results are empty
                if (locationResponse.Results.IsNullOrEmpty())
                {
                    continue;
                }

                ForwardGeocodingResult result = locationResponse.Results.First();

                var geoPointToUpdate = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                    new GeoJson2DGeographicCoordinates(
                        longitude: result.Geometry.Lng,
                        latitude: result.Geometry.Lat));

                await _storeRepository.UpdateStoreLocation(store.ID, geoPointToUpdate);
            }

            #endregion

            // No assert
        }