diff --git a/IsraelHiking.API/Controllers/PointsOfInterestController.cs b/IsraelHiking.API/Controllers/PointsOfInterestController.cs index a2a126920..a87e723a4 100644 --- a/IsraelHiking.API/Controllers/PointsOfInterestController.cs +++ b/IsraelHiking.API/Controllers/PointsOfInterestController.cs @@ -87,12 +87,12 @@ public IEnumerable GetCategoriesByGroup(string categoriesGroup) /// A list of GeoJSON features [Route("")] [HttpGet] - public async Task GetPointsOfInterest(string northEast, string southWest, string categories, + public async Task GetPointsOfInterest(string northEast, string southWest, string categories, string language = "") { if (string.IsNullOrWhiteSpace(categories)) { - return Array.Empty(); + return Array.Empty(); } var categoriesArray = categories.Split(',').Select(f => f.Trim()).ToArray(); var northEastCoordinate = northEast.ToCoordinate(); @@ -232,7 +232,7 @@ private string ValidateFeature(Feature feature, string language) /// [HttpGet] [Route("closest")] - public Task GetClosestPoint(string location, string source, string language) + public Task GetClosestPoint(string location, string source, string language) { return _pointsOfInterestProvider.GetClosestPoint(location.ToCoordinate(), source, language); } diff --git a/IsraelHiking.API/Controllers/SearchController.cs b/IsraelHiking.API/Controllers/SearchController.cs index 1fa8817f4..d22501042 100644 --- a/IsraelHiking.API/Controllers/SearchController.cs +++ b/IsraelHiking.API/Controllers/SearchController.cs @@ -44,7 +44,7 @@ public async Task> GetSearchResults(st (term.EndsWith("\"") || term.StartsWith("״"))) { var exactFeatures = await _searchRepository.SearchExact(term.Substring(1, term.Length - 2), language); - return await Task.WhenAll(exactFeatures.OfType().ToList().Select(f => ConvertFromFeature(f, language))); + return await Task.WhenAll(exactFeatures.ToList().Select(f => ConvertFromFeature(f, language))); } if (term.Count(c => c == ',') == 1) { @@ -57,11 +57,11 @@ public async Task> GetSearchResults(st var envelope = placesFeatures.First().Geometry.EnvelopeInternal; var featuresWithinPlaces = await _searchRepository.SearchByLocation( new Coordinate(envelope.MaxX, envelope.MaxY), new Coordinate(envelope.MinX, envelope.MinY), term, language); - return await Task.WhenAll(featuresWithinPlaces.OfType().ToList().Select(f => ConvertFromFeature(f,language))); + return await Task.WhenAll(featuresWithinPlaces.ToList().Select(f => ConvertFromFeature(f,language))); } } var features = await _searchRepository.Search(term, language); - return await Task.WhenAll(features.OfType().ToList().Select(f => ConvertFromFeature(f, language))); + return await Task.WhenAll(features.ToList().Select(f => ConvertFromFeature(f, language))); } private async Task ConvertFromFeature(IFeature feature, string language) diff --git a/IsraelHiking.API/Controllers/UpdateController.cs b/IsraelHiking.API/Controllers/UpdateController.cs index 5759c224a..a4c9d62b5 100644 --- a/IsraelHiking.API/Controllers/UpdateController.cs +++ b/IsraelHiking.API/Controllers/UpdateController.cs @@ -2,7 +2,6 @@ using IsraelHiking.Common.Api; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using System.Text.Json.Serialization; using System.Net; using System.Text.Json; using System.Threading; diff --git a/IsraelHiking.API/Converters/IOsmGeoJsonConverter.cs b/IsraelHiking.API/Converters/IOsmGeoJsonConverter.cs index f4b8101c0..763725e36 100644 --- a/IsraelHiking.API/Converters/IOsmGeoJsonConverter.cs +++ b/IsraelHiking.API/Converters/IOsmGeoJsonConverter.cs @@ -13,6 +13,6 @@ public interface IOsmGeoJsonConverter /// /// The OSM element to convert /// The GeoJson data - Feature ToGeoJson(ICompleteOsmGeo completeOsmGeo); + IFeature ToGeoJson(ICompleteOsmGeo completeOsmGeo); } } \ No newline at end of file diff --git a/IsraelHiking.API/Converters/OsmGeoJsonConverter.cs b/IsraelHiking.API/Converters/OsmGeoJsonConverter.cs index 61a44754c..795be1654 100644 --- a/IsraelHiking.API/Converters/OsmGeoJsonConverter.cs +++ b/IsraelHiking.API/Converters/OsmGeoJsonConverter.cs @@ -31,7 +31,7 @@ public OsmGeoJsonConverter(GeometryFactory geometryFactory) } /// - public Feature ToGeoJson(ICompleteOsmGeo completeOsmGeo) + public IFeature ToGeoJson(ICompleteOsmGeo completeOsmGeo) { if (completeOsmGeo?.Tags == null || completeOsmGeo.Tags.Count == 0) { diff --git a/IsraelHiking.API/Executors/ElevationSetterHelper.cs b/IsraelHiking.API/Executors/ElevationSetterHelper.cs index b973e71bc..8db541014 100644 --- a/IsraelHiking.API/Executors/ElevationSetterHelper.cs +++ b/IsraelHiking.API/Executors/ElevationSetterHelper.cs @@ -73,7 +73,7 @@ public static void SetElevation(Geometry geometry, IElevationGateway elevationGa /// /// The features to update /// The elevation gateway - public static void SetElevation(IEnumerable features, IElevationGateway elevationGateway) + public static void SetElevation(IEnumerable features, IElevationGateway elevationGateway) { foreach (var feature in features) { diff --git a/IsraelHiking.API/Executors/ExternalSourceUpdaterExecutor.cs b/IsraelHiking.API/Executors/ExternalSourceUpdaterExecutor.cs index c7acfc0f1..39c192c95 100644 --- a/IsraelHiking.API/Executors/ExternalSourceUpdaterExecutor.cs +++ b/IsraelHiking.API/Executors/ExternalSourceUpdaterExecutor.cs @@ -71,14 +71,13 @@ public async Task RebuildSource(string currentSource) _logger.LogInformation($"Finished rebuilding {currentSource}, indexed {features.Count} points."); } - private void UpdateAltitude(List features) + private void UpdateAltitude(List features) { var coordinates = features.Select(f => f.GetLocation()).ToArray(); var elevationValues = _elevationGateway.GetElevation(coordinates).Result; for (var index = 0; index < features.Count; index++) { var feature = features[index]; - var geoLocationCoordinate = feature.GetLocation(); feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ALT, elevationValues[index]); } } diff --git a/IsraelHiking.API/Executors/FeaturesMergeExecutor.cs b/IsraelHiking.API/Executors/FeaturesMergeExecutor.cs index 31f8f13b2..1264d9609 100644 --- a/IsraelHiking.API/Executors/FeaturesMergeExecutor.cs +++ b/IsraelHiking.API/Executors/FeaturesMergeExecutor.cs @@ -20,9 +20,9 @@ namespace IsraelHiking.API.Executors /// Features that are ordered first will be the target of the merge /// while features that are ordered last will be the source of the merge. /// - internal class FeatureComparer : IComparer + internal class FeatureComparer : IComparer { - public int Compare(Feature x, Feature y) + public int Compare(IFeature x, IFeature y) { if (x.Geometry is Point && y.Geometry is Point) { @@ -72,7 +72,7 @@ public class FeaturesMergeExecutor : IFeaturesMergeExecutor } /// - public List Merge(List osmFeatures, List externalFeatures) + public List Merge(List osmFeatures, List externalFeatures) { AddAlternativeTitleToNatureReserves(osmFeatures); externalFeatures = MergeWikipediaToOsmByWikipediaTags(osmFeatures, externalFeatures); @@ -93,7 +93,7 @@ public List Merge(List osmFeatures, List externalFeat return all; } - private List MergeOsmElementsByName(List orderedOsmFeatures, string nameAttribute) + private List MergeOsmElementsByName(List orderedOsmFeatures, string nameAttribute) { _logger.LogInformation($"Starting OSM merging by {nameAttribute}."); var featureIdsToRemove = new ConcurrentBag(); @@ -137,11 +137,11 @@ private List MergeOsmElementsByName(List orderedOsmFeatures, s return orderedOsmFeatures; } - private List MergeExternalFeaturesToOsm(List osmFeatures, List externalFeatures) + private List MergeExternalFeaturesToOsm(List osmFeatures, List externalFeatures) { var featureIdsToRemove = new HashSet(); _logger.LogInformation("Starting external features merging by title into OSM."); - var titlesDictionary = new Dictionary>(); + var titlesDictionary = new Dictionary>(); foreach (var osmFeature in osmFeatures) { foreach (var title in osmFeature.GetTitles()) @@ -152,7 +152,7 @@ private List MergeExternalFeaturesToOsm(List osmFeatures, List } else { - titlesDictionary[title] = new List { osmFeature }; + titlesDictionary[title] = new List { osmFeature }; } } } @@ -176,7 +176,7 @@ private List MergeExternalFeaturesToOsm(List osmFeatures, List return externalFeatures; } - private List MergePlaceNodes(List osmFeatures) + private List MergePlaceNodes(List osmFeatures) { var featureIdsToRemove = new ConcurrentBag(); var containers = osmFeatures.Where(IsPlaceContainer).OrderBy(f => f.Geometry.Area).ToList(); @@ -200,9 +200,9 @@ private List MergePlaceNodes(List osmFeatures) return osmFeatures.Where(f => list.Contains(f.GetId()) == false).ToList(); } - private bool IsPlaceContainer(Feature feature) + private bool IsPlaceContainer(IFeature feature) { - if (!(feature.Geometry is Polygon) && !(feature.Geometry is MultiPolygon)) + if (feature.Geometry is not Polygon && feature.Geometry is not MultiPolygon) { return false; } @@ -225,7 +225,7 @@ private bool IsPlaceContainer(Feature feature) return false; } - private List UpdatePlacesGeometry(Feature feature, List places) + private List UpdatePlacesGeometry(IFeature feature, List places) { var placeContainers = places.Where(c => IsPlaceContainerContainsFeature(c, feature)) .OrderBy(f => f.Geometry.Area) @@ -243,7 +243,7 @@ private List UpdatePlacesGeometry(Feature feature, List places return placeContainers; } - private bool IsPlaceContainerContainsFeature(Feature container, Feature feature) + private bool IsPlaceContainerContainsFeature(IFeature container, IFeature feature) { try { @@ -270,7 +270,7 @@ private bool IsPlaceContainerContainsFeature(Feature container, Feature feature) return false; } - private void SimplifyGeometriesCollection(List results) + private void SimplifyGeometriesCollection(List results) { foreach (var feature in results) { @@ -366,7 +366,7 @@ private void SimplifyGeometriesCollection(List results) } } - private void WriteToReport(Feature featureToMergeTo, Feature feature) + private void WriteToReport(IFeature featureToMergeTo, IFeature feature) { if (!_options.WriteMergeReport) { @@ -386,7 +386,7 @@ private void WriteToReport(Feature featureToMergeTo, Feature feature) _reportLogger.LogInformation(from + " " + to); } - private string GetWebsite(Feature feature) + private string GetWebsite(IFeature feature) { if (feature.Attributes.Exists(FeatureAttributes.WEBSITE)) { @@ -402,7 +402,7 @@ private string GetWebsite(Feature feature) return string.Empty; } - private void MergeFeatures(Feature featureToMergeTo, Feature feature) + private void MergeFeatures(IFeature featureToMergeTo, IFeature feature) { if (featureToMergeTo.GetId().Equals(feature.GetId())) { @@ -447,7 +447,7 @@ private void MergeFeatures(Feature featureToMergeTo, Feature feature) WriteToReport(featureToMergeTo, feature); } - private bool CanMerge(Feature target, Feature source) + private bool CanMerge(IFeature target, IFeature source) { if (target.GetId().Equals(source.GetId())) { @@ -514,7 +514,7 @@ private bool CanMerge(Feature target, Feature source) /// /// /// - private bool IsFeaturesTagsMismatched(Feature target, Feature source, string tagName) { + private bool IsFeaturesTagsMismatched(IFeature target, IFeature source, string tagName) { return target.Attributes[FeatureAttributes.POI_SOURCE].Equals(Sources.OSM) && (target.Attributes.GetNames().Contains(tagName) && !source.Attributes.GetNames().Contains(tagName) || @@ -522,7 +522,7 @@ private bool CanMerge(Feature target, Feature source) source.Attributes.GetNames().Contains(tagName)); } - private List MergeWikipediaToOsmByWikipediaTags(List osmFeatures, List externalFeatures) + private List MergeWikipediaToOsmByWikipediaTags(List osmFeatures, List externalFeatures) { WriteToBothLoggers("Starting joining Wikipedia markers."); var featureIdsToRemove = new HashSet(); @@ -550,7 +550,7 @@ private List MergeWikipediaToOsmByWikipediaTags(List osmFeatur return externalFeatures.Where(f => featureIdsToRemove.Contains(f.GetId()) == false).ToList(); } - private void AddAlternativeTitleToNatureReserves(List features) + private void AddAlternativeTitleToNatureReserves(List features) { WriteToBothLoggers("Starting adding alternative names to nature reserves"); var natureReserveFeatures = features.Where(f => f.Attributes[FeatureAttributes.POI_ICON].Equals("icon-nature-reserve")).ToList(); @@ -595,7 +595,7 @@ private void WriteToBothLoggers(string message) _reportLogger.LogInformation(message + "
"); } - private void MergeTitles(Feature target, Feature source) + private void MergeTitles(IFeature target, IFeature source) { if (!(target.Attributes[FeatureAttributes.POI_NAMES] is AttributesTable targetTitlesByLanguage)) { @@ -625,7 +625,7 @@ private void MergeTitles(Feature target, Feature source) /// /// /// - private void MergeDescriptionAndAuthor(Feature target, Feature source) + private void MergeDescriptionAndAuthor(IFeature target, IFeature source) { foreach (var languagePostfix in Languages.Array.Select(s => ":" + s).Concat(new[] { string.Empty })) { @@ -648,7 +648,7 @@ private void MergeDescriptionAndAuthor(Feature target, Feature source) } } - private void MergeDates(Feature target, Feature source) + private void MergeDates(IFeature target, IFeature source) { if (target.GetLastModified() < source.GetLastModified()) { @@ -656,7 +656,7 @@ private void MergeDates(Feature target, Feature source) } } - private void MergeWebsite(Feature target, Feature source) + private void MergeWebsite(IFeature target, IFeature source) { var websiteUrls = target.Attributes.GetNames().Where(n => n.StartsWith(FeatureAttributes.WEBSITE)) .Select(key => target.Attributes[key]).ToList(); @@ -690,7 +690,7 @@ private void MergeWebsite(Feature target, Feature source) } } - private void MergeImages(Feature target, Feature source) + private void MergeImages(IFeature target, IFeature source) { var imagesUrls = target.Attributes.GetNames().Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL)) .Select(key => target.Attributes[key]).ToList(); @@ -713,7 +713,7 @@ private void MergeImages(Feature target, Feature source) } } - private void CopyKeysIfExist(Feature target, Feature source, params string[] attributeKeys) + private void CopyKeysIfExist(IFeature target, IFeature source, params string[] attributeKeys) { foreach (var key in attributeKeys) { diff --git a/IsraelHiking.API/Executors/IFeaturesMergeExecutor.cs b/IsraelHiking.API/Executors/IFeaturesMergeExecutor.cs index b15341a14..ab749f5b7 100644 --- a/IsraelHiking.API/Executors/IFeaturesMergeExecutor.cs +++ b/IsraelHiking.API/Executors/IFeaturesMergeExecutor.cs @@ -14,6 +14,6 @@ public interface IFeaturesMergeExecutor /// /// /// - List Merge(List osmFeatures, List externalFeatures); + List Merge(List osmFeatures, List externalFeatures); } } \ No newline at end of file diff --git a/IsraelHiking.API/Executors/IOsmGeoJsonPreprocessorExecutor.cs b/IsraelHiking.API/Executors/IOsmGeoJsonPreprocessorExecutor.cs index 0cc85b03a..541fdd7b5 100644 --- a/IsraelHiking.API/Executors/IOsmGeoJsonPreprocessorExecutor.cs +++ b/IsraelHiking.API/Executors/IOsmGeoJsonPreprocessorExecutor.cs @@ -14,12 +14,12 @@ public interface IOsmGeoJsonPreprocessorExecutor /// /// /// a list of preprocessed features - List Preprocess(List osmEntities); + List Preprocess(List osmEntities); /// /// Preprocess highways into features - line strings /// /// /// - List Preprocess(List highways); + List Preprocess(List highways); } } \ No newline at end of file diff --git a/IsraelHiking.API/Executors/IPointsOfInterestFilesCreatorExecutor.cs b/IsraelHiking.API/Executors/IPointsOfInterestFilesCreatorExecutor.cs index 9b8b90c49..b50a4f55e 100644 --- a/IsraelHiking.API/Executors/IPointsOfInterestFilesCreatorExecutor.cs +++ b/IsraelHiking.API/Executors/IPointsOfInterestFilesCreatorExecutor.cs @@ -12,12 +12,12 @@ public interface IPointsOfInterestFilesCreatorExecutor /// This function creates the sitemap.xml file inside the wwwroot folder /// /// - void CreateSiteMapXmlFile(List features); + void CreateSiteMapXmlFile(List features); /// /// This function creates the pois-slim.geojson file inside the wwwroot folder /// /// - void CreateOfflinePoisFile(List features); + void CreateOfflinePoisFile(List features); } } \ No newline at end of file diff --git a/IsraelHiking.API/Executors/OsmGeoJsonPreprocessorExecutor.cs b/IsraelHiking.API/Executors/OsmGeoJsonPreprocessorExecutor.cs index 02bdd8927..db396251c 100644 --- a/IsraelHiking.API/Executors/OsmGeoJsonPreprocessorExecutor.cs +++ b/IsraelHiking.API/Executors/OsmGeoJsonPreprocessorExecutor.cs @@ -40,7 +40,7 @@ public class OsmGeoJsonPreprocessorExecutor : IOsmGeoJsonPreprocessorExecutor } /// - public List Preprocess(List osmEntities) + public List Preprocess(List osmEntities) { _logger.LogInformation("Preprocessing OSM data to GeoJson, total entities: " + osmEntities.Count); osmEntities = RemoveDuplicateWaysThatExistInRelations(osmEntities); @@ -85,7 +85,7 @@ private List RemoveDuplicateWaysThatExistInRelations(List - public List Preprocess(List highways) + public List Preprocess(List highways) { var highwayFeatures = highways.Select(_osmGeoJsonConverter.ToGeoJson).Where(h => h != null).ToList(); foreach (var highwayFeature in highwayFeatures) @@ -136,10 +136,10 @@ public List Preprocess(List highways) /// This is a static function to update the geolocation of a feature for search capabilities /// /// - private void UpdateLocation(Feature feature) + private void UpdateLocation(IFeature feature) { Coordinate geoLocation; - if ((feature.Geometry is LineString || feature.Geometry is MultiLineString) && feature.Geometry.Coordinate != null) + if (feature.Geometry is LineString or MultiLineString && feature.Geometry.Coordinate != null) { geoLocation = feature.Geometry.Coordinate; } @@ -154,7 +154,7 @@ private void UpdateLocation(Feature feature) feature.Attributes.SetLocation(geoLocation); } - private void UpdateAltitude(List features) + private void UpdateAltitude(List features) { _logger.LogInformation("Starting to get altitude for features " + features.Count); var coordinates = features.Select(f => f.GetLocation()).ToArray(); diff --git a/IsraelHiking.API/Executors/PointsOfInterestFilesCreatorExecutor.cs b/IsraelHiking.API/Executors/PointsOfInterestFilesCreatorExecutor.cs index 7911f012b..e70f7713c 100644 --- a/IsraelHiking.API/Executors/PointsOfInterestFilesCreatorExecutor.cs +++ b/IsraelHiking.API/Executors/PointsOfInterestFilesCreatorExecutor.cs @@ -52,7 +52,7 @@ public class PointsOfInterestFilesCreatorExecutor : IPointsOfInterestFilesCreato } /// - public void CreateSiteMapXmlFile(List features) + public void CreateSiteMapXmlFile(List features) { using var fileStream = _fileSystemHelper.CreateWriteStream(Path.Combine(_environment.WebRootPath, "sitemap.xml")); var list = features.Where(f => Languages.Array.Any(l => f.IsProperPoi(l))).Select(feature => @@ -75,7 +75,7 @@ public void CreateSiteMapXmlFile(List features) } /// - public void CreateOfflinePoisFile(List features) + public void CreateOfflinePoisFile(List features) { using var outputMemStream = new MemoryStream(); using var zipStream = new ZipOutputStream(outputMemStream); diff --git a/IsraelHiking.API/Executors/SimplePointAdderExecutor.cs b/IsraelHiking.API/Executors/SimplePointAdderExecutor.cs index 0400b13dd..08b8b2121 100644 --- a/IsraelHiking.API/Executors/SimplePointAdderExecutor.cs +++ b/IsraelHiking.API/Executors/SimplePointAdderExecutor.cs @@ -110,7 +110,7 @@ private bool NeedsToBeAddedToClosestLine(SimplePointType pointType) /// /// /// The way from OSM and the equivalent feature, and also all the other closest highways - private async Task<(Way, Feature[])> GetClosestHighways(IAuthClient osmGateway, LatLng latLng) + private async Task<(Way, IFeature[])> GetClosestHighways(IAuthClient osmGateway, LatLng latLng) { var diff = 0.003; // get highways around 300 m radius not to miss highways (elastic bug?) var highways = await _highwaysRepository.GetHighways(new Coordinate(latLng.Lng + diff, latLng.Lat + diff), @@ -169,7 +169,7 @@ private double DistanceToPolygon(Polygon polygon, Point point) /// /// /// The closest node, its index in the way and whether it is a junction node - private (Coordinate, int, long, bool) GetClosestNodeAndCheckIsJunction(LatLng latLng, Feature[] closestHighways) + private (Coordinate, int, long, bool) GetClosestNodeAndCheckIsJunction(LatLng latLng, IFeature[] closestHighways) { var coordinate = latLng.ToCoordinate(); var closestHighway = closestHighways.First(); @@ -233,7 +233,7 @@ private async Task GetOsmChange(IAuthClient osmGateway, AddSimplePoin }; } - private int GetIndexToInsert(int closetNodeIndex, Coordinate closestNodeCoordinate, Feature[] closestHighways, Coordinate newNodeCoordinate) + private int GetIndexToInsert(int closetNodeIndex, Coordinate closestNodeCoordinate, IFeature[] closestHighways, Coordinate newNodeCoordinate) { // Default location is before the closest node var indexToInsert = closetNodeIndex; @@ -272,7 +272,7 @@ private int GetIndexToInsert(int closetNodeIndex, Coordinate closestNodeCoordina return indexToInsert; } - private OsmChange CreateUpdateWayChangeFromData(Way way, int indexToInsert, Node newNode, Feature closestHighway) + private OsmChange CreateUpdateWayChangeFromData(Way way, int indexToInsert, Node newNode, IFeature closestHighway) { if (indexToInsert != 0 && indexToInsert != way.Nodes.Length) { diff --git a/IsraelHiking.API/Gpx/SerializarionExtensions.cs b/IsraelHiking.API/Gpx/SerializarionExtensions.cs index 3d8b2a307..26476f8c2 100644 --- a/IsraelHiking.API/Gpx/SerializarionExtensions.cs +++ b/IsraelHiking.API/Gpx/SerializarionExtensions.cs @@ -1,8 +1,6 @@ using IsraelHiking.API.Converters; using NetTopologySuite.Features; -using NetTopologySuite.Geometries; using NetTopologySuite.IO; -using System.Text.Json.Serialization; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; diff --git a/IsraelHiking.API/Services/Osm/IOsmLineAdderService.cs b/IsraelHiking.API/Services/Osm/IOsmLineAdderService.cs index 159e9bbfa..ca0fc342e 100644 --- a/IsraelHiking.API/Services/Osm/IOsmLineAdderService.cs +++ b/IsraelHiking.API/Services/Osm/IOsmLineAdderService.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Threading.Tasks; -using IsraelHiking.Common; using NetTopologySuite.Geometries; using OsmSharp.IO.API; diff --git a/IsraelHiking.API/Services/Osm/OsmLineAdderService.cs b/IsraelHiking.API/Services/Osm/OsmLineAdderService.cs index a2b02df56..b9183f8c6 100644 --- a/IsraelHiking.API/Services/Osm/OsmLineAdderService.cs +++ b/IsraelHiking.API/Services/Osm/OsmLineAdderService.cs @@ -168,7 +168,7 @@ private static bool CanAddNewNode(List newWayNodes, long newNodeId) /// /// private void AddIntersectingNodes(Coordinate previousCoordinate, Coordinate coordinate, List newWayNodes, - List itmHighways, List highways) + List itmHighways, List highways) { var previousItmPoint = GetItmCoordinate(previousCoordinate); var lineSegment = _geometryFactory.CreateLineString(new [] { previousItmPoint.Coordinate, GetItmCoordinate(coordinate).Coordinate}); @@ -238,7 +238,7 @@ private int GetIndexToInsert(int indexOnWay, LineString closestItmHighway, Point return indexToInsert; } - private async Task> GetHighwaysInArea(LineString line) + private async Task> GetHighwaysInArea(LineString line) { var northEast = _wgs84ItmMathTransform.Transform(line.Coordinates.Max(c => c.X), line.Coordinates.Max(c => c.Y)); var southWest = _wgs84ItmMathTransform.Transform(line.Coordinates.Min(c => c.X), line.Coordinates.Min(c => c.Y)); @@ -261,7 +261,7 @@ private Point GetItmCoordinate(Coordinate coordinate) return new Point(northEast.x, northEast.y); } - private Feature GetClosetHighway(Coordinate coordinate, List itmHighways, List highways) + private IFeature GetClosetHighway(Coordinate coordinate, List itmHighways, List highways) { var point = GetItmCoordinate(coordinate); if (!itmHighways.Any()) @@ -271,14 +271,12 @@ private Feature GetClosetHighway(Coordinate coordinate, List itmHigh var closestHighway = itmHighways.Where(l => l.Distance(point) <= _options.MaxDistanceToExistingLineForMerge) .OrderBy(l => l.Distance(point)) .FirstOrDefault(); - if (closestHighway == null) - { - return null; - } - return highways.First(h => h.GetOsmId() == closestHighway.GetOsmId()); + return closestHighway == null + ? null + : highways.First(h => h.GetOsmId() == closestHighway.GetOsmId()); } - private LineString ToItmLineString(Feature feature) + private LineString ToItmLineString(IFeature feature) { var itmCoordinates = feature.Geometry.Coordinates.Select(c => _wgs84ItmMathTransform.Transform(c.X, c.Y)).Select(c => new Coordinate(c.x, c.y)).ToArray(); var lineString = new LineString(itmCoordinates); @@ -374,7 +372,7 @@ private void CloseLoopWithStartPointIfNeeded(List newWayNodes) newWayNodes.Insert(itmLine.Coordinates.ToList().IndexOf(closestSegment.P1), newWayNodes.First()); } - private Node CreateNodeFromExistingHighway(Feature closetHighway, int indexOnWay) + private Node CreateNodeFromExistingHighway(IFeature closetHighway, int indexOnWay) { var closestNodeId = long.Parse(((List)closetHighway.Attributes[FeatureAttributes.POI_OSM_NODES])[indexOnWay].ToString()); return new Node diff --git a/IsraelHiking.API/Services/Poi/CsvPointsOfInterestAdapter.cs b/IsraelHiking.API/Services/Poi/CsvPointsOfInterestAdapter.cs index 365eeb0e5..7af9c6386 100644 --- a/IsraelHiking.API/Services/Poi/CsvPointsOfInterestAdapter.cs +++ b/IsraelHiking.API/Services/Poi/CsvPointsOfInterestAdapter.cs @@ -115,7 +115,7 @@ public class CsvPointsOfInterestAdapter : IPointsOfInterestAdapter } /// - /// This method is used as late initialiation for setting file name and address + /// This method is used as late initialization for setting file name and address /// /// /// @@ -126,7 +126,7 @@ public void SetFileNameAndAddress(string fileName, string fileAddress) } /// - public async Task> GetAll() + public async Task> GetAll() { var features = await GetAllFeaturesWithoutGeometry(); foreach (var feature in features) @@ -136,7 +136,7 @@ public async Task> GetAll() return features; } - private Feature ConvertCsvRowToFeature(CsvPointOfInterestRow pointOfInterest) + private IFeature ConvertCsvRowToFeature(CsvPointOfInterestRow pointOfInterest) { var table = new AttributesTable { @@ -175,7 +175,7 @@ private IEnumerable GetRecords(Stream stream) } /// - private async Task UpdateGeometry(Feature feature) + private async Task UpdateGeometry(IFeature feature) { if (feature.Attributes.Exists(FeatureAttributes.POI_SHARE_REFERENCE) && !string.IsNullOrWhiteSpace(feature.Attributes[FeatureAttributes.POI_SHARE_REFERENCE].ToString())) @@ -187,7 +187,7 @@ private async Task UpdateGeometry(Feature feature) } /// - public async Task> GetUpdates(DateTime lastModifiedDate) + public async Task> GetUpdates(DateTime lastModifiedDate) { var features = await GetAllFeaturesWithoutGeometry(); features = features.Where(f => f.GetLastModified() > lastModifiedDate).ToList(); @@ -198,7 +198,7 @@ public async Task> GetUpdates(DateTime lastModifiedDate) return features; } - private async Task> GetAllFeaturesWithoutGeometry() + private async Task> GetAllFeaturesWithoutGeometry() { _logger.LogInformation("Getting records from csv file: " + _fileName); var fileContent = await _remoteFileFetcherGateway.GetFileContent(_fileAddress); diff --git a/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs b/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs index 6b4869e1d..04b305ccb 100644 --- a/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs +++ b/IsraelHiking.API/Services/Poi/INaturePointsOfInterestAdapter.cs @@ -45,7 +45,7 @@ public class INaturePointsOfInterestAdapter : IPointsOfInterestAdapter public string Source => Sources.INATURE; /// - public async Task> GetAll() + public async Task> GetAll() { _logger.LogInformation("Getting data from iNature."); var features = await _iNatureGateway.GetAll(); @@ -57,7 +57,7 @@ public async Task> GetAll() return features; } - private async Task UpdateGeometry(Feature feature) + private async Task UpdateGeometry(IFeature feature) { if (!feature.Attributes.Exists(FeatureAttributes.POI_SHARE_REFERENCE)) { @@ -74,7 +74,7 @@ private async Task UpdateGeometry(Feature feature) } /// - public async Task> GetUpdates(DateTime lastModifiedDate) + public async Task> GetUpdates(DateTime lastModifiedDate) { return await _iNatureGateway.GetUpdates(lastModifiedDate); } diff --git a/IsraelHiking.API/Services/Poi/IPointsOfInterestAdapter.cs b/IsraelHiking.API/Services/Poi/IPointsOfInterestAdapter.cs index fff405d7c..67b6a6e9c 100644 --- a/IsraelHiking.API/Services/Poi/IPointsOfInterestAdapter.cs +++ b/IsraelHiking.API/Services/Poi/IPointsOfInterestAdapter.cs @@ -19,12 +19,12 @@ public interface IPointsOfInterestAdapter /// Get all the points from the adapter in order to index them in a database /// /// - Task> GetAll(); + Task> GetAll(); /// /// Get all the points' updates from the adapter in order to index them in a database /// /// - Task> GetUpdates(DateTime lastModifiedDate); + Task> GetUpdates(DateTime lastModifiedDate); } } diff --git a/IsraelHiking.API/Services/Poi/IPointsOfInterestProvider.cs b/IsraelHiking.API/Services/Poi/IPointsOfInterestProvider.cs index e4ebd7df3..11ac83b70 100644 --- a/IsraelHiking.API/Services/Poi/IPointsOfInterestProvider.cs +++ b/IsraelHiking.API/Services/Poi/IPointsOfInterestProvider.cs @@ -19,7 +19,7 @@ public interface IPointsOfInterestProvider /// /// /// - Task GetFeatureById(string source, string id); + Task GetFeatureById(string source, string id); /// /// Gets all the POIs within the bounding box that matches the given categories in the given language @@ -29,7 +29,7 @@ public interface IPointsOfInterestProvider /// The categories /// The language /// An array of POIs - Task GetFeatures(Coordinate northEast, Coordinate southWest, string[] categories, string language); + Task GetFeatures(Coordinate northEast, Coordinate southWest, string[] categories, string language); /// /// Adds a POI @@ -38,7 +38,7 @@ public interface IPointsOfInterestProvider /// /// /// - Task AddFeature(Feature feature, IAuthClient osmGateway, string language); + Task AddFeature(IFeature feature, IAuthClient osmGateway, string language); /// /// Updates a POI @@ -47,7 +47,7 @@ public interface IPointsOfInterestProvider /// /// The relevant language /// - Task UpdateFeature(Feature partialFeature, IAuthClient osmGateway, string language); + Task UpdateFeature(IFeature partialFeature, IAuthClient osmGateway, string language); /// /// Get the closest point to the given location, only for the given source @@ -56,7 +56,7 @@ public interface IPointsOfInterestProvider /// Source is optional /// /// - public Task GetClosestPoint(Coordinate location, string source, string language = ""); + public Task GetClosestPoint(Coordinate location, string source, string language = ""); /// /// Get the all the points that were undated since the given date, and up until a given data @@ -70,6 +70,6 @@ public interface IPointsOfInterestProvider /// Get all points from the OSM repository /// /// - public Task> GetAll(); + public Task> GetAll(); } } diff --git a/IsraelHiking.API/Services/Poi/NakebPointsOfInterestAdapter.cs b/IsraelHiking.API/Services/Poi/NakebPointsOfInterestAdapter.cs index 77a377ecc..77a73a29d 100644 --- a/IsraelHiking.API/Services/Poi/NakebPointsOfInterestAdapter.cs +++ b/IsraelHiking.API/Services/Poi/NakebPointsOfInterestAdapter.cs @@ -33,11 +33,11 @@ public class NakebPointsOfInterestAdapter : IPointsOfInterestAdapter } /// - public async Task> GetAll() + public async Task> GetAll() { _logger.LogInformation("Getting data from Nakeb."); var slimFeatures = await _nakebGateway.GetAll(); - var features = new List(); + var features = new List(); foreach (var slimFeature in slimFeatures) { features.Add(await _nakebGateway.GetById(slimFeature.Attributes[FeatureAttributes.ID].ToString())); @@ -47,10 +47,10 @@ public async Task> GetAll() } /// - public async Task> GetUpdates(DateTime lastModifiedDate) + public async Task> GetUpdates(DateTime lastModifiedDate) { var slimFeatures = await _nakebGateway.GetAll(); - var features = new List(); + var features = new List(); foreach (var slimFeature in slimFeatures.Where(f => f.GetLastModified() > lastModifiedDate)) { features.Add(await _nakebGateway.GetById(slimFeature.Attributes[FeatureAttributes.ID].ToString())); diff --git a/IsraelHiking.API/Services/Poi/PointsOfInterestProvider.cs b/IsraelHiking.API/Services/Poi/PointsOfInterestProvider.cs index db797f876..60e8efed3 100644 --- a/IsraelHiking.API/Services/Poi/PointsOfInterestProvider.cs +++ b/IsraelHiking.API/Services/Poi/PointsOfInterestProvider.cs @@ -46,7 +46,6 @@ public class PointsOfInterestProvider : IPointsOfInterestProvider private readonly IBase64ImageStringToFileConverter _base64ImageConverter; private readonly IImagesUrlsStorageExecutor _imageUrlStoreExecutor; private readonly ILogger _logger; - private readonly MathTransform _wgs84ItmMathTransform; private readonly ConfigurationData _options; /// @@ -56,7 +55,6 @@ public class PointsOfInterestProvider : IPointsOfInterestProvider /// /// /// - /// /// /// /// @@ -68,7 +66,6 @@ public class PointsOfInterestProvider : IPointsOfInterestProvider IElevationGateway elevationGateway, IOsmGeoJsonPreprocessorExecutor osmGeoJsonPreprocessorExecutor, IOsmRepository osmRepository, - IItmWgs84MathTransfromFactory itmWgs84MathTransformFactory, IOsmLatestFileGateway latestFileGateway, IWikimediaCommonGateway wikimediaCommonGateway, IBase64ImageStringToFileConverter base64ImageConverter, @@ -82,7 +79,6 @@ public class PointsOfInterestProvider : IPointsOfInterestProvider _tagsHelper = tagsHelper; _latestFileGateway = latestFileGateway; _elevationGateway = elevationGateway; - _wgs84ItmMathTransform = itmWgs84MathTransformFactory.CreateInverse(); _options = options.Value; _pointsOfInterestRepository = pointsOfInterestRepository; _wikimediaCommonGateway = wikimediaCommonGateway; @@ -114,7 +110,7 @@ private bool UpdateLocationIfNeeded(ICompleteOsmGeo completeOsmGeo, LatLng locat } /// - public async Task> GetAll() + public async Task> GetAll() { _logger.LogInformation("Starting getting OSM points of interest"); await using var stream = await _latestFileGateway.Get(); @@ -125,13 +121,13 @@ public async Task> GetAll() return features; } - private Feature ConvertOsmToFeature(ICompleteOsmGeo osm) + private IFeature ConvertOsmToFeature(ICompleteOsmGeo osm) { var features = _osmGeoJsonPreprocessorExecutor.Preprocess(new List {osm}); return features.Any() ? features.First() : null; } - private async Task UpdateElasticSearch(ICompleteOsmGeo osm) + private async Task UpdateElasticSearch(ICompleteOsmGeo osm) { var feature = ConvertOsmToFeature(osm); if (feature == null) @@ -154,7 +150,7 @@ private async Task UpdateElasticSearch(ICompleteOsmGeo osm) } } feature.SetLastModified(DateTime.Now); - await _pointsOfInterestRepository.UpdatePointsOfInterestData(new List { feature }); + await _pointsOfInterestRepository.UpdatePointsOfInterestData(new List { feature }); return feature; } @@ -262,7 +258,7 @@ private void SetMultipleValuesForTag(TagsCollectionBase tags, string tagKey, str } /// - public async Task GetClosestPoint(Coordinate location, string source, string language = "") + public async Task GetClosestPoint(Coordinate location, string source, string language = "") { var distance = _options.ClosestPointsOfInterestThreshold; var results = await _pointsOfInterestRepository.GetPointsOfInterest( @@ -293,7 +289,7 @@ public async Task GetUpdates(DateTime lastModifiedDate, DateTim } /// - public async Task GetFeatureById(string source, string id) + public async Task GetFeatureById(string source, string id) { var feature = await _pointsOfInterestRepository.GetPointOfInterestById(id, source); if (feature != null) { @@ -307,7 +303,7 @@ public async Task GetFeatureById(string source, string id) } /// - public async Task GetFeatures(Coordinate northEast, Coordinate southWest, string[] categories, string language) + public async Task GetFeatures(Coordinate northEast, Coordinate southWest, string[] categories, string language) { var features = await _pointsOfInterestRepository.GetPointsOfInterest(northEast, southWest, categories, language); var points = features.Where(f => f.IsProperPoi(language)).ToArray(); @@ -324,7 +320,7 @@ public async Task GetFeatures(Coordinate northEast, Coordinate southW } /// - public async Task AddFeature(Feature feature, IAuthClient osmGateway, string language) + public async Task AddFeature(IFeature feature, IAuthClient osmGateway, string language) { var icon = feature.Attributes[FeatureAttributes.POI_ICON].ToString(); var location = feature.GetLocation(); @@ -358,7 +354,7 @@ public async Task AddFeature(Feature feature, IAuthClient osmGateway, s } /// - public async Task UpdateFeature(Feature partialFeature, IAuthClient osmGateway, string language) + public async Task UpdateFeature(IFeature partialFeature, IAuthClient osmGateway, string language) { ICompleteOsmGeo completeOsmGeo = await osmGateway.GetCompleteElement(partialFeature.GetOsmId(), partialFeature.GetOsmType()); var featureBeforeUpdate = await _pointsOfInterestRepository.GetPointOfInterestById(partialFeature.Attributes[FeatureAttributes.ID].ToString(), Sources.OSM); @@ -478,7 +474,7 @@ private async Task UpdateLists(IFeature partialFeature, ICompleteOsmGeo complete SetMultipleValuesForTag(completeOsmGeo.Tags, FeatureAttributes.IMAGE_URL, existingImages.Distinct().ToArray()); } - private async Task UploadImages(Feature feature, string language, IAuthClient osmGateway) + private async Task UploadImages(IFeature feature, string language, IAuthClient osmGateway) { var user = await osmGateway.GetUserDetails(); feature.SetTitles(); @@ -495,7 +491,7 @@ private async Task UploadImages(Feature feature, string language, IAut } private async Task UploadImageIfNeeded(string imageUrl, - Feature feature, string language, string userDisplayName) + IFeature feature, string language, string userDisplayName) { var icon = feature.Attributes[FeatureAttributes.POI_ICON].ToString(); var fileName = string.IsNullOrWhiteSpace(feature.GetTitle(language)) diff --git a/IsraelHiking.API/Services/Poi/WikipediaPointsOfInterestAdapter.cs b/IsraelHiking.API/Services/Poi/WikipediaPointsOfInterestAdapter.cs index 31540dfa7..941a1e848 100644 --- a/IsraelHiking.API/Services/Poi/WikipediaPointsOfInterestAdapter.cs +++ b/IsraelHiking.API/Services/Poi/WikipediaPointsOfInterestAdapter.cs @@ -40,7 +40,7 @@ public class WikipediaPointsOfInterestAdapter : IPointsOfInterestAdapter public string Source => Sources.WIKIPEDIA; /// - public async Task> GetAll() + public async Task> GetAll() { _logger.LogInformation("Start getting Wikipedia pages for indexing."); var allLinkedWikipedia = await _overpassTurboGateway.GetWikipediaLinkedTitles(); @@ -68,10 +68,10 @@ public async Task> GetAll() } _logger.LogInformation($"Created {coordinatesList.Count} coordinates centers to fetch Wikipedia data."); - var allFeatures = new List(); + var allFeatures = new List(); foreach (var language in Languages.Array) { - var lists = new ConcurrentBag>(); + var lists = new ConcurrentBag>(); await Task.Run(() => { Parallel.ForEach(coordinatesList, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (coordinate) => @@ -89,7 +89,7 @@ public async Task> GetAll() _logger.LogInformation($"Got {wikiFeaturesTitles.Count} wiki pages for language: {language}, getting full data"); var requests = 200; var pageSize = wikiFeaturesTitles.Count / requests + 1; - lists = new ConcurrentBag>(); + lists = new ConcurrentBag>(); await Task.Run(() => { Parallel.For(0, requests, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (requestNumber) => @@ -109,7 +109,7 @@ public async Task> GetAll() } /// - public async Task> GetUpdates(DateTime lastModifiedDate) + public async Task> GetUpdates(DateTime lastModifiedDate) { var features = await GetAll(); // The features with the invalid location might be added by editing an OSM element, diff --git a/IsraelHiking.Common/Api/UpdatesResponse.cs b/IsraelHiking.Common/Api/UpdatesResponse.cs index 91463ea5f..a32edacba 100644 --- a/IsraelHiking.Common/Api/UpdatesResponse.cs +++ b/IsraelHiking.Common/Api/UpdatesResponse.cs @@ -5,7 +5,7 @@ namespace IsraelHiking.Common.Api { public class UpdatesResponse { - public Feature[] Features { get; set; } + public IFeature[] Features { get; set; } public ImageItem[] Images { get; set; } public DateTime LastModified { get; set; } } diff --git a/IsraelHiking.Common/Extensions/GeoJsonExtensions.cs b/IsraelHiking.Common/Extensions/GeoJsonExtensions.cs index d14ef8cf4..f9a959260 100644 --- a/IsraelHiking.Common/Extensions/GeoJsonExtensions.cs +++ b/IsraelHiking.Common/Extensions/GeoJsonExtensions.cs @@ -151,7 +151,7 @@ public static string GetTitle(this IFeature feature, string language) { return string.Empty; } - if (!(feature.Attributes[FeatureAttributes.POI_NAMES] is AttributesTable titleByLanguage)) + if (feature.Attributes[FeatureAttributes.POI_NAMES] is not IAttributesTable titleByLanguage) { return string.Empty; } @@ -203,12 +203,9 @@ public static string GetDescriptionWithExternal(this IFeature feature, string la public static string[] GetTitles(this IFeature feature) { - if (!(feature.Attributes[FeatureAttributes.POI_NAMES] is AttributesTable titleByLanguage)) - { - return new string[0]; - } - - return titleByLanguage.GetValues().Select(GetStringListFromAttributeValue).SelectMany(v => v).Distinct().ToArray(); + return feature.Attributes[FeatureAttributes.POI_NAMES] is not IAttributesTable titleByLanguage + ? Array.Empty() + : titleByLanguage.GetValues().Select(GetStringListFromAttributeValue).SelectMany(v => v).Distinct().ToArray(); } public static List GetStringListFromAttributeValue(object value) @@ -228,6 +225,9 @@ public static List GetStringListFromAttributeValue(object value) case string str: titles.Add(str); break; + case object[] objectArray: + titles.AddRange(objectArray.Select(o => o.ToString()).ToList()); + break; } return titles; } @@ -293,17 +293,15 @@ public static void SetLastModified(this IAttributesTable table, DateTime dateTim public static Coordinate GetLocation(this IFeature feature) { - var locationTable = feature.Attributes[FeatureAttributes.POI_GEOLOCATION] as AttributesTable; - if (locationTable == null) + if (feature.Attributes[FeatureAttributes.POI_GEOLOCATION] is not IAttributesTable locationTable) { throw new InvalidOperationException($"Missing location for feature with id {feature.GetId()}"); } - var location = new Coordinate(); - if (locationTable != null) + var location = new Coordinate { - location.Y = double.Parse(locationTable[FeatureAttributes.LAT].ToString()); - location.X = double.Parse(locationTable[FeatureAttributes.LON].ToString()); - } + Y = double.Parse(locationTable[FeatureAttributes.LAT].ToString()), + X = double.Parse(locationTable[FeatureAttributes.LON].ToString()) + }; return location; } diff --git a/IsraelHiking.DataAccess/ElasticSearchGateway.cs b/IsraelHiking.DataAccess/ElasticSearchGateway.cs index 947b636b4..4289488ba 100644 --- a/IsraelHiking.DataAccess/ElasticSearchGateway.cs +++ b/IsraelHiking.DataAccess/ElasticSearchGateway.cs @@ -19,11 +19,9 @@ using System.Text; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Unicode; using System.Threading; using System.Threading.Tasks; using NetTopologySuite.IO.Converters; -using Feature = NetTopologySuite.Features.Feature; public class DynamicDictionaryConverter : JsonConverter { @@ -239,7 +237,6 @@ public T Deserialize(Stream stream) if (TryReturnDefault(stream, out T deserialize)) return deserialize; var buffered = ToReadOnlySpan(stream); - Console.WriteLine(Encoding.UTF8.GetString(buffered)); return JsonSerializer.Deserialize(buffered, _none.Value); } @@ -400,7 +397,7 @@ private async Task InitializeIndexWithAlias(string index1, string index2, string return list; } - private QueryContainer FeatureNameSearchQueryWithFactor(QueryContainerDescriptor q, string searchTerm, string language) + private QueryContainer FeatureNameSearchQueryWithFactor(QueryContainerDescriptor q, string searchTerm, string language) { return q.FunctionScore( fs => fs.Query( @@ -409,7 +406,7 @@ private QueryContainer FeatureNameSearchQueryWithFactor(QueryContainerDescriptor ); } - private QueryContainer FeatureNameSearchQuery(QueryContainerDescriptor q, string searchTerm, string language) + private QueryContainer FeatureNameSearchQuery(QueryContainerDescriptor q, string searchTerm, string language) { return q.DisMax( dm => dm.Queries( @@ -428,13 +425,13 @@ private QueryContainer FeatureNameSearchQuery(QueryContainerDescriptor ); } - public async Task> Search(string searchTerm, string language) + public async Task> Search(string searchTerm, string language) { if (string.IsNullOrWhiteSpace(searchTerm)) { - return new List(); + return new List(); } - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(OSM_POIS_ALIAS) .Size(NUMBER_OF_RESULTS) .TrackScores() @@ -444,13 +441,13 @@ public async Task> Search(string searchTerm, string language) return response.Documents.Where(f => !f.Attributes.Exists(FeatureAttributes.POI_DELETED)).ToList(); } - public async Task> SearchExact(string searchTerm, string language) + public async Task> SearchExact(string searchTerm, string language) { if (string.IsNullOrWhiteSpace(searchTerm)) { - return new List(); + return new List(); } - var response = await _elasticClient.SearchAsync(s => + var response = await _elasticClient.SearchAsync(s => s.Index(OSM_POIS_ALIAS) .Size(100) .Query(q => @@ -476,9 +473,9 @@ public async Task> SearchExact(string searchTerm, string language) .ToList(); } - public async Task> SearchPlaces(string place, string language) + public async Task> SearchPlaces(string place, string language) { - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(OSM_POIS_ALIAS) .Size(5) .TrackScores() @@ -490,9 +487,9 @@ public async Task> SearchPlaces(string place, string language) return response.Documents.Where(f => !f.Attributes.Exists(FeatureAttributes.POI_DELETED)).ToList(); } - public async Task> SearchByLocation(Coordinate northEast, Coordinate southWest, string searchTerm, string language) + public async Task> SearchByLocation(Coordinate northEast, Coordinate southWest, string searchTerm, string language) { - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(OSM_POIS_ALIAS) .Size(NUMBER_OF_RESULTS) .TrackScores() @@ -505,9 +502,9 @@ public async Task> SearchByLocation(Coordinate northEast, Coordina return response.Documents.Where(f => !f.Attributes.Exists(FeatureAttributes.POI_DELETED)).ToList(); } - public async Task> GetContainers(Coordinate coordinate) + public async Task> GetContainers(Coordinate coordinate) { - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(OSM_POIS_ALIAS) .Size(100) .Query(q => @@ -541,7 +538,7 @@ private async Task SwitchIndices(string currentIndex, string newIndex, string al await _elasticClient.Indices.DeleteAsync(currentIndex); } - public async Task UpdateHighwaysZeroDownTime(List highways) + public async Task UpdateHighwaysZeroDownTime(List highways) { var (currentIndex, newIndex) = GetIndicesStatus(OSM_HIGHWAYS_INDEX1, OSM_HIGHWAYS_INDEX2, OSM_HIGHWAYS_ALIAS); @@ -551,7 +548,7 @@ public async Task UpdateHighwaysZeroDownTime(List highways) await SwitchIndices(currentIndex, newIndex, OSM_HIGHWAYS_ALIAS); } - public async Task StorePointsOfInterestDataToSecondaryIndex(List pointsOfInterest) + public async Task StorePointsOfInterestDataToSecondaryIndex(List pointsOfInterest) { var (_, newIndex) = GetIndicesStatus(OSM_POIS_INDEX1, OSM_POIS_INDEX2, OSM_POIS_ALIAS); await CreatePointsOfInterestIndex(newIndex); @@ -564,23 +561,23 @@ public async Task SwitchPointsOfInterestIndices() await SwitchIndices(currentIndex, newIndex, OSM_POIS_ALIAS); } - public Task UpdateHighwaysData(List features) + public Task UpdateHighwaysData(List features) { return UpdateData(features, OSM_HIGHWAYS_ALIAS); } - public Task UpdatePointsOfInterestData(List features) + public Task UpdatePointsOfInterestData(List features) { return UpdateData(features, OSM_POIS_ALIAS); } - private async Task UpdateData(List features, string alias) + private async Task UpdateData(List features, string alias) { var result = await _elasticClient.BulkAsync(bulk => { foreach (var feature in features) { - bulk.Index(i => i.Index(alias).Document(feature).Id(feature.GetId())); + bulk.Index(i => i.Index(alias).Document(feature).Id(feature.GetId())); } return bulk; }); @@ -590,9 +587,9 @@ private async Task UpdateData(List features, string alias) } } - public async Task> GetHighways(Coordinate northEast, Coordinate southWest) + public async Task> GetHighways(Coordinate northEast, Coordinate southWest) { - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(OSM_HIGHWAYS_ALIAS) .Size(5000) .Query( @@ -611,11 +608,11 @@ private GeoCoordinate ConvertCoordinate(Coordinate coordinate) return new GeoCoordinate(coordinate.Y, coordinate.X); } - public async Task> GetPointsOfInterest(Coordinate northEast, Coordinate southWest, string[] categories, string language) + public async Task> GetPointsOfInterest(Coordinate northEast, Coordinate southWest, string[] categories, string language) { var languages = language == Languages.ALL ? Languages.Array : new[] { language }; languages = languages.Concat(new[] { Languages.ALL }).ToArray(); - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(OSM_POIS_ALIAS) .Size(10000).Query( q => q.GeoBoundingBox( @@ -628,11 +625,11 @@ public async Task> GetPointsOfInterest(Coordinate northEast, Coord return response.Documents.Where(f => !f.Attributes.Exists(FeatureAttributes.POI_DELETED)).ToList(); } - public async Task> GetAllPointsOfInterest(bool withDeleted) + public async Task> GetAllPointsOfInterest(bool withDeleted) { await _elasticClient.Indices.RefreshAsync(OSM_POIS_ALIAS); var categories = Categories.Points.Concat(Categories.Routes).Select(c => c.ToLower()).ToArray(); - var response = await _elasticClient.SearchAsync(s => s.Index(OSM_POIS_ALIAS) + var response = await _elasticClient.SearchAsync(s => s.Index(OSM_POIS_ALIAS) .Size(10000) .Scroll("10s") .Query(q => q.Terms(t => t.Field($"{PROPERTIES}.{FeatureAttributes.POI_CATEGORY}").Terms(categories)) @@ -645,7 +642,7 @@ public async Task> GetAllPointsOfInterest(bool withDeleted) return list; } - private GeoBoundingBoxQueryDescriptor ConvertToGeoBoundingBox(GeoBoundingBoxQueryDescriptor b, + private GeoBoundingBoxQueryDescriptor ConvertToGeoBoundingBox(GeoBoundingBoxQueryDescriptor b, Coordinate northEast, Coordinate southWest) { return b.BoundingBox( @@ -654,10 +651,10 @@ public async Task> GetAllPointsOfInterest(bool withDeleted) ).Field($"{PROPERTIES}.{FeatureAttributes.POI_GEOLOCATION}"); } - public async Task> GetPointsOfInterestUpdates(DateTime lastModifiedDate, DateTime modifiedUntil) + public async Task> GetPointsOfInterestUpdates(DateTime lastModifiedDate, DateTime modifiedUntil) { var categories = Categories.Points.Concat(Categories.Routes).Select(c => c.ToLower()).ToArray(); - var response = await _elasticClient.SearchAsync(s => s.Index(OSM_POIS_ALIAS) + var response = await _elasticClient.SearchAsync(s => s.Index(OSM_POIS_ALIAS) .Size(10000) .Scroll("10s") .Query(q => q.DateRange(t => t.Field($"{PROPERTIES}.{FeatureAttributes.POI_LAST_MODIFIED}").GreaterThan(lastModifiedDate).LessThanOrEquals(modifiedUntil)) @@ -666,22 +663,22 @@ public async Task> GetPointsOfInterestUpdates(DateTime lastModifie return GetAllItemsByScrolling(response); } - public async Task GetPointOfInterestById(string id, string source) + public async Task GetPointOfInterestById(string id, string source) { var fullId = GeoJsonExtensions.GetId(source, id); - var response = await _elasticClient.GetAsync(fullId, r => r.Index(OSM_POIS_ALIAS)); + var response = await _elasticClient.GetAsync(fullId, r => r.Index(OSM_POIS_ALIAS)); return response.Source; } public Task DeletePointOfInterestById(string id, string source) { var fullId = GeoJsonExtensions.GetId(source, id); - return _elasticClient.DeleteAsync(fullId, d => d.Index(OSM_POIS_ALIAS)); + return _elasticClient.DeleteAsync(fullId, d => d.Index(OSM_POIS_ALIAS)); } - public async Task> GetExternalPoisBySource(string source) + public async Task> GetExternalPoisBySource(string source) { - var response = await _elasticClient.SearchAsync( + var response = await _elasticClient.SearchAsync( s => s.Index(EXTERNAL_POIS) .Size(10000) .Scroll("10s") @@ -694,13 +691,13 @@ public async Task> GetExternalPoisBySource(string source) return features; } - public async Task GetExternalPoiById(string id, string source) + public async Task GetExternalPoiById(string id, string source) { - var response = await _elasticClient.GetAsync(GeoJsonExtensions.GetId(source, id), r => r.Index(EXTERNAL_POIS)); + var response = await _elasticClient.GetAsync(GeoJsonExtensions.GetId(source, id), r => r.Index(EXTERNAL_POIS)); return response.Source; } - public async Task AddExternalPois(List features) + public async Task AddExternalPois(List features) { if ((await _elasticClient.Indices.ExistsAsync(EXTERNAL_POIS)).Exists == false) { @@ -711,7 +708,7 @@ public async Task AddExternalPois(List features) public Task DeleteExternalPoisBySource(string source) { - return _elasticClient.DeleteByQueryAsync(d => + return _elasticClient.DeleteByQueryAsync(d => d.Index(EXTERNAL_POIS) .Query(q => q.Term(t => t.Field($"{PROPERTIES}.{FeatureAttributes.POI_SOURCE}").Value(source.ToLower())) @@ -722,7 +719,7 @@ public Task DeleteExternalPoisBySource(string source) private Task CreateHighwaysIndex(string highwaysIndexName) { return _elasticClient.Indices.CreateAsync(highwaysIndexName, - c => c.Map(m => + c => c.Map(m => m.Dynamic(false) .Properties(ps => ps.GeoShape(g => @@ -736,7 +733,7 @@ private Task CreateHighwaysIndex(string highwaysIndexName) private Task CreatePointsOfInterestIndex(string poisIndexName) { return _elasticClient.Indices.CreateAsync(poisIndexName, - c => c.Map(m => + c => c.Map(m => m.Properties(ps => ps.Object(o => o .Name(PROPERTIES) @@ -754,9 +751,9 @@ private Task CreatePointsOfInterestIndex(string poisIndexName) private Task CreateExternalPoisIndex() { return _elasticClient.Indices.CreateAsync(EXTERNAL_POIS, - c => c.Map(m => + c => c.Map(m => m.Properties(fp => - fp.Object(a => a + fp.Object(a => a .Name(PROPERTIES) .Properties(p => p.Keyword(s => s.Name(FeatureAttributes.ID))) ) @@ -784,10 +781,10 @@ private Task CreateSharesIndex() c => c.Map(m => m.AutoMap()) ); } - private async Task UpdateUsingPaging(List features, string alias) + private async Task UpdateUsingPaging(List features, string alias) { _logger.LogInformation($"Starting indexing {features.Count} records"); - var smallCacheList = new List(PAGE_SIZE); + var smallCacheList = new List(PAGE_SIZE); int total = 0; foreach (var feature in features) { @@ -924,7 +921,7 @@ public async Task DeleteImageByUrl(string url) var imageItem = await GetImageByUrl(url); if (imageItem != null) { - await _elasticClient.DeleteAsync(imageItem.Hash, d => d.Index(IMAGES)); + await _elasticClient.DeleteAsync(imageItem.Hash, d => d.Index(IMAGES)); } } diff --git a/IsraelHiking.DataAccess/INatureGateway.cs b/IsraelHiking.DataAccess/INatureGateway.cs index b6339c053..e271a7def 100644 --- a/IsraelHiking.DataAccess/INatureGateway.cs +++ b/IsraelHiking.DataAccess/INatureGateway.cs @@ -42,7 +42,7 @@ public async Task Initialize() _logger.LogInformation("Finished initializing iNature service"); } - public async Task> GetAll() + public async Task> GetAll() { var allpagesGenerator = new AllPagesGenerator(_wikiSite) { @@ -193,7 +193,7 @@ private async Task TitleToFeature(string title) return feature; } - public async Task> GetUpdates(DateTime lastUpdated) + public async Task> GetUpdates(DateTime lastUpdated) { var recentChangesGEnerator = new RecentChangesGenerator(_wikiSite) { @@ -207,9 +207,9 @@ public async Task> GetUpdates(DateTime lastUpdated) return await GetFeaturesFromTitles(titles.Select(i => i.Title).ToArray()); } - private async Task> GetFeaturesFromTitles(string[] titles) + private async Task> GetFeaturesFromTitles(string[] titles) { - var features = new ConcurrentBag(); + var features = new ConcurrentBag(); await Task.Run(() => { Parallel.ForEach(titles, new ParallelOptions { MaxDegreeOfParallelism = 5 }, (title) => diff --git a/IsraelHiking.DataAccess/ImageCreationGateway.cs b/IsraelHiking.DataAccess/ImageCreationGateway.cs index 885e29757..9c06e9f34 100644 --- a/IsraelHiking.DataAccess/ImageCreationGateway.cs +++ b/IsraelHiking.DataAccess/ImageCreationGateway.cs @@ -1,4 +1,3 @@ -using System; using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; diff --git a/IsraelHiking.DataAccess/ImgurGateway.cs b/IsraelHiking.DataAccess/ImgurGateway.cs index bbd347859..f9f98b564 100644 --- a/IsraelHiking.DataAccess/ImgurGateway.cs +++ b/IsraelHiking.DataAccess/ImgurGateway.cs @@ -2,7 +2,6 @@ using IsraelHiking.DataAccessInterfaces; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using System.Text.Json.Serialization; using Newtonsoft.Json.Linq; using System; using System.IO; diff --git a/IsraelHiking.DataAccess/RemoteFileFetcherGateway.cs b/IsraelHiking.DataAccess/RemoteFileFetcherGateway.cs index 5b3dd9307..5324d320f 100644 --- a/IsraelHiking.DataAccess/RemoteFileFetcherGateway.cs +++ b/IsraelHiking.DataAccess/RemoteFileFetcherGateway.cs @@ -1,10 +1,8 @@ -using System.Net; -using IsraelHiking.DataAccessInterfaces; +using IsraelHiking.DataAccessInterfaces; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using System.Net.Http; using System; -using System.Linq; using IsraelHiking.Common; using IsraelHiking.Common.Api; diff --git a/IsraelHiking.DataAccess/WikipediaGateway.cs b/IsraelHiking.DataAccess/WikipediaGateway.cs index 8649fda8d..91f2ee3d9 100644 --- a/IsraelHiking.DataAccess/WikipediaGateway.cs +++ b/IsraelHiking.DataAccess/WikipediaGateway.cs @@ -45,7 +45,7 @@ public async Task Initialize() _logger.LogInformation("Finished initializing Wikipedia service"); } - public async Task> GetByPagesTitles(string[] titles, string language) + public async Task> GetByPagesTitles(string[] titles, string language) { try { @@ -72,14 +72,14 @@ public async Task> GetByPagesTitles(string[] titles, string langua { _logger.LogError($"Unable to get wikipedia pages due to {ex.Message} for (note that the titles are batched and so not all the titles here are causing this issue): " + string.Join(",", titles)); } - return new List(); + return new List(); } /// /// This recursive method is used to get wikipedia features by bounding box. - /// Since boundingbox can't scroll diue to a wikimedia implementiaion issue the workaround is - /// to recursivly split each bounding box to 4 rectangles until there's no overflow of results. + /// Since bounding-box can't scroll due to a wikimedia implementation issue the workaround is + /// to recursively split each bounding box to 4 rectangles until there's no overflow of results. /// A rectangle that is not overflowing will not be split. /// See here: https://github.com/CXuesong/WikiClientLibrary/issues/64 /// @@ -87,7 +87,7 @@ public async Task> GetByPagesTitles(string[] titles, string langua /// Top right corner of the rectangle /// The relevant language /// A list of features inside this rectangle - public async Task> GetByBoundingBox(Coordinate southWest, Coordinate northEast, string language) + public async Task> GetByBoundingBox(Coordinate southWest, Coordinate northEast, string language) { for (int retryIndex = 0; retryIndex < 3; retryIndex++) { @@ -99,7 +99,7 @@ public async Task> GetByBoundingBox(Coordinate southWest, Coordina PaginationSize = 500 }; var results = await geoSearchGenerator.EnumItemsAsync().ToListAsync(); - var features = new List(); + var features = new List(); if (results.Count < 500) // recursive stop condition { foreach (var geoSearchResultItem in results) @@ -127,7 +127,7 @@ public async Task> GetByBoundingBox(Coordinate southWest, Coordina } } _logger.LogError($"All Retries failed while trying to get data from {language}.wikipedia"); - return new List(); + return new List(); } public Reference GetReference(string title, string language) @@ -139,7 +139,7 @@ public Reference GetReference(string title, string language) }; } - private Feature ConvertPageToFeature(WikiPage page, string language) + private IFeature ConvertPageToFeature(WikiPage page, string language) { var geoCoordinate = page.GetPropertyGroup().PrimaryCoordinate; var coordinate = geoCoordinate.IsEmpty diff --git a/IsraelHiking.DataAccessInterfaces/IINatureGateway.cs b/IsraelHiking.DataAccessInterfaces/IINatureGateway.cs index 85a58c11f..39b08b1da 100644 --- a/IsraelHiking.DataAccessInterfaces/IINatureGateway.cs +++ b/IsraelHiking.DataAccessInterfaces/IINatureGateway.cs @@ -7,9 +7,9 @@ namespace IsraelHiking.DataAccessInterfaces { public interface IINatureGateway : IInitializable { - Task> GetAll(); + Task> GetAll(); - Task> GetUpdates(DateTime lastUpdated); + Task> GetUpdates(DateTime lastUpdated); } diff --git a/IsraelHiking.DataAccessInterfaces/IWikipediaGateway.cs b/IsraelHiking.DataAccessInterfaces/IWikipediaGateway.cs index ba4dd3a8d..eeb2c86b7 100644 --- a/IsraelHiking.DataAccessInterfaces/IWikipediaGateway.cs +++ b/IsraelHiking.DataAccessInterfaces/IWikipediaGateway.cs @@ -8,8 +8,8 @@ namespace IsraelHiking.DataAccessInterfaces { public interface IWikipediaGateway: IInitializable { - Task> GetByBoundingBox(Coordinate sourhWest, Coordinate northEast, string language); + Task> GetByBoundingBox(Coordinate sourhWest, Coordinate northEast, string language); Reference GetReference(string title, string language); - Task> GetByPagesTitles(string[] titles, string language); + Task> GetByPagesTitles(string[] titles, string language); } } diff --git a/IsraelHiking.DataAccessInterfaces/Repositories/IExternalSourcesRepository.cs b/IsraelHiking.DataAccessInterfaces/Repositories/IExternalSourcesRepository.cs index 552986386..0a2ad10e1 100644 --- a/IsraelHiking.DataAccessInterfaces/Repositories/IExternalSourcesRepository.cs +++ b/IsraelHiking.DataAccessInterfaces/Repositories/IExternalSourcesRepository.cs @@ -6,9 +6,9 @@ namespace IsraelHiking.DataAccessInterfaces.Repositories { public interface IExternalSourcesRepository { - Task> GetExternalPoisBySource(string source); - Task GetExternalPoiById(string id, string source); - Task AddExternalPois(List features); + Task> GetExternalPoisBySource(string source); + Task GetExternalPoiById(string id, string source); + Task AddExternalPois(List features); Task DeleteExternalPoisBySource(string source); } } diff --git a/IsraelHiking.DataAccessInterfaces/Repositories/IHighwaysRepository.cs b/IsraelHiking.DataAccessInterfaces/Repositories/IHighwaysRepository.cs index 706cddf2a..22c42a777 100644 --- a/IsraelHiking.DataAccessInterfaces/Repositories/IHighwaysRepository.cs +++ b/IsraelHiking.DataAccessInterfaces/Repositories/IHighwaysRepository.cs @@ -7,8 +7,8 @@ namespace IsraelHiking.DataAccessInterfaces.Repositories { public interface IHighwaysRepository { - Task UpdateHighwaysZeroDownTime(List highways); - Task UpdateHighwaysData(List features); - Task> GetHighways(Coordinate northEast, Coordinate southWest); + Task UpdateHighwaysZeroDownTime(List highways); + Task UpdateHighwaysData(List features); + Task> GetHighways(Coordinate northEast, Coordinate southWest); } } diff --git a/IsraelHiking.DataAccessInterfaces/Repositories/IOsmRepository.cs b/IsraelHiking.DataAccessInterfaces/Repositories/IOsmRepository.cs index 312ef4d98..f2acda715 100644 --- a/IsraelHiking.DataAccessInterfaces/Repositories/IOsmRepository.cs +++ b/IsraelHiking.DataAccessInterfaces/Repositories/IOsmRepository.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using OsmSharp.Complete; using System.IO; -using OsmSharp; namespace IsraelHiking.DataAccessInterfaces.Repositories { diff --git a/IsraelHiking.DataAccessInterfaces/Repositories/IPointsOfInterestRepository.cs b/IsraelHiking.DataAccessInterfaces/Repositories/IPointsOfInterestRepository.cs index 9629b2ed5..11bd2f90d 100644 --- a/IsraelHiking.DataAccessInterfaces/Repositories/IPointsOfInterestRepository.cs +++ b/IsraelHiking.DataAccessInterfaces/Repositories/IPointsOfInterestRepository.cs @@ -9,13 +9,13 @@ namespace IsraelHiking.DataAccessInterfaces.Repositories { public interface IPointsOfInterestRepository { - Task StorePointsOfInterestDataToSecondaryIndex(List pointsOfInterest); + Task StorePointsOfInterestDataToSecondaryIndex(List pointsOfInterest); Task SwitchPointsOfInterestIndices(); - Task UpdatePointsOfInterestData(List features); - Task> GetPointsOfInterest(Coordinate northEast, Coordinate southWest, string[] categories, string language); - Task> GetAllPointsOfInterest(bool withDeleted); - Task> GetPointsOfInterestUpdates(DateTime lastModifiedDate, DateTime modifiedUntil); - Task GetPointOfInterestById(string id, string source); + Task UpdatePointsOfInterestData(List features); + Task> GetPointsOfInterest(Coordinate northEast, Coordinate southWest, string[] categories, string language); + Task> GetAllPointsOfInterest(bool withDeleted); + Task> GetPointsOfInterestUpdates(DateTime lastModifiedDate, DateTime modifiedUntil); + Task GetPointOfInterestById(string id, string source); Task DeletePointOfInterestById(string id, string source); Task StoreRebuildContext(RebuildContext context); Task GetLastSuccessfulRebuildTime(); diff --git a/IsraelHiking.DataAccessInterfaces/Repositories/ISearchRepository.cs b/IsraelHiking.DataAccessInterfaces/Repositories/ISearchRepository.cs index e1569ca79..e62e3ce15 100644 --- a/IsraelHiking.DataAccessInterfaces/Repositories/ISearchRepository.cs +++ b/IsraelHiking.DataAccessInterfaces/Repositories/ISearchRepository.cs @@ -7,10 +7,10 @@ namespace IsraelHiking.DataAccessInterfaces.Repositories { public interface ISearchRepository { - Task> Search(string searchTerm, string language); - Task> SearchPlaces(string place, string language); - Task> SearchByLocation(Coordinate northEast, Coordinate southWest, string searchTerm, string language); - Task> SearchExact(string searchTerm, string language); - Task> GetContainers(Coordinate coordinate); + Task> Search(string searchTerm, string language); + Task> SearchPlaces(string place, string language); + Task> SearchByLocation(Coordinate northEast, Coordinate southWest, string searchTerm, string language); + Task> SearchExact(string searchTerm, string language); + Task> GetContainers(Coordinate coordinate); } } diff --git a/IsraelHiking.Web/OsmAccessTokenEventsHelper.cs b/IsraelHiking.Web/OsmAccessTokenEventsHelper.cs index cdd1dfa43..556f8d7cf 100644 --- a/IsraelHiking.Web/OsmAccessTokenEventsHelper.cs +++ b/IsraelHiking.Web/OsmAccessTokenEventsHelper.cs @@ -1,12 +1,10 @@ -using IsraelHiking.Common; -using IsraelHiking.Common.Configuration; +using IsraelHiking.Common.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OsmSharp.IO.API; using System; using System.Security.Claims; using System.Threading.Tasks; -using IsraelHiking.API.Services; using IsraelHiking.API.Services.Osm; using LazyCache; using Microsoft.AspNetCore.Authentication.JwtBearer; diff --git a/IsraelHiking.Web/Program.cs b/IsraelHiking.Web/Program.cs index 24960ffea..e0d3cb312 100644 --- a/IsraelHiking.Web/Program.cs +++ b/IsraelHiking.Web/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; using Microsoft.Extensions.Logging; using System.IO; using System.Net.Http; @@ -24,7 +23,6 @@ using NeoSmart.Caching.Sqlite; using NetTopologySuite.Features; using NetTopologySuite.Geometries; -using NetTopologySuite.IO; using NetTopologySuite.IO.Converters; using NLog.Web; using OsmSharp.IO.API; diff --git a/Tests/IsraelHiking.API.Tests/Controllers/ControllerTestHelper.cs b/Tests/IsraelHiking.API.Tests/Controllers/ControllerTestHelper.cs index 2d5ec6e34..104b95f78 100644 --- a/Tests/IsraelHiking.API.Tests/Controllers/ControllerTestHelper.cs +++ b/Tests/IsraelHiking.API.Tests/Controllers/ControllerTestHelper.cs @@ -1,8 +1,6 @@ -using IsraelHiking.Common; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; -using IsraelHiking.API.Services; using IsraelHiking.API.Services.Osm; namespace IsraelHiking.API.Tests.Controllers diff --git a/Tests/IsraelHiking.API.Tests/Controllers/OsmControllerTests.cs b/Tests/IsraelHiking.API.Tests/Controllers/OsmControllerTests.cs index c73a36446..5ff362646 100644 --- a/Tests/IsraelHiking.API.Tests/Controllers/OsmControllerTests.cs +++ b/Tests/IsraelHiking.API.Tests/Controllers/OsmControllerTests.cs @@ -3,7 +3,6 @@ using IsraelHiking.API.Gpx; using IsraelHiking.API.Services; using IsraelHiking.API.Services.Osm; -using IsraelHiking.Common; using IsraelHiking.Common.Configuration; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; diff --git a/Tests/IsraelHiking.API.Tests/Controllers/OsmTracesControllerTests.cs b/Tests/IsraelHiking.API.Tests/Controllers/OsmTracesControllerTests.cs index 12aafd6ea..cb99d2b70 100644 --- a/Tests/IsraelHiking.API.Tests/Controllers/OsmTracesControllerTests.cs +++ b/Tests/IsraelHiking.API.Tests/Controllers/OsmTracesControllerTests.cs @@ -14,7 +14,6 @@ using OsmSharp.IO.API; using System.IO; using System.Text; -using Castle.Core.Logging; using IsraelHiking.Common.DataContainer; using IsraelHiking.Common.Extensions; using IsraelHiking.DataAccessInterfaces; @@ -179,7 +178,7 @@ public void PostUploadRouteData_DefaultName_ShouldCreateTraceAndUpdateDescriptio {FeatureAttributes.POI_ID, "42"} }); containingFeature.SetTitles(); - _searchRepository.GetContainers(Arg.Any()).Returns(new List {containingFeature}); + _searchRepository.GetContainers(Arg.Any()).Returns(new List {containingFeature}); _distributedCache.Get(Arg.Any()).Returns((byte[])null); _controller.PostUploadRouteData(routeData, Languages.ENGLISH).Wait(); diff --git a/Tests/IsraelHiking.API.Tests/Controllers/PointsOfInterestControllerTests.cs b/Tests/IsraelHiking.API.Tests/Controllers/PointsOfInterestControllerTests.cs index 4ec54fc5f..c28742a28 100644 --- a/Tests/IsraelHiking.API.Tests/Controllers/PointsOfInterestControllerTests.cs +++ b/Tests/IsraelHiking.API.Tests/Controllers/PointsOfInterestControllerTests.cs @@ -88,6 +88,8 @@ public void GetPointsOfInterest_OneAdapter_ShouldReturnPoi() [TestMethod] public void GetPointOfInterest_WrongSource_ShouldReturnBadRequest() { + _pointsOfInterestProvider.GetFeatureById(Arg.Any(), Arg.Any()).Returns(null as IFeature); + var result = _controller.GetPointOfInterest("wrong source", string.Empty).Result as NotFoundResult; Assert.IsNotNull(result); diff --git a/Tests/IsraelHiking.API.Tests/Controllers/SearchControllerTests.cs b/Tests/IsraelHiking.API.Tests/Controllers/SearchControllerTests.cs index ef9b77030..243cfca47 100644 --- a/Tests/IsraelHiking.API.Tests/Controllers/SearchControllerTests.cs +++ b/Tests/IsraelHiking.API.Tests/Controllers/SearchControllerTests.cs @@ -27,7 +27,7 @@ public void TestInitialize() [TestMethod] public void GetSearchResults_ShouldPassRequestToGateway_NoResultsFound() { - var list = new List(); + var list = new List(); var searchTerm = "searchTerm"; _searchRepository.Search(searchTerm, Languages.ENGLISH).Returns(list); @@ -40,7 +40,7 @@ public void GetSearchResults_ShouldPassRequestToGateway_NoResultsFound() [TestMethod] public void GetSearchResults_UsingQuotes_ShouldGetExactMatch() { - var list = new List(); + var list = new List(); var searchTerm = "\"searchTerm\""; _searchRepository.SearchExact(Arg.Any(), Languages.ENGLISH).Returns(list); @@ -69,9 +69,9 @@ public void GetSearchResults_WithPlaceNameThatDoNotExist_ShouldReturnRegularResu featureInPlace.SetTitles(); featureInPlace.SetLocation(featureLocation); var featuresInsidePlace = new List { featureInPlace }; - _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List()); - _searchRepository.Search("searchTerm", Languages.ENGLISH).Returns(new List { featureInPlace }); - _searchRepository.GetContainers(featureLocation).Returns(new List()); + _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List()); + _searchRepository.Search("searchTerm", Languages.ENGLISH).Returns(new List { featureInPlace }); + _searchRepository.GetContainers(featureLocation).Returns(new List()); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result.ToList(); @@ -109,12 +109,12 @@ public void GetSearchResults_WithPlaceName_ShouldSearchOnlyPlacesInThatPlace() }); featureInPlace.SetTitles(); featureInPlace.SetLocation(featureLocation); - var featuresInsidePlace = new List { featureInPlace }; - _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List {placeFeature}); + var featuresInsidePlace = new List { featureInPlace }; + _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List {placeFeature}); _searchRepository .SearchByLocation(Arg.Any(), Arg.Any(), "searchTerm", Languages.ENGLISH) .Returns(featuresInsidePlace); - _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); + _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result.ToList(); @@ -156,12 +156,12 @@ public void GetSearchResults_GeometryCollection_ShouldNotFail() ); featureInPlace.SetTitles(); featureInPlace.SetLocation(featureLocation); - var featuresInsidePlace = new List { featureInPlace }; - _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List { placeFeature }); + var featuresInsidePlace = new List { featureInPlace }; + _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List { placeFeature }); _searchRepository .SearchByLocation(Arg.Any(), Arg.Any(), "searchTerm", Languages.ENGLISH) .Returns(featuresInsidePlace); - _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); + _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result.ToList(); @@ -204,12 +204,12 @@ public void GetSearchResults_GeometryCollectionNoContainers_ShouldNotFail() ); featureInPlace.SetTitles(); featureInPlace.SetLocation(featureLocation); - var featuresInsidePlace = new List { featureInPlace }; - _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List { placeFeature }); + var featuresInsidePlace = new List { featureInPlace }; + _searchRepository.SearchPlaces(place, Languages.ENGLISH).Returns(new List { placeFeature }); _searchRepository .SearchByLocation(Arg.Any(), Arg.Any(), "searchTerm", Languages.ENGLISH) .Returns(featuresInsidePlace); - _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); + _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result.ToList(); @@ -247,8 +247,8 @@ public void GetSearchResults_ContainerHasNoName_ShouldNotIAddItToDisplayName() }); featureInPlace.SetTitles(); featureInPlace.SetLocation(featureLocation); - _searchRepository.Search(searchTerm, Languages.ENGLISH).Returns(new List { featureInPlace }); - _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); + _searchRepository.Search(searchTerm, Languages.ENGLISH).Returns(new List { featureInPlace }); + _searchRepository.GetContainers(featureLocation).Returns(new List { placeFeature }); var results = _controller.GetSearchResults(searchTerm, Languages.ENGLISH).Result; diff --git a/Tests/IsraelHiking.API.Tests/Executors/ExternalSourceUpdaterExecutorTests.cs b/Tests/IsraelHiking.API.Tests/Executors/ExternalSourceUpdaterExecutorTests.cs index b2940821f..0e011ead6 100644 --- a/Tests/IsraelHiking.API.Tests/Executors/ExternalSourceUpdaterExecutorTests.cs +++ b/Tests/IsraelHiking.API.Tests/Executors/ExternalSourceUpdaterExecutorTests.cs @@ -38,13 +38,13 @@ public void UpdateSource_NoPreviousPoints_ShouldUpdate() { const string sourceName = "sourceName"; var adapter = Substitute.For(); - adapter.GetUpdates(Arg.Any()).Returns(new List()); + adapter.GetUpdates(Arg.Any()).Returns(new List()); _pointsOfInterestAdapterFactory.GetBySource(sourceName).Returns(adapter); - _externalSourcesRepository.GetExternalPoisBySource(sourceName).Returns(new List()); + _externalSourcesRepository.GetExternalPoisBySource(sourceName).Returns(new List()); _executor.UpdateSource(sourceName).Wait(); - _externalSourcesRepository.Received(1).AddExternalPois(Arg.Any>()); + _externalSourcesRepository.Received(1).AddExternalPois(Arg.Any>()); } [TestMethod] @@ -54,13 +54,13 @@ public void UpdateSource_UseLastModified_ShouldUpdate() var feature = new Feature(new Point(0, 0), new AttributesTable()); feature.SetLastModified(new DateTime(0)); var adapter = Substitute.For(); - adapter.GetUpdates(Arg.Any()).Returns(new List()); + adapter.GetUpdates(Arg.Any()).Returns(new List()); _pointsOfInterestAdapterFactory.GetBySource(sourceName).Returns(adapter); - _externalSourcesRepository.GetExternalPoisBySource(sourceName).Returns(new List {feature}); + _externalSourcesRepository.GetExternalPoisBySource(sourceName).Returns(new List {feature}); _executor.UpdateSource(sourceName).Wait(); - _externalSourcesRepository.Received(1).AddExternalPois(Arg.Any>()); + _externalSourcesRepository.Received(1).AddExternalPois(Arg.Any>()); } [TestMethod] @@ -70,14 +70,14 @@ public void RebuildSource_ShouldRebuild() var adapter = Substitute.For(); var feature = new Feature(new Point(0, 0), new AttributesTable()); feature.SetLocation(new Coordinate(0,0)); - adapter.GetAll().Returns(new List { feature}); + adapter.GetAll().Returns(new List { feature}); _elevationGateway.GetElevation(Arg.Any()).Returns(new [] {0.0}); _pointsOfInterestAdapterFactory.GetBySource(sourceName).Returns(adapter); _executor.RebuildSource(sourceName).Wait(); _externalSourcesRepository.Received(1).DeleteExternalPoisBySource(sourceName); - _externalSourcesRepository.Received(1).AddExternalPois(Arg.Any>()); + _externalSourcesRepository.Received(1).AddExternalPois(Arg.Any>()); } } } \ No newline at end of file diff --git a/Tests/IsraelHiking.API.Tests/Executors/FeaturesMergeExecutorTests.cs b/Tests/IsraelHiking.API.Tests/Executors/FeaturesMergeExecutorTests.cs index 9fb32b321..ee5048fc1 100644 --- a/Tests/IsraelHiking.API.Tests/Executors/FeaturesMergeExecutorTests.cs +++ b/Tests/IsraelHiking.API.Tests/Executors/FeaturesMergeExecutorTests.cs @@ -20,7 +20,7 @@ public class FeaturesMergeExecutorTests { private IFeaturesMergeExecutor _executor; - private Feature CreateFeature(string id, double x, double y) + private IFeature CreateFeature(string id, double x, double y) { var feature = new Feature(new Point(x, y), new AttributesTable { @@ -60,7 +60,7 @@ public void MergeFeatures_HasSameTitleOSMSource_ShouldMergeWithoutLink() feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME + ":en", "11"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); } @@ -75,7 +75,7 @@ public void MergeFeatures_HasSameMtbName_ShouldMerge() feature2.Attributes.AddOrUpdate(FeatureAttributes.MTB_NAME, "1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); } @@ -95,7 +95,7 @@ public void MergeFeatures_HasSameTitleAndSameImagesAndWebsite_ShouldMergeWithout feature2.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "web1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); Assert.AreEqual(2, results.First().Attributes.GetNames().Count(n => n.StartsWith(FeatureAttributes.IMAGE_URL))); @@ -114,7 +114,7 @@ public void MergeFeatures_HasSameTitleButNotTheSameCategoryFamily_ShouldNotMerge feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_CATEGORY, Categories.HISTORIC); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(2, results.Count); } @@ -139,7 +139,7 @@ public void MergeFeatures_HasSameTitleDifferentSource_ShouldMergeWithLink() feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_ICON_COLOR, "green"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); Assert.AreEqual(Categories.INATURE, results.First().Attributes[FeatureAttributes.POI_CATEGORY]); @@ -162,7 +162,7 @@ public void MergeFeatures_HasSameTitleButFarAway_ShouldNotMerge() feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME + ":en", "11"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(2, results.Count); } @@ -178,7 +178,7 @@ public void MergeFeatures_HasSameTitleAndCloseEnoughFromExternalSource_ShouldMer feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE, Sources.INATURE); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); } @@ -195,7 +195,7 @@ public void MergeFeatures_HasSameTitleButFarAwayFromExternalSource_ShouldNotMerg feature2.SetTitles(); feature2.SetLocation(new Coordinate()); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(2, results.Count); } @@ -213,7 +213,7 @@ public void MergeFeatures_HasSameTitleBetweenEveryTwoOrdered_ShouldMergeToASingl node3.Attributes.AddOrUpdate(FeatureAttributes.NAME, "2"); node3.SetTitles(); - var results = _executor.Merge(new List { node1, node2, node3 }, new List()); + var results = _executor.Merge(new List { node1, node2, node3 }, new List()); Assert.AreEqual(1, results.Count); } @@ -231,7 +231,7 @@ public void MergeFeatures_HasSameTitleBetweenEveryTwoNotOrdered_ShouldMergeToASi node3.Attributes.AddOrUpdate(FeatureAttributes.NAME, "2"); node3.SetTitles(); - var results = _executor.Merge(new List { node1, node2, node3 }, new List()); + var results = _executor.Merge(new List { node1, node2, node3 }, new List()); Assert.AreEqual(1, results.Count); } @@ -249,7 +249,7 @@ public void MergeFeatures_HasSameTitleBetweenEveryTwoOrderedAsBadlyAsPossible_Sh node3.Attributes.AddOrUpdate(FeatureAttributes.NAME, "2"); node3.SetTitles(); - var results = _executor.Merge(new List { node1, node2, node3 }, new List()); + var results = _executor.Merge(new List { node1, node2, node3 }, new List()); Assert.AreEqual(1, results.Count); } @@ -274,7 +274,7 @@ public void MergeFeatures_AreaAndPoint_ShouldMergeGeometryOfAreaToPoint() point.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); point.SetTitles(); - var results = _executor.Merge(new List { point, area }, new List()); + var results = _executor.Merge(new List { point, area }, new List()); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Geometry is Polygon); @@ -293,7 +293,7 @@ public void MergeFeatures_OsmWithWikipediaTags_ShouldMerge() feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE, Sources.WIKIPEDIA); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); } @@ -335,7 +335,7 @@ public void MergeFeatures_TwoPolygonsAndPoint_ShouldMerge() feature3.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); feature3.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2, feature3 }, new List()); + var results = _executor.Merge(new List { feature1, feature2, feature3 }, new List()); Assert.AreEqual(1, results.Count); } @@ -367,7 +367,7 @@ public void MergeFeatures_PolygonsAndLinestringOfHighway_ShouldMerge() feature2.Attributes.AddOrUpdate("highway", "residential"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); Assert.AreEqual(OgcGeometryType.MultiLineString, results.First().Geometry.OgcGeometryType); @@ -407,7 +407,7 @@ public void MergeFeatures_MultiLineWithLine_ShouldMergeAndCreateASingleMultiLine feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); var mls = results.First().Geometry as MultiLineString; @@ -452,7 +452,7 @@ public void MergeFeatures_MultiPolygonWithPolygon_ShouldMergeAndCreateASingleMul feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); var mls = results.First().Geometry as MultiPolygon; @@ -489,7 +489,7 @@ public void MergeFeatures_PolygonWithOverlappingPolygon_ShouldMergeAndCreateASin feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); var isValidOp = new IsValidOp(results.First().Geometry); @@ -527,7 +527,7 @@ public void MergeFeatures_PolygonWithCoveringPolygon_ShouldMergeAndCreateASingle feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); var isValidOp = new IsValidOp(results.First().Geometry); @@ -565,7 +565,7 @@ public void MergeFeatures_PolygonTouchingAnotherPolygon_ShouldMergeAndCreateASin feature2.Attributes.AddOrUpdate(FeatureAttributes.NAME, "1"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(1, results.Count); var isValidOp = new IsValidOp(results.First().Geometry); @@ -604,7 +604,7 @@ public void MergeFeatures_MultiPolygonWithPoint_ShouldMergeAndCreateASingleMulti feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE, Sources.WIKIPEDIA); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 } , new List { feature2 }); + var results = _executor.Merge(new List { feature1 } , new List { feature2 }); Assert.AreEqual(1, results.Count); var mls = results.First().Geometry as MultiPolygon; @@ -630,7 +630,7 @@ public void MergeFeatures_TwoBusStopsAndWikipedia_ShouldMergeOnlyBusStops() node3.SetTitles(); node3.SetLocation(new Coordinate()); - var results = _executor.Merge(new List { node1, node2 }, new List { node3 }); + var results = _executor.Merge(new List { node1, node2 }, new List { node3 }); Assert.AreEqual(2, results.Count); } @@ -650,7 +650,7 @@ public void MergeFeatures_WayAndNodeAreSortedBackwards_ShouldMergeWayToNode() node.Attributes.AddOrUpdate(FeatureAttributes.NAME, "name"); node.SetTitles(); - var results = _executor.Merge(new List { way, node }, new List()); + var results = _executor.Merge(new List { way, node }, new List()); Assert.AreEqual(1, results.Count); } @@ -682,7 +682,7 @@ public void MergeFeatures_FeatureHasDescriptionWebsiteAndImage_ShouldMergeThem() node3.Attributes.AddOrUpdate(hebrewDescriptionKey, "wiki description"); node3.SetTitles(); - var results = _executor.Merge(new List { node1 }, new List { node2, node3 }); + var results = _executor.Merge(new List { node1 }, new List { node2, node3 }); Assert.AreEqual(1, results.Count); Assert.AreEqual(importantDescription, results.First().Attributes[hebrewDescriptionKey].ToString()); @@ -704,7 +704,7 @@ public void MergeFeatures_RailwayAndPlace_ShouldNotMergeThem() node2.Attributes.AddOrUpdate("railway", "station"); node2.SetTitles(); - var results = _executor.Merge(new List { node1, node2 }, new List()); + var results = _executor.Merge(new List { node1, node2 }, new List()); Assert.AreEqual(2, results.Count); } @@ -734,7 +734,7 @@ public void MergeFeatures_MultipleMerges_ShouldMergeGeometriesRight() node4.Attributes.AddOrUpdate(FeatureAttributes.NAME, "name"); node4.SetTitles(); - var results = _executor.Merge(new List { node1, node2, node3, node4 }, new List()); + var results = _executor.Merge(new List { node1, node2, node3, node4 }, new List()); Assert.AreEqual(1, results.Count); var multiPoint = results.First().Geometry as MultiPoint; @@ -767,7 +767,7 @@ public void MergePlaceAndWay_ShouldMergePolygonIntoNode() new Coordinate(0,0), })); - var results = _executor.Merge(new List() { placeBoundary, placeNode }, new List()); + var results = _executor.Merge(new List { placeBoundary, placeNode }, new List()); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Geometry is Polygon); @@ -812,7 +812,7 @@ public void MergePlaceNodeWithInPlaceWithinBoundary_ShouldMergeAndRemove() new Coordinate(-1,-1), })); - var results = _executor.Merge(new List { placeBoundary, placeBoundary2, placeNode }, new List ()).ToList(); + var results = _executor.Merge(new List { placeBoundary, placeBoundary2, placeNode }, new List ()).ToList(); Assert.AreEqual(1, results.Count); } @@ -855,7 +855,7 @@ public void MergePlaceNodeWithInPlaceWithinBoundary_NodeIsInsideBoundaryButNotIn new Coordinate(-1,-1), })); - var results = _executor.Merge(new List { placeBoundary, placeBoundary2, placeNode }, new List()).ToList(); + var results = _executor.Merge(new List { placeBoundary, placeBoundary2, placeNode }, new List()).ToList(); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Geometry.IsValid); @@ -873,7 +873,7 @@ public void MergeFeatures_HasSameTitleDifferentHighwayType_ShouldNotMerge() feature2.Attributes.AddOrUpdate("highway", "track"); feature2.SetTitles(); feature2.Geometry = new LineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1) }); - var results = _executor.Merge(new List { feature1, feature2 }, new List()); + var results = _executor.Merge(new List { feature1, feature2 }, new List()); Assert.AreEqual(2, results.Count); } @@ -891,7 +891,7 @@ public void MergeFeatures_HasSameTitleWithSameWebsiteFromExternalSource_ShouldMe feature2.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "website"); feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE_IMAGE_URL, "siu"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Attributes.Exists(FeatureAttributes.POI_SOURCE_IMAGE_URL)); @@ -909,7 +909,7 @@ public void MergeFeatures_HasSameTitleWithWebsiteOnlyFromExternalSource_ShouldMe feature2.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "website"); feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE_IMAGE_URL, "siu"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Attributes.Exists(FeatureAttributes.POI_SOURCE_IMAGE_URL)); @@ -929,7 +929,7 @@ public void MergeFeatures_SecondWebsiteOfSourceIsFromExternal_ShouldMergeAndAddS feature2.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "web2"); feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE_IMAGE_URL, "siu"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Attributes.Exists(FeatureAttributes.POI_SOURCE_IMAGE_URL + "1")); @@ -954,7 +954,7 @@ public void MergeFeatures_HasSameTitleWithSameMultipleWebsites_ShouldMergeAndAdd feature3.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "web2"); feature3.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE_IMAGE_URL, "siu2"); feature3.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2, feature3 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2, feature3 }); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.First().Attributes.Exists(FeatureAttributes.POI_SOURCE_IMAGE_URL)); @@ -974,7 +974,7 @@ public void MergeFeatures_DescriptionOnlyExistsInExternalSource_ShouldMergeAndAd feature2.Attributes.AddOrUpdate(FeatureAttributes.POI_SOURCE, Sources.INATURE); feature2.Attributes.AddOrUpdate(FeatureAttributes.DESCRIPTION, "description"); feature2.SetTitles(); - var results = _executor.Merge(new List { feature1 }, new List { feature2 }); + var results = _executor.Merge(new List { feature1 }, new List { feature2 }); Assert.AreEqual(1, results.Count); Assert.IsFalse(results.First().Attributes.Exists(FeatureAttributes.DESCRIPTION)); diff --git a/Tests/IsraelHiking.API.Tests/Executors/PointsOfInterestFilesCreatorExecutorTests.cs b/Tests/IsraelHiking.API.Tests/Executors/PointsOfInterestFilesCreatorExecutorTests.cs index 7ee70f637..9b4086803 100644 --- a/Tests/IsraelHiking.API.Tests/Executors/PointsOfInterestFilesCreatorExecutorTests.cs +++ b/Tests/IsraelHiking.API.Tests/Executors/PointsOfInterestFilesCreatorExecutorTests.cs @@ -52,7 +52,7 @@ public void CreateSiteMapXmlFile_ShouldCreatIt() var stream = new MemoryStream(); _fileSystemHelper.CreateWriteStream(Arg.Any()).Returns(stream); - _executor.CreateSiteMapXmlFile(new List {feature}); + _executor.CreateSiteMapXmlFile(new List {feature}); Assert.IsTrue(stream.ToArray().Length > 0); } @@ -75,7 +75,7 @@ public void CreateOfflinePoisFile_SomeImagesExistsAndSomeDoNot_ShouldCreatIt() _imagesRepository.GetAllUrls().Returns(new List {"image", "image2"}); _imagesRepository.GetImageByUrl("image2").Returns(new ImageItem()); - _executor.CreateOfflinePoisFile(new List {feature}); + _executor.CreateOfflinePoisFile(new List {feature}); _fileSystemHelper.Received(1).WriteAllBytes(Arg.Any(), Arg.Any()); } diff --git a/Tests/IsraelHiking.API.Tests/Executors/SimplePointAdderExecutorTests.cs b/Tests/IsraelHiking.API.Tests/Executors/SimplePointAdderExecutorTests.cs index 92c78a177..40f8dc8b2 100644 --- a/Tests/IsraelHiking.API.Tests/Executors/SimplePointAdderExecutorTests.cs +++ b/Tests/IsraelHiking.API.Tests/Executors/SimplePointAdderExecutorTests.cs @@ -89,7 +89,7 @@ public void AddParking_ShouldSucceed() [TestMethod] public void AddGate_NearNoWhere_ShouldSucceed() { - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List()); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List()); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { @@ -119,7 +119,7 @@ public void AddGate_NearAWayAndVeryCloseToExistingNode_ShouldUpdateExistingNodeA .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y, Tags = new TagsCollection { {"tourism", "viewpoint"}}}); } _authClient.GetWay(42).Returns(new Way { Id = 42, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { LatLng = new LatLng(0, 1), @@ -150,7 +150,7 @@ public void AddGate_NearAWayAndVeryCloseToExistingNode_ShouldUpdateExistingNodeW .Returns(new Node {Longitude = coordinate.X, Latitude = coordinate.Y}); } _authClient.GetWay(42).Returns(new Way { Id = 42, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { LatLng = new LatLng(0, 1), @@ -178,7 +178,7 @@ public void AddGate_ABitAfterTheEndOfTheHighway_ShouldProlongTheHighway() .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y }); } _authClient.GetWay(42).Returns(new Way { Id = 42, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { LatLng = new LatLng(0, 2.0001), @@ -208,7 +208,7 @@ public void AddGate_NearAWay_ShouldAddItInTheRightPlace() .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y }); } _authClient.GetWay(42).Returns(new Way { Id = 42, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { LatLng = new LatLng(0, 1), @@ -238,7 +238,7 @@ public void AddGate_NearAWay_ShouldAddItOnTheWayItselfPerpendicularToItsLocation .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y }); } _authClient.GetWay(42).Returns(new Way { Id = 42, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { LatLng = new LatLng(0.0001, 0.5), @@ -280,7 +280,7 @@ public void AddGate_NearAJunction_ShouldAddItNotOnTheJunctionsNode() } _authClient.GetWay(1).Returns(new Way { Id = 1, Version = 1, Nodes = new long[] { 0, 1, 2 } }); _authClient.GetWay(2).Returns(new Way { Id = 2, Version = 1, Nodes = new long[] { 3, 1, 4 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature, feature2 }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature, feature2 }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { @@ -311,7 +311,7 @@ public void AddGate_NotNearEnoughToTheEndOfTheWay_ShouldAddANewNodeForIt() .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y }); } _authClient.GetWay(1).Returns(new Way { Id = 1, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { @@ -342,7 +342,7 @@ public void AddGate_GeometryOfTheWayAndGateLocationAreNotCompatible_ShouldThrow( .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y }); } _authClient.GetWay(1).Returns(new Way { Id = 1, Version = 1, Nodes = new long[] { 0, 1, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); Assert.ThrowsException(() => _executor.Add(_authClient, new AddSimplePointOfInterestRequest { @@ -380,7 +380,7 @@ public void AddGate_InsidePolygonAndCloserWay_ShouldAddToCloserWay() } _authClient.GetWay(1).Returns(new Way { Id = 1, Version = 1, Nodes = new long[] { 0, 1 } }); _authClient.GetWay(2).Returns(new Way { Id = 2, Version = 1, Nodes = new long[] { 2, 3, 4, 5, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature, feature2 }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature, feature2 }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { @@ -423,7 +423,7 @@ public void AddGate_NearMultipolygon_ShouldAddIt() .Returns(new Node { Longitude = coordinate.X, Latitude = coordinate.Y }); } _authClient.GetWay(2).Returns(new Way { Id = 2, Version = 1, Nodes = new long[] { 2, 3, 4, 5, 2 } }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { @@ -454,7 +454,7 @@ public void AddGate_NearAnOutdatedWay_ShouldAddItInTheRightPlace() } _authClient.GetWay(42).Returns(new Way { Id = 42, Version = 2, Nodes = new long[] { 0, 1, 2, 3 } }); _authClient.GetCompleteWay(42).Returns(new CompleteWay()); - _osmGeoJsonPreprocessorExecutor.Preprocess(Arg.Any>()).Returns(new List { + _osmGeoJsonPreprocessorExecutor.Preprocess(Arg.Any>()).Returns(new List { new Feature(new LineString(new[] { new Coordinate(0,0), new Coordinate(0.5,0), @@ -466,7 +466,7 @@ public void AddGate_NearAnOutdatedWay_ShouldAddItInTheRightPlace() {FeatureAttributes.POI_VERSION, 2 } }) }); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { feature }); _executor.Add(_authClient, new AddSimplePointOfInterestRequest { diff --git a/Tests/IsraelHiking.API.Tests/Services/AddibleGpxLinesFinderServiceTests.cs b/Tests/IsraelHiking.API.Tests/Services/AddibleGpxLinesFinderServiceTests.cs index 714cd6991..1a574b2d8 100644 --- a/Tests/IsraelHiking.API.Tests/Services/AddibleGpxLinesFinderServiceTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/AddibleGpxLinesFinderServiceTests.cs @@ -23,12 +23,14 @@ public class AddibleGpxLinesFinderServiceTests private void SetupHighways(List lineStrings = null) { - lineStrings = lineStrings ?? new List(); - var conveter = new ItmWgs84MathTransfromFactory().Create(); - var highways = lineStrings.Select(l => new Feature(new LineString(l.Coordinates.Select(c => conveter.Transform(c.X, c.Y)) + lineStrings ??= new List(); + var converter = new ItmWgs84MathTransfromFactory().Create(); + var highways = lineStrings.Select(l => new Feature(new LineString(l.Coordinates.Select(c => converter.Transform(c.X, c.Y)) .Select(c => new Coordinate(c.x, c.y)) .ToArray()), - new AttributesTable())).ToList(); + new AttributesTable())) + .Cast() + .ToList(); int id = 1; foreach (var highway in highways) { @@ -42,8 +44,10 @@ private void SetupHighways(List lineStrings = null) public void TestInitialize() { _highwaysRepository = Substitute.For(); - _options = new ConfigurationData(); - _options.MinimalProlongLineLength = 0; + _options = new ConfigurationData + { + MinimalProlongLineLength = 0 + }; var optionsProvider = Substitute.For>(); optionsProvider.Value.Returns(_options); var geometryFactory = new GeometryFactory(); diff --git a/Tests/IsraelHiking.API.Tests/Services/NonApiMiddlewareTests.cs b/Tests/IsraelHiking.API.Tests/Services/NonApiMiddlewareTests.cs index 5ac3cf085..e5a9127b1 100644 --- a/Tests/IsraelHiking.API.Tests/Services/NonApiMiddlewareTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/NonApiMiddlewareTests.cs @@ -113,6 +113,7 @@ public void TestCrawler_NotExistingPoi_ShouldReturnDefault() var fileInfo = Substitute.For(); fileInfo.CreateReadStream().Returns(new MemoryStream(new byte[] {1})); _homePageHelper.IndexFileInfo.Returns(fileInfo); + _pointsOfInterestProvider.GetFeatureById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _middleware.InvokeAsync(context, detectionService).Wait(); diff --git a/Tests/IsraelHiking.API.Tests/Services/Osm/DatabasesUpdaterServiceTests.cs b/Tests/IsraelHiking.API.Tests/Services/Osm/DatabasesUpdaterServiceTests.cs index 321588de1..2a7ae8961 100644 --- a/Tests/IsraelHiking.API.Tests/Services/Osm/DatabasesUpdaterServiceTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/Osm/DatabasesUpdaterServiceTests.cs @@ -95,34 +95,34 @@ public void TestRebuild_Highways_ShouldRebuildHighwaysAndPoints() { _service.Rebuild(new UpdateRequest {Highways = true}).Wait(); - _highwaysRepository.Received(1).UpdateHighwaysZeroDownTime(Arg.Any>()); + _highwaysRepository.Received(1).UpdateHighwaysZeroDownTime(Arg.Any>()); _pointsOfInterestRepository.StoreRebuildContext(Arg.Is(c => c.Succeeded == true)); } [TestMethod] public void TestRebuild_Points_ShouldRebuildPointsWhileMarkingOneAsDeleted() { var adapter = Substitute.For(); - adapter.GetAll().Returns(new List()); + adapter.GetAll().Returns(new List()); _pointsOfInterestAdapterFactory.GetAll().Returns(new[] {adapter}); - _externalSourcesRepository.GetExternalPoisBySource(Arg.Any()).Returns(new List()); + _externalSourcesRepository.GetExternalPoisBySource(Arg.Any()).Returns(new List()); var feature = new Feature(new Point(0, 0), new AttributesTable { {FeatureAttributes.NAME, "feature in database that needs to be deleted"}, {FeatureAttributes.POI_ID, "42"} }); feature.SetLastModified(new DateTime(0)); - _pointsOfInterestRepository.GetAllPointsOfInterest(Arg.Any()).Returns(new List {feature}); - _pointsOfInterestRepository.GetPointsOfInterestUpdates(Arg.Any(), Arg.Any()).Returns(new List()); - _featuresMergeExecutor.Merge(Arg.Any>(), Arg.Any>()).Returns(new List + _pointsOfInterestRepository.GetAllPointsOfInterest(Arg.Any()).Returns(new List {feature}); + _pointsOfInterestRepository.GetPointsOfInterestUpdates(Arg.Any(), Arg.Any()).Returns(new List()); + _featuresMergeExecutor.Merge(Arg.Any>(), Arg.Any>()).Returns(new List { - new (new Point(0,0), new AttributesTable { {FeatureAttributes.POI_ID, "1"}}) + new Feature(new Point(0,0), new AttributesTable { {FeatureAttributes.POI_ID, "1"}}) }); - _pointsOfInterestProvider.GetAll().Returns(new List()); + _pointsOfInterestProvider.GetAll().Returns(new List()); _service.Rebuild(new UpdateRequest {PointsOfInterest = true}).Wait(); - _pointsOfInterestRepository.Received(2).StorePointsOfInterestDataToSecondaryIndex(Arg.Any>()); - _pointsOfInterestRepository.Received(1).StorePointsOfInterestDataToSecondaryIndex(Arg.Is>(l => l.Any(f => f.Attributes.Exists(FeatureAttributes.POI_DELETED)))); + _pointsOfInterestRepository.Received(2).StorePointsOfInterestDataToSecondaryIndex(Arg.Any>()); + _pointsOfInterestRepository.Received(1).StorePointsOfInterestDataToSecondaryIndex(Arg.Is>(l => l.Any(f => f.Attributes.Exists(FeatureAttributes.POI_DELETED)))); _pointsOfInterestRepository.Received(1).SwitchPointsOfInterestIndices(); _pointsOfInterestRepository.StoreRebuildContext(Arg.Is(c => c.Succeeded == true)); } @@ -136,7 +136,7 @@ public void TestRebuild_Images_ShouldRebuildImages() {FeatureAttributes.IMAGE_URL, "imageUrl2"} }); feature.SetLastModified(new DateTime(0)); - _pointsOfInterestRepository.GetAllPointsOfInterest(false).Returns(new List {feature}); + _pointsOfInterestRepository.GetAllPointsOfInterest(false).Returns(new List {feature}); _osmRepository.GetImagesUrls(Arg.Any()).Returns(new List {imageUrl}); _service.Rebuild(new UpdateRequest {Images = true}).Wait(); @@ -150,7 +150,7 @@ public void TestRebuild_SiteMap_ShouldRebuildSiteMap() { _service.Rebuild(new UpdateRequest {SiteMap = true}).Wait(); - _pointsOfInterestFilesCreatorExecutor.Received(1).CreateSiteMapXmlFile(Arg.Any>()); + _pointsOfInterestFilesCreatorExecutor.Received(1).CreateSiteMapXmlFile(Arg.Any>()); _pointsOfInterestRepository.StoreRebuildContext(Arg.Is(c => c.Succeeded == true)); } @@ -159,12 +159,12 @@ public void TestRebuild_OfflinePointsFile_ShouldRebuildIt() { var feature = new Feature(new Point(0, 0), new AttributesTable()); feature.SetLastModified(new DateTime(0)); - _pointsOfInterestRepository.GetAllPointsOfInterest(false).Returns(new List {feature}); + _pointsOfInterestRepository.GetAllPointsOfInterest(false).Returns(new List {feature}); _elevationGateway.GetElevation(Arg.Any()).Returns(new[] {1.0}); _service.Rebuild(new UpdateRequest {OfflinePoisFile = true}).Wait(); - _pointsOfInterestFilesCreatorExecutor.Received(1).CreateOfflinePoisFile(Arg.Any>()); + _pointsOfInterestFilesCreatorExecutor.Received(1).CreateOfflinePoisFile(Arg.Any>()); _pointsOfInterestRepository.StoreRebuildContext(Arg.Is(c => c.Succeeded == true)); } diff --git a/Tests/IsraelHiking.API.Tests/Services/Osm/OsmLineAdderServiceTests.cs b/Tests/IsraelHiking.API.Tests/Services/Osm/OsmLineAdderServiceTests.cs index 9955bd397..0b98959c0 100644 --- a/Tests/IsraelHiking.API.Tests/Services/Osm/OsmLineAdderServiceTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/Osm/OsmLineAdderServiceTests.cs @@ -62,7 +62,7 @@ private void SetupHighway(int wayId, Coordinate[] coordinates, IAuthClient osmGa {FeatureAttributes.ID, wayId.ToString()}, {FeatureAttributes.POI_OSM_NODES, osmCompleteWay.Nodes.Select(n => n.Id.Value).Cast().ToList()} }; - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List { new Feature(new LineString(coordinates), table) }); @@ -73,7 +73,7 @@ public void AddLineWithTags_NoHighwaysInArea_ShouldAddTheLine() { long changesetId = 1; var osmGateway = SetupOsmGateway(changesetId); - _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List()); + _highwaysRepository.GetHighways(Arg.Any(), Arg.Any()).Returns(new List()); osmGateway.UploadChangeset(changesetId, Arg.Any()).Returns(new DiffResult { Results = new OsmGeoResult[0]}); var tags = new Dictionary { diff --git a/Tests/IsraelHiking.API.Tests/Services/Poi/INaturePointsOfInterestAdapterTests.cs b/Tests/IsraelHiking.API.Tests/Services/Poi/INaturePointsOfInterestAdapterTests.cs index da1151c6b..00d8edf72 100644 --- a/Tests/IsraelHiking.API.Tests/Services/Poi/INaturePointsOfInterestAdapterTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/Poi/INaturePointsOfInterestAdapterTests.cs @@ -39,15 +39,15 @@ public void GetSourceName_ShouldReturnINature() [TestMethod] public void GetPointsForIndexing_ShouldGetFromGateway() { - var features = new List + var features = new List { - new (new Point(0,0), new AttributesTable()), - new (new LineString(new [] { new Coordinate(0,0), new Coordinate(1,1)}), + new Feature(new Point(0,0), new AttributesTable()), + new Feature(new LineString(new [] { new Coordinate(0,0), new Coordinate(1,1)}), new AttributesTable { {FeatureAttributes.POI_SHARE_REFERENCE, "missing-url"} }), - new (new LineString(new [] { new Coordinate(0,0), new Coordinate(1,1)}), + new Feature(new LineString(new [] { new Coordinate(0,0), new Coordinate(1,1)}), new AttributesTable { {FeatureAttributes.POI_SHARE_REFERENCE, "share-url"} @@ -66,7 +66,7 @@ public void GetPointsForIndexing_ShouldGetFromGateway() [TestMethod] public void GetUpdates_ShouldGetThem() { - var list = new List(); + var list = new List(); _iNatureGateway.GetUpdates(Arg.Any()).Returns(list); var results = _adapter.GetUpdates(DateTime.Now).Result; diff --git a/Tests/IsraelHiking.API.Tests/Services/Poi/PointsOfInterestProviderTests.cs b/Tests/IsraelHiking.API.Tests/Services/Poi/PointsOfInterestProviderTests.cs index 098837f36..b18385f5c 100644 --- a/Tests/IsraelHiking.API.Tests/Services/Poi/PointsOfInterestProviderTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/Poi/PointsOfInterestProviderTests.cs @@ -55,7 +55,6 @@ public void TestInitialize() ElevationGateway, _osmGeoJsonPreprocessorExecutor, _osmRepository, - _itmWgs84MathTransfromFactory, _latestFileGateway, _wikimediaCommonGateway, new Base64ImageStringToFileConverter(), @@ -81,7 +80,7 @@ public void GetFeature_FilterRelevant_ShouldReturnEmptyList() Attributes = new AttributesTable { { FeatureAttributes.POI_ID, "42" } } }; feature.SetLocation(new Coordinate(0, 0)); - _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, null).Returns(new List { feature }); + _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, null).Returns(new List { feature }); var results = _adapter.GetFeatures(null, null, null, null).Result; @@ -95,7 +94,7 @@ public void GetFeature_EnglishTitleOnly_ShouldReturnIt() var feature = GetValidFeature("poiId", Sources.OSM); feature.Attributes.DeleteAttribute(FeatureAttributes.NAME); feature.Attributes.Add("name:en", name); - _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, "en").Returns(new List { feature }); + _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, "en").Returns(new List { feature }); var result = _adapter.GetFeatures(null, null, null, "en").Result; @@ -111,7 +110,7 @@ public void GetFeature_ImageAndDescriptionOnly_ShouldReturnIt() feature.Attributes.DeleteAttribute(FeatureAttributes.NAME); feature.Attributes.Add(FeatureAttributes.IMAGE_URL, FeatureAttributes.IMAGE_URL); feature.Attributes.Add(FeatureAttributes.WIKIPEDIA, FeatureAttributes.DESCRIPTION); - _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, "he").Returns(new List { feature }); + _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, "he").Returns(new List { feature }); var result = _adapter.GetFeatures(null, null, null, "he").Result; @@ -124,7 +123,7 @@ public void GetFeature_NoIcon_ShouldReturnItWithSearchIcon() { var feature = GetValidFeature("poiId", Sources.OSM); feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ICON, string.Empty); - _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, "he").Returns(new List { feature }); + _pointsOfInterestRepository.GetPointsOfInterest(null, null, null, "he").Returns(new List { feature }); var result = _adapter.GetFeatures(null, null, null, "he").Result; @@ -225,11 +224,12 @@ public void AddFeature_ShouldUpdateOsmAndElasticSearch() feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ICON, _tagsHelper.GetCategoriesByGroup(Categories.POINTS_OF_INTEREST).First().Icon); feature.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "he.wikipedia.org/wiki/%D7%AA%D7%9C_%D7%A9%D7%9C%D7%9D"); _imagesUrlsStorageExecutor.GetImageUrlIfExists(Arg.Any(), Arg.Any()).Returns((string)null); - + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); + var results = _adapter.AddFeature(feature, gateway, language).Result; Assert.IsNotNull(results); - _pointsOfInterestRepository.Received(1).UpdatePointsOfInterestData(Arg.Any>()); + _pointsOfInterestRepository.Received(1).UpdatePointsOfInterestData(Arg.Any>()); gateway.Received().CreateElement(Arg.Any(), Arg.Is(x => x.Tags[FeatureAttributes.WIKIPEDIA + ":" + language].Contains("תל שלם"))); gateway.Received().CreateChangeset(Arg.Any()); gateway.Received().CloseChangeset(Arg.Any()); @@ -244,11 +244,13 @@ public void AddFeature_WikipediaMobileLink_ShouldUpdateOsmAndElasticSearch() var feature = GetValidFeature("42", Sources.OSM); feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ICON, _tagsHelper.GetCategoriesByGroup(Categories.POINTS_OF_INTEREST).First().Icon); feature.Attributes.AddOrUpdate(FeatureAttributes.WEBSITE, "https://he.m.wikipedia.org/wiki/%D7%96%D7%95%D7%94%D7%A8_(%D7%9E%D7%95%D7%A9%D7%91)"); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); + var results = _adapter.AddFeature(feature, gateway, language).Result; Assert.IsNotNull(results); - _pointsOfInterestRepository.Received(1).UpdatePointsOfInterestData(Arg.Any>()); + _pointsOfInterestRepository.Received(1).UpdatePointsOfInterestData(Arg.Any>()); gateway.Received().CreateElement(Arg.Any(), Arg.Is(x => x.Tags[FeatureAttributes.WIKIPEDIA + ":" + language].Contains("זוהר"))); } @@ -381,7 +383,7 @@ public void GetPointsForIndexing_ShouldGetThem() [TestMethod] public void GetClosestPoint_ShouldGetTheClosesOsmPoint() { - var list = new List + var list = new List { new Feature(new LineString(Array.Empty()), new AttributesTable { @@ -413,7 +415,7 @@ public void GetUpdates_TooOld_ShouldThrow() public void GetUpdates_ShouldReturnThem() { _pointsOfInterestRepository.GetPointsOfInterestUpdates(Arg.Any(), Arg.Any()) - .Returns(new List()); + .Returns(new List()); _pointsOfInterestRepository.GetLastSuccessfulRebuildTime().Returns(DateTime.Now); var results = _adapter.GetUpdates(DateTime.Now, DateTime.Now).Result; @@ -471,6 +473,7 @@ public void UpdateFeature_WithImageInRepository_ShouldNotUploadImage() "8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="} } }); _imagesUrlsStorageExecutor.GetImageUrlIfExists(Arg.Any(), Arg.Any()).Returns("some-url"); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable @@ -503,6 +506,7 @@ public void UpdateFeature_NewTitleDescriptionUrlsLocation_ShouldUpdateInOSM() poi.Attributes.AddOrUpdate(FeatureAttributes.NAME + ":" + Languages.HEBREW, "new name"); poi.Attributes.AddOrUpdate(FeatureAttributes.DESCRIPTION + ":" + Languages.HEBREW, "new description"); poi.SetLocation(new Coordinate(6, 5)); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable @@ -565,6 +569,7 @@ public void UpdateFeature_IconChange_ShouldUpdateInOSM() { FeatureAttributes.ID, id }, { FeatureAttributes.POI_ICON, "icon-ruins" }, }); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable @@ -595,6 +600,7 @@ public void UpdateFeature_RemoveUrl_ShouldUpdateInOSM() { FeatureAttributes.POI_ICON, "icon-ruins" }, { FeatureAttributes.POI_REMOVED_URLS, new [] { "url-to-remove" } } }); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable @@ -627,6 +633,7 @@ public void UpdateFeature_RemoveWikiUrl_ShouldUpdateInOSM() { FeatureAttributes.POI_ICON, "icon-ruins" }, { FeatureAttributes.POI_REMOVED_URLS, new [] { "https://he.wikipedia.org/wiki/123" } } }); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable @@ -660,6 +667,7 @@ public void UpdateFeature_RemoveWikiUrl_ShouldUpdateInOSMButNotRemoveEnglishWiki { FeatureAttributes.POI_ICON, "icon-ruins" }, { FeatureAttributes.POI_REMOVED_URLS, new [] { "https://he.wikipedia.org/wiki/123" } } }); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable @@ -695,6 +703,7 @@ public void UpdateFeature_RemoveImage_ShouldUpdateInOSM() { FeatureAttributes.POI_ICON, "icon-ruins" }, { FeatureAttributes.POI_REMOVED_IMAGES, new [] { "image-to-remove" } } }); + _pointsOfInterestRepository.GetPointOfInterestById(Arg.Any(), Arg.Any()).Returns(null as IFeature); _pointsOfInterestRepository.GetPointOfInterestById(id, Sources.OSM).Returns(new Feature { Attributes = new AttributesTable diff --git a/Tests/IsraelHiking.API.Tests/Services/Poi/WikipediaPointsOfInterestAdapterTests.cs b/Tests/IsraelHiking.API.Tests/Services/Poi/WikipediaPointsOfInterestAdapterTests.cs index e711689ef..d149c688d 100644 --- a/Tests/IsraelHiking.API.Tests/Services/Poi/WikipediaPointsOfInterestAdapterTests.cs +++ b/Tests/IsraelHiking.API.Tests/Services/Poi/WikipediaPointsOfInterestAdapterTests.cs @@ -32,7 +32,7 @@ public void GetAll_ShouldGetAllPointsFromGateway() { var feature = GetValidFeature("1", Sources.WIKIPEDIA); feature.SetId(); - var list = new List { feature }; + var list = new List { feature }; _wikipediaGateway.GetByBoundingBox(Arg.Any(), Arg.Any(), Arg.Any()).Returns(list); _wikipediaGateway.GetByPagesTitles(Arg.Any(), Arg.Any()).Returns(list); _overpassTurboGateway.GetWikipediaLinkedTitles().Returns(new List()); diff --git a/Tests/IsraelHiking.DataAccess.Tests/ElasticSearch/ElasticSearchGatewayTests.cs b/Tests/IsraelHiking.DataAccess.Tests/ElasticSearch/ElasticSearchGatewayTests.cs index ae86db1c6..7d0931c14 100644 --- a/Tests/IsraelHiking.DataAccess.Tests/ElasticSearch/ElasticSearchGatewayTests.cs +++ b/Tests/IsraelHiking.DataAccess.Tests/ElasticSearch/ElasticSearchGatewayTests.cs @@ -10,10 +10,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text.Json; -using System.Text.Json.Serialization; using System.Threading.Tasks; -using NetTopologySuite.IO.Converters; namespace IsraelHiking.DataAccess.Tests.ElasticSearch { @@ -100,7 +97,7 @@ public void GetContainers_ShouldGetSome() [Ignore] public void GetPoisBySource_ShouldGetThem() { - var tasks = new List>> + var tasks = new List>> { _gateway.GetExternalPoisBySource(Sources.INATURE), _gateway.GetExternalPoisBySource(Sources.NAKEB), @@ -152,7 +149,7 @@ public void UpdatePointOfInterest_ShouldBeAbleToGetRightAfterAdding() }); feature.SetId(); feature.SetTitles(); - _gateway.UpdatePointsOfInterestData(new List { feature }).Wait(); + _gateway.UpdatePointsOfInterestData(new List { feature }).Wait(); var results = _gateway.GetPointOfInterestById(id, Sources.OSM).Result; Assert.IsNotNull(results); }