Skip to content

Commit

Permalink
Fix tests warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
maximn committed Oct 9, 2024
1 parent eae8b3a commit 080bd3c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 45 deletions.
5 changes: 3 additions & 2 deletions GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;

namespace GoogleMapsApi.Test.IntegrationTests
{
{
// Note: The integration tests run against the real Google API web
// servers and count towards your query limit. Also, the tests
// require a working internet connection in order to pass.
Expand All @@ -11,6 +11,7 @@ namespace GoogleMapsApi.Test.IntegrationTests

public class BaseTestIntegration
{
const string ApiKeyEnvironmentVariable = "GOOGLE_API_KEY";
private readonly IConfigurationRoot Configuration;

public BaseTestIntegration()
Expand All @@ -22,6 +23,6 @@ public BaseTestIntegration()
.Build();
}

protected string ApiKey => Configuration.GetValue<string>("GOOGLE_API_KEY");
protected string ApiKey => Configuration.GetValue<string>(ApiKeyEnvironmentVariable) ?? throw new InvalidOperationException($"API key is not configured. Please set the {ApiKeyEnvironmentVariable} environment variable.");
}
}
12 changes: 6 additions & 6 deletions GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public async Task Directions_WithWayPoints()
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(DirectionsStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(156097, Is.EqualTo(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value)).Within(10 * 1000));
Assert.That(result.Status, Is.EqualTo(DirectionsStatusCodes.OK), result.ErrorMessage);
Assert.That(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), Is.EqualTo(156097).Within(10 * 1000));

Assert.That(result.Routes.First().Legs.First().EndAddress, Does.Contain("Philadelphia"));
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public async Task Directions_ExceedingRouteLength()
var result = await GoogleMaps.Directions.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(DirectionsStatusCodes.MAX_ROUTE_LENGTH_EXCEEDED, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(result.Status, Is.EqualTo(DirectionsStatusCodes.MAX_ROUTE_LENGTH_EXCEEDED), result.ErrorMessage);
}

[Test]
Expand All @@ -99,8 +99,8 @@ public async Task Directions_Correct_OverviewPath()
OverviewPolyline overviewPath = result.Routes.First().OverviewPath;
OverviewPolyline polyline = result.Routes.First().Legs.First().Steps.First().PolyLine;

Assert.That(DirectionsStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(122, Is.EqualTo(overviewPath.Points.Count()).Within(30));
Assert.That(result.Status, Is.EqualTo(DirectionsStatusCodes.OK), result.ErrorMessage);
Assert.That(overviewPath.Points.Count(), Is.EqualTo(122).Within(30));
Assert.That(polyline.Points.Count(), Is.GreaterThan(1));
}

Expand All @@ -112,7 +112,7 @@ public void DirectionsAsync_SumOfStepDistancesCorrect()
var result = GoogleMaps.Directions.QueryAsync(request).Result;

AssertInconclusive.NotExceedQuota(result);
Assert.That(DirectionsStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(result.Status, Is.EqualTo(DirectionsStatusCodes.OK));
Assert.That(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), Is.GreaterThan(100));
}

Expand Down
16 changes: 8 additions & 8 deletions GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public async Task ShouldReturnValidValueWhenTwoOriginsSpecified()
var result = await GoogleMaps.DistanceMatrix.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(result.Status, Is.EqualTo(DistanceMatrixStatusCodes.OK));
Assert.That(result.DestinationAddresses, Is.EqualTo(new[] { "Alter Sirksfelder Weg 10, 23881 Koberg, Germany" }));
Assert.That(result.OriginAddresses, Is.EqualTo(new[] { "St2154 18, 92726 Waidhaus, Germany", "Böhmerwaldstraße 19, 93444 Bad Kötzting, Germany" }));
Assert.That(2, Is.EqualTo(result.Rows.Count()));
Assert.That(DistanceMatrixElementStatusCodes.OK, Is.EqualTo(result.Rows.First().Elements.First().Status));
Assert.That(DistanceMatrixElementStatusCodes.OK, Is.EqualTo(result.Rows.Last().Elements.First().Status));
Assert.That(result.Rows.Count(), Is.EqualTo(2));
Assert.That(result.Rows.First().Elements.First().Status, Is.EqualTo(DistanceMatrixElementStatusCodes.OK));
Assert.That(result.Rows.Last().Elements.First().Status, Is.EqualTo(DistanceMatrixElementStatusCodes.OK));
}

[Test]
Expand All @@ -70,7 +70,7 @@ public async Task ShouldReturnDurationInTrafficWhenDepartureTimeAndApiKeySpecifi
var result = await GoogleMaps.DistanceMatrix.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(result.Status, Is.EqualTo(DistanceMatrixStatusCodes.OK));
Assert.That(result.Rows.First().Elements.First().DurationInTraffic, Is.Not.Null);
}

Expand Down Expand Up @@ -207,8 +207,8 @@ static Uri onUriCreated(Uri uri)
var result = await GoogleMaps.DistanceMatrix.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That("1,2", Is.EqualTo(result.OriginAddresses.First()));
Assert.That(result.Status, Is.EqualTo(DistanceMatrixStatusCodes.OK), result.ErrorMessage);
Assert.That(result.OriginAddresses.First(), Is.EqualTo("1,2"));
}
finally
{
Expand Down Expand Up @@ -237,7 +237,7 @@ public async Task ShouldPassRawDataToOnRawResponseRecivied()
var result = await GoogleMaps.DistanceMatrix.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage);
Assert.That(result.Status, Is.EqualTo(DistanceMatrixStatusCodes.OK), result.ErrorMessage);
Assert.That(rawData, Is.Not.Empty);
}
finally
Expand Down
4 changes: 2 additions & 2 deletions GoogleMapsApi.Test/IntegrationTests/ElevationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void ElevationAsync_ReturnsCorrectElevation()
var result = GoogleMaps.Elevation.QueryAsync(request).Result;

AssertInconclusive.NotExceedQuota(result);
Assert.That(Entities.Elevation.Response.Status.OK, Is.EqualTo(result.Status));
Assert.That(16.92, Is.EqualTo(result.Results.First().Elevation).Within(1.0));
Assert.That(result.Status, Is.EqualTo(Entities.Elevation.Response.Status.OK));
Assert.That(result.Results.First().Elevation, Is.EqualTo(16.92).Within(1.0));
}
}
}
16 changes: 8 additions & 8 deletions GoogleMapsApi.Test/IntegrationTests/GeocodingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void GeocodingAsync_ReturnsCorrectLocation()
var result = GoogleMaps.Geocode.QueryAsync(request).Result;

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
// 40.{*}, -73.{*}
Assert.That(result.Results.First().Geometry.Location.LocationString, Does.Match("40\\.\\d*,-73\\.\\d*"));
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public async Task ReverseGeocoding_LatLng_ReturnsCorrectAddress()
var result = await GoogleMaps.Geocode.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}

Expand All @@ -118,7 +118,7 @@ public async Task ReverseGeocoding_PlaceId_ReturnsCorrectAddress()
var result = await GoogleMaps.Geocode.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}

Expand All @@ -135,7 +135,7 @@ public async Task ReverseGeocoding_PlaceIdAndRegion_ReturnsCorrectAddress()
var result = await GoogleMaps.Geocode.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}

Expand All @@ -156,7 +156,7 @@ public async Task ReverseGeocoding_PlaceIdAndBounds_ReturnsCorrectAddress()
var result = await GoogleMaps.Geocode.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}

Expand All @@ -173,7 +173,7 @@ public async Task ReverseGeocoding_PlaceIdAndComponents_ReturnsCorrectAddress()
var result = await GoogleMaps.Geocode.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}

Expand All @@ -190,7 +190,7 @@ public async Task ReverseGeocoding_PlaceIdAndAddress_ReturnsCorrectAddress()
var result = await GoogleMaps.Geocode.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}

Expand All @@ -206,7 +206,7 @@ public void ReverseGeocodingAsync_ReturnsCorrectAddress()
var result = GoogleMaps.Geocode.QueryAsync(request).Result;

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA"));
}
}
Expand Down
14 changes: 7 additions & 7 deletions GoogleMapsApi.Test/IntegrationTests/PlaceAutocompleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task OffsetTest()
PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.ZERO_RESULTS, Is.EqualTo(result.Status), "results for jibberish");
Assert.That(result.Status, Is.EqualTo(Status.ZERO_RESULTS), "results for jibberish");

var offsetRequest = new PlaceAutocompleteRequest
{
Expand All @@ -55,7 +55,7 @@ public async Task OffsetTest()
PlaceAutocompleteResponse offsetResult = await GoogleMaps.PlaceAutocomplete.QueryAsync(offsetRequest);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(offsetResult.Status), "results using offset");
Assert.That(offsetResult.Status, Is.EqualTo(Status.OK), "results using offset");
}

[Test]
Expand All @@ -73,7 +73,7 @@ public async Task TypeTest()
PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));

foreach (var oneResult in result.Results)
{
Expand All @@ -98,7 +98,7 @@ public async Task CheckForExpectedRoad( string aSearch, string anExpected)
PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status));
Assert.That(result.Status, Is.Not.EqualTo(Status.ZERO_RESULTS));

Assert.That(result.Results.Any(t => t.Description.ToUpper().Contains(anExpected)));
}
Expand All @@ -109,15 +109,15 @@ public async Task CheckZeroRadius()
var request = CreatePlaceAutocompleteRequest("RIX", 0);
PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request);
AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status));
Assert.That(result.Status, Is.Not.EqualTo(Status.ZERO_RESULTS));
}
[Test(Description = "Ensures that it is ok to sent negative value as a radius")]
public async Task CheckNegativeRadius()
{
var request = CreatePlaceAutocompleteRequest("RIX", -1);
PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request);
AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status));
Assert.That(result.Status, Is.Not.EqualTo(Status.ZERO_RESULTS));
}

[Test(Description = "Ensures that it is ok to sent huge value as a radius")]
Expand All @@ -126,7 +126,7 @@ public async Task CheckLargerThenEarthRadius()
var request = CreatePlaceAutocompleteRequest("RIX", 30000000);
PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request);
AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status));
Assert.That(result.Status, Is.Not.EqualTo(Status.ZERO_RESULTS));
}

private PlaceAutocompleteRequest CreatePlaceAutocompleteRequest(string query, double? radius)
Expand Down
9 changes: 5 additions & 4 deletions GoogleMapsApi.Test/IntegrationTests/PlacesDetailsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task ReturnsNotFoundForWrongReferenceString()
PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.NOT_FOUND, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.NOT_FOUND));
}

readonly PriceLevel[] anyPriceLevel = new PriceLevel[] { PriceLevel.Free, PriceLevel.Inexpensive, PriceLevel.Moderate, PriceLevel.Expensive, PriceLevel.VeryExpensive };
Expand All @@ -57,7 +57,8 @@ public async Task ReturnsStronglyTypedPriceLevel()
PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Result.PriceLevel, Is.Not.Null);
Assert.That(new PriceLevel[] { result.Result.PriceLevel.Value }, Is.SubsetOf(anyPriceLevel));
}

Expand All @@ -73,7 +74,7 @@ public async Task ReturnsOpeningTimes()
PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));

// commented out because seems like google doesn't have opening hours for this place anymore
/*
Expand All @@ -87,7 +88,7 @@ public async Task ReturnsOpeningTimes()
*/
}

private string cachedMyPlaceId;
private string? cachedMyPlaceId;
private async Task<string> GetMyPlaceId()
{
if (cachedMyPlaceId == null)
Expand Down
8 changes: 5 additions & 3 deletions GoogleMapsApi.Test/IntegrationTests/PlacesNearByTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task TestNearbySearchType()
PlacesNearByResponse result = await GoogleMaps.PlacesNearBy.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.Any(), Is.True);
Assert.That(result.Results.Any(t => t.Name.Contains("John F. Kennedy")), Is.True);
}
Expand All @@ -65,7 +65,7 @@ public async Task TestNearbySearchPagination()
PlacesNearByResponse result = await GoogleMaps.PlacesNearBy.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
//we should have more than one page of pizza results from the NearBy Search
Assert.That(!String.IsNullOrEmpty(result.NextPage), Is.True);
//a full page of results is always 20
Expand All @@ -85,10 +85,12 @@ public async Task TestNearbySearchPagination()
PageToken = result.NextPage
};
result = await GoogleMaps.PlacesNearBy.QueryAsync(request);
Assert.That(GoogleMapsApi.Entities.PlacesNearBy.Response.Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
//make sure the second page has some results
Assert.That(result.Results != null && result.Results.Any(), Is.True);
//make sure the result from the first page isn't on the second page to confirm we actually got a second page with new results
Assert.That(result.Results, Is.Not.Null);
Assert.That(resultFromFirstPage, Is.Not.Null);
Assert.That(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId), Is.False);
}
}
Expand Down
8 changes: 5 additions & 3 deletions GoogleMapsApi.Test/IntegrationTests/PlacesSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task TestNearbySearchType()
PlacesResponse result = await GoogleMaps.Places.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
Assert.That(result.Results.Any(), Is.True);
Assert.That(result.Results.Any(t => t.Name.Contains("John F. Kennedy")), Is.True);
}
Expand All @@ -65,7 +65,7 @@ public async Task TestNearbySearchPagination()
PlacesResponse result = await GoogleMaps.Places.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
//we should have more than one page of pizza results from the NearBy Search
Assert.That(!String.IsNullOrEmpty(result.NextPage), Is.True);
//a full page of results is always 20
Expand All @@ -87,10 +87,12 @@ public async Task TestNearbySearchPagination()
result = await GoogleMaps.Places.QueryAsync(request);

AssertInconclusive.NotExceedQuota(result);
Assert.That(Status.OK, Is.EqualTo(result.Status));
Assert.That(result.Status, Is.EqualTo(Status.OK));
//make sure the second page has some results
Assert.That(result.Results != null && result.Results.Any(), Is.True);
//make sure the result from the first page isn't on the second page to confirm we actually got a second page with new results
Assert.That(result.Results, Is.Not.Null);
Assert.That(resultFromFirstPage, Is.Not.Null);
Assert.That(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId), Is.False);
}
}
Expand Down
Loading

0 comments on commit 080bd3c

Please sign in to comment.