public void GetQueryStringParametersWhenKeyIsStringEmptyTest() { var request = new PlacesFindSearchRequest { Key = string.Empty, Location = new Location(0, 0), Radius = 5000 }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.AreEqual(exception.Message, "Key is required"); }
public void PlacesFindSearchWhenAsyncAndCancelledTest() { var request = new PlacesFindSearchRequest { Key = this.ApiKey, Input = "picadelly circus" }; var cancellationTokenSource = new CancellationTokenSource(); var task = GooglePlaces.FindSearch.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 PlacesFindSearchWhenBoundsTest() { var request = new PlacesFindSearchRequest { Key = this.ApiKey, Input = "picadelly circus", Bounds = new ViewPort { NorthEast = new Location(51.5100913, -0.1345676), SouthWest = new Location(50.5100913, -0.0345676) } }; var response = GooglePlaces.FindSearch.Query(request); Assert.IsNotNull(response); Assert.AreEqual(Status.Ok, response.Status); }
public void GetUriWhenBoundsTest() { var request = new PlacesFindSearchRequest { Key = "abc", Input = "test", Bounds = new ViewPort { NorthEast = new Location(1, 1), SouthWest = new Location(2, 2) } }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/place/findplacefromtext/json?key={request.Key}&input={request.Input}&inputtype={request.Type.ToString().ToLower()}&fields=place_id&language={request.Language.ToCode()}&locationbias=rectangle%3A{Uri.EscapeDataString(request.Bounds.SouthWest.ToString())}%7C{Uri.EscapeDataString(request.Bounds.NorthEast.ToString())}", uri.PathAndQuery); }
public void PlacesFindSearchWhenKeyIsNullTest() { var request = new PlacesFindSearchRequest { Key = null, Input = "picadelly circus" }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.FindSearch.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 PlacesNearBySearchWhenInvalidKeyTest() { var request = new PlacesFindSearchRequest { Key = "test", Input = "test" }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.FindSearch.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerExceptions.FirstOrDefault(); Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual("RequestDenied: The provided API key is invalid.", innerException.Message); }
public void PlacesFindSearchWhenQueryIsStringEmptyTest() { var request = new PlacesFindSearchRequest { Key = this.ApiKey, Input = string.Empty }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.FindSearch.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Input is required"); }
public void GetQueryStringParametersTest() { var request = new PlacesFindSearchRequest { Key = "key", Input = "input" }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var key = queryStringParameters.FirstOrDefault(x => x.Key == "key"); var keyExpected = request.Key; Assert.IsNotNull(key); Assert.AreEqual(keyExpected, key.Value); var input = queryStringParameters.FirstOrDefault(x => x.Key == "input"); var inputExpected = request.Input; Assert.IsNotNull(input); Assert.AreEqual(inputExpected, input.Value); var type = queryStringParameters.FirstOrDefault(x => x.Key == "inputtype"); Assert.IsNotNull(type); Assert.AreEqual("textquery", type.Value); var language = queryStringParameters.FirstOrDefault(x => x.Key == "language"); Assert.IsNotNull(language); Assert.AreEqual("en", language.Value); var fields = queryStringParameters.FirstOrDefault(x => x.Key == "fields"); Assert.IsNotNull(fields); Assert.AreEqual("place_id", fields.Value); var locationbias = queryStringParameters.FirstOrDefault(x => x.Key == "locationbias"); Assert.IsNotNull(locationbias); Assert.AreEqual("ipbias", locationbias.Value); }
public void PlacesFindSearchTest() { var request = new PlacesFindSearchRequest { Key = this.ApiKey, Input = "picadelly circus", Type = InputType.TextQuery }; var response = GooglePlaces.FindSearch.Query(request); Assert.IsNotNull(response); Assert.AreEqual(Status.Ok, response.Status); var candidate = response.Candidates.FirstOrDefault(); Assert.IsNotNull(candidate); Assert.IsNotNull(candidate.PlaceId); }
public void PlacesFindSearchWhenInputIsNullTest() { var request = new PlacesFindSearchRequest { Key = this.ApiKey, Input = null }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.FindSearch.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, "Input is required"); }
public void PlacesFindSearchWhenKeyIsStringEmptyTest() { var request = new PlacesFindSearchRequest { Key = string.Empty, Input = "picadelly circus" }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.FindSearch.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, "Key is required"); }
public void GetQueryStringParametersWhenFieldsTest() { var request = new PlacesFindSearchRequest { Key = "key", Input = "input", Fields = FieldTypes.Name | FieldTypes.Place_Id }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var fields = queryStringParameters.FirstOrDefault(x => x.Key == "fields"); var requestedFields = Enum.GetValues(typeof(FieldTypes)) .Cast <FieldTypes>() .Where(x => request.Fields.HasFlag(x) && x != FieldTypes.Basic && x != FieldTypes.Contact && x != FieldTypes.Atmosphere) .Aggregate(string.Empty, (current, x) => $"{current}{x.ToString().ToLowerInvariant()},"); var fieldsExpected = requestedFields.EndsWith(",") ? requestedFields[..^ 1] : requestedFields;
public void PlacesFindSearchTest() { var request = new PlacesFindSearchRequest { Key = this.ApiKey, Input = "picadelly circus", Fields = FieldTypes.Formatted_Address | FieldTypes.Geometry | FieldTypes.Icon | FieldTypes.Id | FieldTypes.Name | FieldTypes.Permanently_Closed | FieldTypes.Photos | FieldTypes.Place_Id | FieldTypes.Plus_Code | //FieldTypes.Scope | //FieldTypes.Opening_Hours | FieldTypes.Price_Level | FieldTypes.Rating, Type = InputType.TextQuery }; var response = GooglePlaces.FindSearch.Query(request); Assert.IsNotNull(response); Assert.AreEqual(Status.Ok, response.Status); var candidate = response.Candidates.FirstOrDefault(); Assert.IsNotNull(candidate); Assert.IsNotNull(candidate.PlaceId); Assert.IsNotNull(candidate.Geometry); Assert.IsNotNull(candidate.Geometry.Location); Assert.IsNotNull(candidate.Geometry.ViewPort); Assert.AreEqual("https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png", candidate.Icon); }