public void SnapToRoadWhenAsyncTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new[] { new Location(60.170880, 24.942795), new Location(60.170879, 24.942796), new Location(60.170877, 24.942796) } }; var result = GoogleMaps.SnapToRoad.QueryAsync(request).Result; Assert.IsNotNull(result); Assert.AreEqual(Status.Ok, result.Status); var snappedPoints = result.SnappedPoints?.ToArray(); Assert.IsNotNull(snappedPoints); Assert.AreEqual(3, snappedPoints.Length); Assert.AreEqual(0, snappedPoints[0].OriginalIndex); Assert.AreEqual(60.170877918672588, snappedPoints[0].Location.Latitude, 0.0001); Assert.AreEqual(24.942699821922421, snappedPoints[0].Location.Longitude, 0.0001); Assert.AreEqual(1, snappedPoints[1].OriginalIndex); Assert.AreEqual(60.170876898776406, snappedPoints[1].Location.Latitude, 0.0001); Assert.AreEqual(24.942699912064771, snappedPoints[1].Location.Longitude, 0.0001); Assert.AreEqual(2, snappedPoints[2].OriginalIndex); Assert.AreEqual(60.170874902634374, snappedPoints[2].Location.Latitude, 0.0001); Assert.AreEqual(24.942700088491474, snappedPoints[2].Location.Longitude, 0.0001); }
public void GetQueryStringParametersTest() { var request = new SnapToRoadsRequest { Key = "key", Path = new[] { new Coordinate(1, 1), new Coordinate(2, 2) } }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var key = queryStringParameters.SingleOrDefault(x => x.Key == "key"); var keyExpected = request.Key; Assert.IsNotNull(key); Assert.AreEqual(keyExpected, key.Value); var points = queryStringParameters.FirstOrDefault(x => x.Key == "path"); var pointsExpected = string.Join("|", request.Path); Assert.IsNotNull(points); Assert.AreEqual(pointsExpected, points.Value); var interpolate = queryStringParameters.FirstOrDefault(x => x.Key == "interpolate"); var interpolateExpected = request.Interpolate.ToString().ToLower(); Assert.IsNotNull(interpolate); Assert.AreEqual(interpolateExpected, interpolate.Value); }
public void ConstructorDefaultTest() { var request = new SnapToRoadsRequest(); Assert.IsTrue(request.IsSsl); Assert.IsFalse(request.Interpolate); }
public void SnapToRoadWhenPathIsNullTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey }; var exception = Assert.Throws <ArgumentException>(() => GoogleMaps.SnapToRoad.Query(request)); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Path is required"); }
public void SnapToRoadAsyncTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new[] { new Entities.Maps.Roads.Common.Location(0, 0) } }; var result = GoogleMaps.SnapToRoad.QueryAsync(request).Result; Assert.IsNotNull(result); Assert.AreEqual(Status.Ok, result.Status); }
public void SnapToRoadWhenKeyIsStringEmptyTest() { var request = new SnapToRoadsRequest { Key = string.Empty, Path = new[] { new Location(0, 0) } }; var exception = Assert.Throws <ArgumentException>(() => GoogleMaps.SnapToRoad.Query(request)); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Key is required"); }
public void SnapToRoadWhenPathIsEmptyTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new Entities.Maps.Roads.Common.Location[0] }; var exception = Assert.Throws <ArgumentException>(() => GoogleMaps.SnapToRoad.Query(request)); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Path is required."); }
public void SnapToRoadWhenKeyIsNullTest() { var request = new SnapToRoadsRequest { Key = null, Path = new[] { new Entities.Maps.Roads.Common.Location(0, 0) } }; var exception = Assert.Throws <ArgumentException>(() => GoogleMaps.SnapToRoad.Query(request)); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Key is required."); }
public void GetQueryStringParametersTest() { var request = new SnapToRoadsRequest { Key = "abc", Path = new[] { new Location(1, 1), new Location(2, 2) } }; Assert.DoesNotThrow(() => request.GetQueryStringParameters()); }
public void GetQueryStringParametersWhenKeyIsStringEmptyTest() { var request = new SnapToRoadsRequest { Key = string.Empty }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "'Key' is required"); }
public void GetQueryStringParametersWhenPathIsNullTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Path is required"); }
public void GetUriTest() { var request = new SnapToRoadsRequest { Key = "abc", Path = new[] { new Location(1, 1), new Location(2, 2) } }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/v1/snapToRoads?key={request.Key}&path={Uri.EscapeDataString(string.Join("|", request.Path))}&interpolate={request.Interpolate.ToString().ToLower()}", uri.PathAndQuery); }
public void SnapToRoadWhenAsyncTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new[] { new Coordinate(60.170880, 24.942795), new Coordinate(60.170879, 24.942796), new Coordinate(60.170877, 24.942796) } }; var result = GoogleMaps.SnapToRoad.QueryAsync(request).Result; Assert.IsNotNull(result); Assert.AreEqual(Status.Ok, result.Status); }
public void SnapToRoadWhenPathIsNullTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey }; var exception = Assert.Throws <AggregateException>(() => GoogleMaps.SnapToRoad.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Path is required"); }
public void GetQueryStringParametersWhenPathCotaninsMoreThanHundredLocationsTest() { var request = new SnapToRoadsRequest { Key = "abc", Path = new Coordinate[101] }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "'Path' must contain equal or less than 100 coordinates"); }
public void SnapToRoadWhenAsyncAndCancelledTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new[] { new Location(0, 0) } }; var cancellationTokenSource = new CancellationTokenSource(); var task = GoogleMaps.SnapToRoad.QueryAsync(request, cancellationTokenSource.Token); cancellationTokenSource.Cancel(); var exception = Assert.Throws <OperationCanceledException>(() => task.Wait(cancellationTokenSource.Token)); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "The operation was canceled."); }
public void GetQueryStringParametersWhenPathCotaninsMoreThan100LocationsTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new Location[101] }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Path must contain less than 100 locations"); }
public void GetQueryStringParametersWhenKeyIsNullTest() { var request = new SnapToRoadsRequest { Key = null, Path = new[] { new Location(0, 0) } }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "Key is required"); }
protected override async Task <List <Coordinate>?> ExecuteRequestAsync( List <Coordinate> coordinates, CancellationToken cancellationToken) { var request = new SnapToRoadsRequest { Interpolate = true, Key = APIKey, Path = coordinates.Select(c => new GoogleApi.Entities.Maps.Roads.Common.Coordinate(c.Latitude, c.Longitude)) }; SnapToRoadsResponse?result = null; try { result = await GoogleMaps.SnapToRoad.QueryAsync(request, cancellationToken); } catch (Exception e) { Logger?.Error <string>("Snap to road request failed. Message was '{0}'", e.Message); return(null); } if (result == null) { Logger?.Error("Snap to road request failed"); return(null); } var errors = result.Errors?.ToList() ?? new List <Error>(); if (errors.Count <= 0) { return(result.SnappedPoints .Select(p => new Coordinate(p.Location.Latitude, p.Location.Longitude)) .ToList()); } foreach (var error in errors) { Logger?.Error <string>("Snap to road error: {0}", error.ErrorMessage); } return(null); }
public void SnapToRoadWhenKeyIsStringEmptyTest() { var request = new SnapToRoadsRequest { Key = string.Empty, Path = new[] { new Location(0, 0) } }; var exception = Assert.Throws <AggregateException>(() => GoogleMaps.SnapToRoad.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Key is required"); }
public void SnapToRoadWhenPathIsEmptyTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new Location[0] }; var exception = Assert.Throws <AggregateException>(() => GoogleMaps.SnapToRoad.Query(request)); Assert.IsNotNull(exception); Assert.AreEqual("One or more errors occurred.", exception.Message); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Path is required"); }
public void SnapToRoadWhenAsyncAndTimeoutTest() { var request = new SnapToRoadsRequest { Key = this.ApiKey, Path = new[] { new Location(0, 0) } }; var exception = Assert.Throws <AggregateException>(() => { var result = GoogleMaps.SnapToRoad.QueryAsync(request, TimeSpan.FromMilliseconds(1)).Result; Assert.IsNull(result); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "One or more errors occurred."); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(innerException.GetType(), typeof(TaskCanceledException)); Assert.AreEqual(innerException.Message, "A task was canceled."); }
public void SnapToRoadWhenInvalidKeyTest() { var request = new SnapToRoadsRequest { Key = "test", Path = new[] { new Location(60.170880, 24.942795), new Location(60.170879, 24.942796), new Location(60.170877, 24.942796) } }; var exception = Assert.Throws <AggregateException>(() => GoogleMaps.SnapToRoad.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerExceptions.FirstOrDefault(); Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException).ToString(), innerException.GetType().ToString()); Assert.AreEqual("Response status code does not indicate success: 400 (Bad Request).", innerException.Message); }