public void GetUriTest() { var request = new PlacesDetailsRequest { Key = "abc", PlaceId = "abc" }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/place/details/json?key={request.Key}&placeid={request.PlaceId}&language={request.Language.ToCode()}&fields=address_component%2Cadr_address%2Calt_id%2Cformatted_address%2Cgeometry%2Cicon%2Cid%2Cname%2Cpermanently_closed%2Cphoto%2Cplace_id%2Cplus_code%2Cscope%2Ctype%2Curl%2Cutc_offset%2Cvicinity", uri.PathAndQuery); }
public void GetUriTest() { var request = new PlacesDetailsRequest { Key = "abc", PlaceId = "abc" }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/place/details/json?key={request.Key}&placeid={request.PlaceId}&language={request.Language.ToCode()}", uri.PathAndQuery); }
public void ReturnsStronglyTypedPriceLevel() { var request = new PlacesDetailsRequest { ApiKey = ApiKey, PlaceId = GetMyPlaceId(), }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); Assert.That(new PriceLevel[] { result.Result.PriceLevel.Value }, Is.SubsetOf(anyPriceLevel)); }
private async void interestedBtn_Clicked(object sender, EventArgs e) { Button button = (Button)sender; DisableParent(button); var placeChosen = places[currentPlaceIndex]; var placeDetailsRequest = new PlacesDetailsRequest() { PlaceId = placeChosen.Id }; try { var httpAddress = AppSettings.GetValue("PlaceDetailsRequestApi"); placeDetails = (PlaceDetails)(await placeDetailsRequest.SendAsync(httpAddress)); if (placeDetails == null) { var missingDetailsMsg = new Label { Text = "I'm sorry but " + places[currentPlaceIndex].Name + " didn't provide their contact details", Style = Application.Current.Resources["DefaultLabelStyle"] as Style }; MainPanel.Children.Add(missingDetailsMsg); await AddLoaderToView(MainPanel, 2000); var additionalMsg = new Label { Text = "I'll look for some other places you can go...", Style = Application.Current.Resources["DefaultLabelStyle"] as Style }; MainPanel.Children.Add(additionalMsg); await AddLoaderToView(MainPanel, 2000); currentPlaceIndex++; CreatePlaceSuggestion(MainPanel); } else { CreatePlaceDetailsSuggestion(MainPanel); } } catch (Exception ex) { Debug.WriteLine(ex); } }
public void ReturnsPhotos() { var request = new PlacesDetailsRequest { ApiKey = ApiKey, PlaceId = "ChIJZ3VuVMQdLz4REP9PWpQ4SIY" }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); Assert.IsNotEmpty(result.Result.Photos); }
public void ReturnsNotFoundForWrongReferenceString() { var request = new PlacesDetailsRequest { ApiKey = base.ApiKey, // Needs to be a correct looking reference. 1 character too short or long and google will return INVALID_REQUEST instead. PlaceId = "ChIJbWWgrQAVkFQReAwrXXWzlYs" }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.NOT_FOUND, result.Status); }
public void GetUriWhenExtensionsTest() { var request = new PlacesDetailsRequest { Key = "abc", PlaceId = "abc", Extensions = Extensions.ReviewSummary }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/place/details/json?key={request.Key}&placeid={request.PlaceId}&language={request.Language.ToCode()}&fields=address_component%2Cadr_address%2Cformatted_address%2Cgeometry%2Cicon%2Cid%2Cname%2Cphoto%2Cplace_id%2Cplus_code%2Ctype%2Curl%2Cutc_offset%2Cvicinity%2Cbusiness_status&extensions={request.Extensions.ToString().ToLower()}", uri.PathAndQuery); }
public void GetUriWhenExtensionsTest() { var request = new PlacesDetailsRequest { Key = "abc", PlaceId = "abc", Extensions = Extensions.ReviewSummary }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/place/details/json?key={request.Key}&placeid={request.PlaceId}&language={request.Language.ToCode()}&extensions={request.Extensions.ToString().ToLower()}", uri.PathAndQuery); }
public void GetQueryStringParametersWhenKeyIsStringEmptyTest() { var request = new PlacesDetailsRequest { Key = string.Empty }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.AreEqual(exception.Message, "'Key' is required"); }
public async Task ReturnsStronglyTypedPriceLevelAsync() { var request = new PlacesDetailsRequest { ApiKey = ApiKey, PlaceId = await GetMyPlaceIdAsync() }; PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); Assert.NotNull(result.Result.PriceLevel); Assert.That(new PriceLevel[] { result.Result.PriceLevel.Value }, Is.SubsetOf(_anyPriceLevel)); }
public void GetQueryStringParametersWhenPlaceIdIsNullTest() { var request = new PlacesDetailsRequest { Key = "key", PlaceId = null }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.AreEqual(exception.Message, "'PlaceId' is required"); }
public void PlacesDetailsTest() { var request = new PlacesAutoCompleteRequest { Key = ApiKey, Input = "jagtvej 2200 København" }; var response = GooglePlaces.AutoComplete.Query(request); var placeId = response.Predictions.Select(x => x.PlaceId).FirstOrDefault(); var request2 = new PlacesDetailsRequest { Key = ApiKey, PlaceId = placeId }; var response2 = GooglePlaces.Details.Query(request2); Assert.IsNotNull(response2); Assert.AreEqual(Status.Ok, response2.Status); var result = response2.Result; Assert.IsNotNull(result); Assert.IsNotNull(result.Url); Assert.IsNotNull(result.Icon); Assert.IsNotNull(result.PlaceId); Assert.IsNotNull(result.Vicinity); Assert.IsNotNull(result.UtcOffset); Assert.IsNotNull(result.AdrAddress); Assert.IsNotNull(result.Geometry); Assert.IsNotNull(result.Geometry.Location); Assert.Contains(PlaceLocationType.Route, result.Types.ToArray()); Assert.AreEqual(BusinessStatus.Operational, result.BusinessStatus); var formattedAddress = result.FormattedAddress.ToLower(); Assert.IsNotNull(formattedAddress); Assert.IsTrue(formattedAddress.Contains("jagtvej")); Assert.IsTrue(formattedAddress.Contains("københavn")); var addressComponents = result.AddressComponents?.ToArray(); Assert.IsNotNull(addressComponents); Assert.GreaterOrEqual(addressComponents.Length, 4); }
public void ReturnsPhotos() { var request = new PlacesDetailsRequest { ApiKey = ApiKey, PlaceId = "ChIJZ3VuVMQdLz4REP9PWpQ4SIY" }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); if (result.Status == Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(Status.OK, result.Status); Assert.IsNotEmpty(result.Result.Photos); }
public void ReturnsNotFoundForWrongReferenceString() { var request = new PlacesDetailsRequest { ApiKey = base.ApiKey, // Needs to be a correct looking reference. 1 character too short or long and google will return INVALID_REQUEST instead. PlaceId = "ChIJbWWgrQAVkFQReAwrXXWzlYs" }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); if (result.Status == Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(Status.NOT_FOUND, result.Status); }
public void ReturnsNotFoundForWrongReferenceString() { var request = new PlacesDetailsRequest { ApiKey = base.ApiKey, // Needs to be a correct looking reference. 1 character too short or long and google will return INVALID_REQUEST instead. Reference = "CnRqAAAAvs_8564VF4xq2St_9P-YaCYEep2qa86WfWBcBL6q-264bgWE3vWD1zI5kIcWVOA6r9XA2vOfOKZ3uEMs_FQNQZGpTGxyaaq5aTF8XJD36ZcYMbmPuTP00jVEXBPlEmnUxUuHHbxzDd_7fZwxABkPIhIQ4IypqCmBf4WOCXSnT9jiIRoUi8iVFfW6-txsNpGCFurUqA-qHos" }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); if (result.Status == Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(Status.NOT_FOUND, result.Status); }
public void ReturnsStronglyTypedPriceLevel() { var request = new PlacesDetailsRequest { ApiKey = ApiKey, Reference = GetMyPlaceReference(), }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); if (result.Status == Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(Status.OK, result.Status); Assert.AreEqual(PriceLevel.Moderate, result.Result.PriceLevel); }
public void PlacesDetailsWhenAsyncAndCancelledTest() { var request = new PlacesDetailsRequest { Key = this.ApiKey, PlaceId = Guid.NewGuid().ToString("N") }; var cancellationTokenSource = new CancellationTokenSource(); var task = GooglePlaces.Details.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 PlacesDetailsWhenKeyIsNullTest() { var request = new PlacesDetailsRequest { Key = null, PlaceId = "test" }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Details.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 ReturnsStronglyTypedPriceLevel() { var request = new PlacesDetailsRequest { ApiKey = ApiKey, PlaceId = GetMyPlaceId(), }; PlacesDetailsResponse result = GoogleMaps.PlacesDetails.Query(request); if (result.Status == Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(Status.OK, result.Status); Assert.That(new PriceLevel[] { result.Result.PriceLevel.Value }, Is.SubsetOf(anyPriceLevel)); }
public void PlacesDetailsWhenPlaceIdIsStringEmptyTest() { var request = new PlacesDetailsRequest { Key = ApiKey, PlaceId = string.Empty }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Details.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "PlaceId is required"); }
public void PlacesDetailsWhenInvalidKeyTest() { var request = new PlacesDetailsRequest { Key = "test", PlaceId = "abc" }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Details.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 PlacesDeleteTest() { var request = new PlacesAddRequest { Key = this.ApiKey, Name = Guid.NewGuid().ToString("N"), Types = new[] { PlaceLocationType.Street_Address }, Location = new Location(55.664425, 12.502264) }; var response = GooglePlaces.Add.Query(request); Assert.IsNotNull(response); Assert.IsNotNull(response.PlaceId); var request2 = new PlacesDeleteRequest { Key = this.ApiKey, PlaceId = response.PlaceId }; var response2 = GooglePlaces.Delete.Query(request2); Assert.IsNotNull(response2); Assert.AreEqual(response2.Status, Status.Ok); var request3 = new PlacesDetailsRequest { Key = this.ApiKey, PlaceId = response.PlaceId }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Details.Query(request3)); Assert.IsNotNull(exception); Assert.AreEqual("One or more errors occurred.", exception.Message); var innerException = exception.InnerExceptions.FirstOrDefault() as GoogleApiException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(Status.NotFound, innerException.Status); Assert.AreEqual("Exception of type 'GoogleApi.Exceptions.GoogleApiException' was thrown.", innerException.Message); }
public void GetQueryStringParametersWhenRegionTest() { var request = new PlacesDetailsRequest { Key = "key", PlaceId = "placeId", Region = "region" }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var region = queryStringParameters.FirstOrDefault(x => x.Key == "region"); var regionExpected = request.Region; Assert.IsNotNull(region); Assert.AreEqual(regionExpected, region.Value); }
public void PlacesDetailsWhenPlaceIdIsNullTest() { var request = new PlacesDetailsRequest { Key = ApiKey, PlaceId = null }; var exception = Assert.Throws <AggregateException>(() => GooglePlaces.Details.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, "PlaceId is required"); }
public void GetQueryStringParametersWhenSessionTokenTest() { var request = new PlacesDetailsRequest { Key = "key", PlaceId = "placeId", SessionToken = "sessiontoken" }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var sessiontoken = queryStringParameters.FirstOrDefault(x => x.Key == "sessiontoken"); var sessiontokenExpected = request.SessionToken; Assert.IsNotNull(sessiontoken); Assert.AreEqual(sessiontokenExpected, sessiontoken.Value); }
public void PlacesAddTest() { var request = new PlacesAddRequest { Key = this.ApiKey, Name = Guid.NewGuid().ToString("N"), Types = new[] { PlaceLocationType.Street_Address }, Location = new Location(55.664425, 12.502264), Accuracy = 50, PhoneNumber = "+45 00000000", Address = Guid.NewGuid().ToString("N"), Website = "http://www.google.com", Language = Language.English }; var response = GooglePlaces.Add.Query(request); Assert.IsNotNull(response); Assert.IsNotNull(response.PlaceId); Assert.AreEqual(response.Scope, Scope.App); Assert.AreEqual(response.Status, Status.Ok); var request2 = new PlacesDetailsRequest { Key = this.ApiKey, PlaceId = response.PlaceId }; var response2 = GooglePlaces.Details.Query(request2); Assert.IsNotNull(response2); Assert.AreEqual(Status.Ok, response2.Status); Assert.AreEqual(response2.Result.Name, request.Name); Assert.AreEqual(response2.Result.Website, request.Website); Assert.AreEqual(response2.Result.FormattedAddress, request.Address); Assert.AreEqual(response2.Result.FormattedPhoneNumber, request.PhoneNumber); Assert.AreEqual(response2.Result.Geometry.Location.Latitude, request.Location.Latitude); Assert.AreEqual(response2.Result.Geometry.Location.Longitude, request.Location.Longitude); Assert.AreEqual(Scope.App, response2.Result.Scope); Assert.AreEqual(response2.Result.PlaceId, response.PlaceId); Assert.AreEqual(PlaceLocationType.Street_Address, response2.Result.Types.FirstOrDefault()); }
public DTOResponse <PlacesDetailsResponse> GetPlaceDetail(string placeId) { var basicDetailsQuery = new PlacesDetailsRequest() { Key = _generalSettings.GoogleApiKey, PlaceId = placeId, Fields = FieldTypes.Basic }; var detailsQueryResult = GoogleApi.GooglePlaces.Details.Query(basicDetailsQuery); if (!detailsQueryResult.Status.HasValue || detailsQueryResult.Status.Value != Status.Ok) { return(new DTOResponse <PlacesDetailsResponse>() { Code = 400, Message = detailsQueryResult.ErrorMessage }); } var contactDetailsQuery = new PlacesDetailsRequest() { Key = _generalSettings.GoogleApiKey, PlaceId = placeId, Fields = FieldTypes.Contact }; var contactDetailsQueryResult = GoogleApi.GooglePlaces.Details.Query(contactDetailsQuery); if (contactDetailsQueryResult.Status.HasValue && contactDetailsQueryResult.Status == Status.Ok) { detailsQueryResult.Result.FormattedPhoneNumber = contactDetailsQueryResult.Result.FormattedPhoneNumber; detailsQueryResult.Result.Website = contactDetailsQueryResult.Result.Website; } return(new DTOResponse <PlacesDetailsResponse>() { Code = 200, Data = detailsQueryResult }); }
public void PlacesDetailsAsyncTest() { var request = new PlacesAutoCompleteRequest { Key = ApiKey, Input = "jagtvej 2200" }; var response = GooglePlaces.AutoComplete.QueryAsync(request).Result; var results = response.Predictions.ToArray(); var result = results.First(); var request2 = new PlacesDetailsRequest { Key = ApiKey, PlaceId = result.PlaceId }; var response2 = GooglePlaces.Details.Query(request2); Assert.AreEqual(Status.Ok, response2.Status); }
public void PlacesDetailsWhenFieldsTest() { var request = new PlacesAutoCompleteRequest { Key = ApiKey, Input = "jagtvej 2200 København" }; var response = GooglePlaces.AutoComplete.Query(request); var request2 = new PlacesDetailsRequest { Key = ApiKey, PlaceId = response.Predictions.Select(x => x.PlaceId).FirstOrDefault(), Fields = FieldTypes.Place_Id }; var response2 = GooglePlaces.Details.Query(request2); Assert.IsNotNull(response2); Assert.AreEqual(Status.Ok, response2.Status); Assert.IsNotNull(response2.Result.PlaceId); }
public void PlacesDetailsWhenAsyncAndTimeoutTest() { var request = new PlacesDetailsRequest { Key = this.ApiKey, PlaceId = Guid.NewGuid().ToString("N") }; var exception = Assert.Throws <AggregateException>(() => { var result = GooglePlaces.Details.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."); }