Пример #1
0
        /// <inheritdoc />
        public override async Task <PointOfInterestExtended> GetPointOfInterestById(string id, string language)
        {
            var featureCollection = await GetFromCacheIfExists(id);

            if (featureCollection == null)
            {
                featureCollection = await _iNatureGateway.GetById(id);

                SetToCache(featureCollection);
            }
            var poiItem = await ConvertToPoiExtended(featureCollection, language);

            poiItem.IsEditable = false;
            poiItem.IsArea     = false;
            var mainFeature = featureCollection.Features.First();

            if (mainFeature.Attributes.Exists(FeatureAttributes.POI_SHARE_REFERENCE))
            {
                var share = await _repository.GetUrlById(mainFeature.Attributes[FeatureAttributes.POI_SHARE_REFERENCE].ToString());

                poiItem.DataContainer = share.DataContainer;
                poiItem.IsRoute       = true;
            }
            else
            {
                poiItem.IsRoute = false;
            }
            return(poiItem);
        }
        /// <inheritdoc />
        public override async Task <Feature> GetRawPointOfInterestById(string id)
        {
            var feature = await _iNatureGateway.GetById(id);

            if (!feature.Attributes.Exists(FeatureAttributes.POI_SHARE_REFERENCE))
            {
                return(feature);
            }
            var share = await _repository.GetUrlById(feature.Attributes[FeatureAttributes.POI_SHARE_REFERENCE].ToString());

            if (share == null)
            {
                return(feature);
            }
            var featureBytes = await _dataContainerConverterService.ToAnyFormat(share.DataContainer, FlowFormats.GEOJSON);

            return(featureBytes.ToFeatureCollection().FirstOrDefault(f => f.Geometry is LineString) as Feature);
        }
        public void GetPointOfInterestById_NotInCache_ShouldGetFromGatewayAndAddShareData()
        {
            var poiId   = "poiId";
            var shareId = "shareId";
            var feature = GetValidFeature(poiId, _adapter.Source);

            feature.Attributes.AddAttribute(FeatureAttributes.POI_SHARE_REFERENCE, shareId);
            _repository.GetUrlById(shareId).Returns(new ShareUrl {
                DataContainer = new DataContainer()
            });
            _iNatureGateway.GetById(poiId).Returns(new FeatureCollection(new Collection <IFeature> {
                feature
            }));
            _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns(new DataContainer {
                Routes = new List <RouteData>()
            });

            var resutls = _adapter.GetPointOfInterestById(poiId, Languages.HEBREW).Result;

            Assert.IsNotNull(resutls);
            _repository.Received(1).GetUrlById(shareId);
        }