Beispiel #1
0
        private async Task <string> GetDisplayName(IFeature feature, string language, string title)
        {
            var displayName = title;
            var containers  = await _elasticSearchGateway.GetContainers(feature.Geometry.Coordinate);

            var featureGeometry = feature.Geometry.GetGeometryN(0);
            var container       = containers.Where(c =>
                                                   c.Attributes[FeatureAttributes.ID] != feature.Attributes[FeatureAttributes.ID] &&
                                                   c.Geometry.Covers(featureGeometry) &&
                                                   c.Geometry.EqualsTopologically(featureGeometry) == false)
                                  .OrderBy(c => c.Geometry.Area)
                                  .FirstOrDefault();

            if (container == null)
            {
                return(displayName);
            }
            var address = container.GetTitle(language);

            if (!string.IsNullOrWhiteSpace(address))
            {
                displayName += ", " + address;
            }

            return(displayName);
        }
        public void GetSearchResults_WithPlaceNameThatDoNotExist_ShouldReturnRegularResults()
        {
            var place           = "place";
            var searchTerm      = "searchTerm, " + place;
            var featureLocation = new Coordinate(0.5, 0.5);
            var featureInPlace  = new Feature(new Point(featureLocation), new AttributesTable
            {
                { FeatureAttributes.NAME, "name" },
                {
                    FeatureAttributes.GEOLOCATION,
                    new AttributesTable {
                        { FeatureAttributes.LAT, featureLocation.Y }, { FeatureAttributes.LON, featureLocation.X }
                    }
                },
                { FeatureAttributes.POI_CATEGORY, Categories.HISTORIC },
                { FeatureAttributes.POI_SOURCE, Sources.OSM },
                { FeatureAttributes.ICON, string.Empty },
                { FeatureAttributes.ICON_COLOR, "black" },
                { FeatureAttributes.ID, "id" }
            });

            featureInPlace.SetTitles();
            var featuresInsidePlace = new List <Feature> {
                featureInPlace
            };

            _elasticSearchGateway.SearchPlaces(place, Languages.ENGLISH).Returns(new List <Feature>());
            _elasticSearchGateway.Search("searchTerm", Languages.ENGLISH).Returns(new List <Feature> {
                featureInPlace
            });
            _elasticSearchGateway.GetContainers(featureLocation).Returns(new List <Feature>());

            var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result.ToList();

            Assert.IsNotNull(results);
            Assert.AreEqual(featuresInsidePlace.Count, results.Count);
            Assert.IsFalse(results.First().DisplayName.Contains(place));
        }