public async Task When_fetching_images_the_progress_is_being_updated_and_images_downloaded() { // Arrange var placemark = new MooiPlacemark(); var group = new MooiCluster { Placemarks = { placemark } }; var document = new MooiDocument { Sections = { new MooiSection { Clusters = { group} } } }; var tempPath = "temp-path"; var overviewBytes = new byte[] { 0x22 }; var thumbnailBytes = new byte[] { 0x44 }; _resourceNameMock.Setup(x => x.CreateFileNameForOverviewMap(group)).Returns("overview-path"); _resourceNameMock.Setup(x => x.CreateFileNameForPlacemarkThumbnail(placemark)).Returns("thumb-path"); _hereMock.Setup(x => x.FetchOverviewMap(group)) .Returns(Task.FromResult(overviewBytes)); _hereMock.Setup(x => x.FetchThumbnail(placemark)) .Returns(Task.FromResult(thumbnailBytes)); // Act await _fetcher.Object.FetchMapImages(document, tempPath, _progressMock.Object); // Verify _fileMock.Verify(x => x.WriteBytesAsync(tempPath + @"\overview-path", overviewBytes)); _fileMock.Verify(x => x.WriteBytesAsync(tempPath + @"\thumb-path", thumbnailBytes)); _progressMock.Verify(x => x.ReportFetchImagesCount(1 + 1), Times.Once); _progressMock.Verify(x => x.ReportFetchImageProcessed(), Times.Exactly(2)); }
public void ExtendPlacemarkWithVenueData(MooiPlacemark placemark) { if (placemark.AttachedVenues == null) { return; } foreach (var venue in placemark.AttachedVenues) { switch (venue.SourceType) { case VenueSource.Here: break; case VenueSource.Foursquare: var fsq = venue as FoursquareVenue; if (fsq == null) { continue; } placemark.Images.AddRange(fsq.PhotoUrls.Take(MAX_PHOTOS_TO_PICK_FROM_VENUE)); break; case VenueSource.Undefined: default: throw new ArgumentOutOfRangeException(); } } }
public async Task <byte[]> FetchThumbnail(MooiPlacemark placemark) { if (placemark.Type == PlacemarkType.Route) { throw new NotSupportedException("Routes are not supported"); } var url = $"c={_formatter.FormatCoordinates(null, placemark)}&z={THUMBNAIL_MAP_ZOOM}&ppi=320&w=600&h=390"; return(await DownloadData(IMAGES_MAPVIEW_URL, url)); }
public void When_creating_model_the_discovered_places_are_appended_correctly() { // Arrange var kmlDocument = new KmlDocument { Folders = { new KmlFolder(new List <KmlPlacemark> { new KmlPlacemark() }) } }; var venue = new DummyVenue { Title = "venue", IconUrl = new Uri("http://url"), Coordinate = new GeoCoordinate(1, 2) }; var discoveredPlaces = new List <DiscoveredPlace> { new DiscoveredPlace { Venue = new DummyVenue(), AttachedToPlacemark = kmlDocument.Folders[0].Placemarks[0] }, new DiscoveredPlace { Venue = venue } }; var placemarkExplored = new MooiPlacemark { Name = venue.Title, IconPath = venue.IconUrl.ToString(), Coordinates = new [] { venue.Coordinate } }; _mooiGroupFactoryMock.Setup(x => x.CreateList(kmlDocument.Folders[0], discoveredPlaces, string.Empty)) .Returns(new List <MooiCluster>()); _mooiGroupFactoryMock.Setup(x => x.CreateList(It.Is <KmlFolder>(f => f.Name == Resources.Kml_Folder_Explored), discoveredPlaces, string.Empty)) .Returns((KmlFolder folder, List <DiscoveredPlace> dps, string path) => new List <MooiCluster> { new MooiCluster { Placemarks = { placemarkExplored } } }); // Act var result = _factory.Create(kmlDocument, discoveredPlaces, string.Empty); // Verify var sectionWithExploredPlacemarks = result.Sections[1]; Assert.AreEqual(kmlDocument.Folders[0].Name, result.Sections[0].Name); Assert.AreEqual(Resources.Kml_Folder_Explored, sectionWithExploredPlacemarks.Name); Assert.AreEqual(1, sectionWithExploredPlacemarks.Clusters.Count); Assert.AreEqual(1, sectionWithExploredPlacemarks.Clusters[0].Placemarks.Count); Assert.AreEqual(placemarkExplored, sectionWithExploredPlacemarks.Clusters[0].Placemarks[0]); }
public void Only_supported_venue_types_are_processed() { // Arrange var placemark = new MooiPlacemark { AttachedVenues = Enum.GetValues(typeof(VenueSource)).Cast <VenueSource>() .Where(x => x != VenueSource.Undefined) .Select(x => (VenueBase) new DummyVenue(x)) .ToArray() }; // Act _factory.Object.ExtendPlacemarkWithVenueData(placemark); }
public async Task When_fetching_placemark_thumbnail_the_parameters_passed_correctly() { // Arrange var placemark = new MooiPlacemark { Coordinates = new [] { new GeoCoordinate(1.11, 2.22) } }; var bytesToMatch = SetupWebClient(uri => uri.AbsoluteUri.StartsWith(HereAdapter.IMAGES_MAPVIEW_URL), p => p.Contains("1.11,2.22") && p.Contains("z=18")); // Act var bytes = await _here.Object.FetchThumbnail(placemark); // Verify CollectionAssert.AreEqual(bytesToMatch, bytes); }
private async Task FetchPlacemarkMapImage(MooiPlacemark placemark, string tempPath) { if (placemark.Type == PlacemarkType.Point) { var imageBytes = await _hereAdapter.FetchThumbnail(placemark); if (imageBytes == null) { _logger.Warn($"Was unable to download thumbnail map image for '{placemark.Id}'"); return; } var filePath = Path.Combine(tempPath, _resourceName.CreateFileNameForPlacemarkThumbnail(placemark)); await _file.WriteBytesAsync(filePath, imageBytes); _logger.Info($"A thumbnail map image for '{placemark.Id}' has been successfully downloaded"); } }
private MooiPlacemarkDto CreatePlacemark(MooiPlacemark placemark) { var pm = new MooiPlacemarkDto { Id = placemark.Id, Index = placemark.Cluster.Placemarks.IndexOf(placemark) + 1, Name = placemark.Name, Description = placemark.Description, Images = placemark.Images.ToArray(), Coordinates = placemark.Coordinates.Select(ConvertCoordinateToString).ToArray(), AttachedVenues = placemark.AttachedVenues.Select(x => _venueConverters[x.SourceType](x)).ToArray(), IconPath = placemark.IconPathIsOnWeb ? placemark.IconPath : ConvertToLocalFileUrl(placemark.IconPath), ThumbnailFilePath = ConvertToLocalFileUrl(placemark.ThumbnailMapFilePath), IsShape = placemark.IsShape, Distance = placemark.Distance }; return(pm); }
public MooiPlacemark Create(KmlPlacemark kmlPlacemark, IEnumerable <VenueBase> venues, string reportTempPath) { var descriptionAndImages = ExtractImagesFromContent(kmlPlacemark.Description); var description = FilterContent(descriptionAndImages.filteredContent); var placemark = new MooiPlacemark { Name = kmlPlacemark.Name, Description = description, AttachedVenues = venues?.ToArray(), Coordinates = kmlPlacemark.Coordinates, IconPath = kmlPlacemark.IconPath }; if (descriptionAndImages.images != null) { placemark.Images.AddRange(descriptionAndImages.images); } if (placemark.IconPath != null && !placemark.IconPathIsOnWeb) { placemark.IconPath = Path.Combine(reportTempPath, placemark.IconPath); } placemark.ThumbnailMapFilePath = Path.Combine(reportTempPath, _resourceName.CreateFileNameForPlacemarkThumbnail(placemark)); placemark.IsShape = _kmlCalculator.PlacemarkIsShape(placemark); if (placemark.IsShape) { var distanceInMeters = _kmlCalculator.CalculateRouteDistanceInMeters(placemark); placemark.Distance = _formatter.FormatDistance(distanceInMeters); } ExtendPlacemarkWithVenueData(placemark); return(placemark); }
public void Trim_out_coordinates_when_too_much_passed_within_route() { // Arrange var routePlacemarkToInclude = new MooiPlacemark { Coordinates = Enumerable.Range(1, HereAdapter.TOO_MUCH_OF_COORDINATE_POINTS * 3) .Select(x => new GeoCoordinate(x * 0.001, x * 0.001)).ToArray() }; var placemarkShouldBeExcluded = new MooiPlacemark { Coordinates = new[] { new GeoCoordinate(1, 1) } }; var group = new MooiCluster { Placemarks = { routePlacemarkToInclude, placemarkShouldBeExcluded } }; // Act var result = _here.Object.GetAndTrimRouteCoordinates(group); // Verify Assert.AreEqual(HereAdapter.TOO_MUCH_OF_COORDINATE_POINTS, result.Coordinates.Length); }
public string CreateFileNameForPlacemarkThumbnail(MooiPlacemark placemark) { return($"{placemark.Id}.jpg"); }
private void AppendPlacemarkToCluster(MooiPlacemark placemark, MooiCluster cluster) { placemark.Cluster = cluster; cluster.Placemarks.Add(placemark); }