diff --git a/.gitignore b/.gitignore index 19540fc..374f802 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ packages \.vs/ GoogleMapsApi/project\.lock\.json + +**/appsettings.json diff --git a/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj b/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj index 0b2916b..5dcfa70 100644 --- a/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj +++ b/GoogleMapsApi.Test/GoogleMapsApi.Test.csproj @@ -1,15 +1,20 @@  - net6.0; + net8.0;net6.0 latest Library + false + enable + enable - - - + + + + + @@ -18,7 +23,7 @@ - Always + PreserveNewest diff --git a/GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs b/GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs index d67bcc0..c78224c 100644 --- a/GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs @@ -21,8 +21,8 @@ public async Task Directions_SumOfStepDistancesCorrect() var result = await GoogleMaps.Directions.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage); - Assert.Greater(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), 100); + Assert.That(result.Status, Is.EqualTo(DirectionsStatusCodes.OK), result.ErrorMessage); + Assert.That(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), Is.GreaterThan(100)); } [Test] @@ -37,9 +37,8 @@ public async Task Directions_ErrorMessage() var result = await GoogleMaps.Directions.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DirectionsStatusCodes.REQUEST_DENIED, result.Status); - Assert.IsNotNull (result.ErrorMessage); - Assert.IsNotEmpty (result.ErrorMessage); + Assert.That(result.Status, Is.EqualTo(DirectionsStatusCodes.REQUEST_DENIED)); + Assert.That(result.ErrorMessage, Is.Not.Null.And.Not.Empty); } [Test] @@ -49,11 +48,12 @@ public async Task Directions_WithWayPoints() var result = await GoogleMaps.Directions.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage); - Assert.AreEqual(156097, result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), 10 * 1000); + 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)); - StringAssert.Contains("Philadelphia", result.Routes.First().Legs.First().EndAddress); + Assert.That(result.Routes.First().Legs.First().EndAddress, Does.Contain("Philadelphia")); } + [Test] public async Task Directions_ExceedingRouteLength() { @@ -79,7 +79,7 @@ public async Task Directions_ExceedingRouteLength() var result = await GoogleMaps.Directions.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DirectionsStatusCodes.MAX_ROUTE_LENGTH_EXCEEDED, result.Status, result.ErrorMessage); + Assert.That(DirectionsStatusCodes.MAX_ROUTE_LENGTH_EXCEEDED, Is.EqualTo(result.Status), result.ErrorMessage); } [Test] @@ -99,9 +99,9 @@ public async Task Directions_Correct_OverviewPath() OverviewPolyline overviewPath = result.Routes.First().OverviewPath; OverviewPolyline polyline = result.Routes.First().Legs.First().Steps.First().PolyLine; - Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage); - Assert.AreEqual(122, overviewPath.Points.Count(), 30); - Assert.Greater(polyline.Points.Count(), 1); + Assert.That(DirectionsStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage); + Assert.That(122, Is.EqualTo(overviewPath.Points.Count()).Within(30)); + Assert.That(polyline.Points.Count(), Is.GreaterThan(1)); } [Test] @@ -112,8 +112,8 @@ public void DirectionsAsync_SumOfStepDistancesCorrect() var result = GoogleMaps.Directions.QueryAsync(request).Result; AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage); - Assert.Greater(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), 100); + Assert.That(DirectionsStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage); + Assert.That(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), Is.GreaterThan(100)); } //The sub_steps differes between google docs documentation and implementation. We use it as google implemented, so we have test to make sure it's not broken. @@ -136,7 +136,7 @@ public async Task Directions_VerifysubSteps() var leg = route.Legs.First(); var step = leg.Steps.First(); - Assert.NotNull(step); + Assert.That(step, Is.Not.Null); } [Test] @@ -156,14 +156,14 @@ public async Task Directions_VerifyBounds() var route = result.Routes.First(); - Assert.NotNull(route); - Assert.NotNull(route.Bounds); - Assert.Greater(route.Bounds.NorthEast.Latitude, 50); - Assert.Greater(route.Bounds.NorthEast.Longitude, 3); - Assert.Greater(route.Bounds.SouthWest.Latitude, 50); - Assert.Greater(route.Bounds.SouthWest.Longitude, 3); - Assert.Greater(route.Bounds.Center.Latitude, 50); - Assert.Greater(route.Bounds.Center.Longitude, 3); + Assert.That(route, Is.Not.Null); + Assert.That(route.Bounds, Is.Not.Null); + Assert.That(route.Bounds.NorthEast.Latitude, Is.GreaterThan(50)); + Assert.That(route.Bounds.NorthEast.Longitude, Is.GreaterThan(3)); + Assert.That(route.Bounds.SouthWest.Latitude, Is.GreaterThan(50)); + Assert.That(route.Bounds.SouthWest.Longitude, Is.GreaterThan(3)); + Assert.That(route.Bounds.Center.Latitude, Is.GreaterThan(50)); + Assert.That(route.Bounds.Center.Longitude, Is.GreaterThan(3)); } [Test] @@ -192,11 +192,11 @@ public async Task Directions_WithIcons() var leg = route.Legs.First(); var steps = leg.Steps; - Assert.IsNotEmpty(steps.Where(s => + Assert.That(steps.Where(s => s.TransitDetails? .Lines? .Vehicle? - .Icon != null)); + .Icon != null), Is.Not.Empty); } [Test] @@ -219,8 +219,8 @@ public async Task Directions_WithRegionSearch() DirectionsResponse result = await GoogleMaps.Directions.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.IsNotEmpty(result.Routes); - Assert.True(result.Status.Equals(DirectionsStatusCodes.OK)); + Assert.That(result.Routes, Is.Not.Empty); + Assert.That(result.Status.Equals(DirectionsStatusCodes.OK), Is.True); } [Test] @@ -238,10 +238,10 @@ public async Task Directions_CanGetDurationWithTraffic() AssertInconclusive.NotExceedQuota(result); //All legs have duration - Assert.IsTrue(result.Routes.First().Legs.All(l => l.DurationInTraffic != null)); + Assert.That(result.Routes.First().Legs.All(l => l.DurationInTraffic != null), Is.True); //Duration with traffic is usually longer but is not guaranteed - Assert.AreNotEqual(result.Routes.First().Legs.Sum(s => s.Duration.Value.TotalSeconds), result.Routes.First().Legs.Sum(s => s.DurationInTraffic.Value.TotalSeconds)); + Assert.That(result.Routes.First().Legs.Sum(s => s.Duration.Value.TotalSeconds), Is.Not.EqualTo(result.Routes.First().Legs.Sum(s => s.DurationInTraffic.Value.TotalSeconds))); } [Test] diff --git a/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs b/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs index 77b788c..7ed3a76 100644 --- a/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/DistanceMatrixTests.cs @@ -27,16 +27,12 @@ public async Task ShouldReturnValidValueWhenOneOriginAndOneDestinationsSpeciefed var result = await GoogleMaps.DistanceMatrix.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); - CollectionAssert.AreEqual( - new [] {"Alter Sirksfelder Weg 10, 23881 Koberg, Germany"}, - result.DestinationAddresses); - CollectionAssert.AreEqual( - new[] { "St2154 18, 92726 Waidhaus, Germany" }, - result.OriginAddresses); - Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.First().Elements.First().Status); - Assert.IsNotNull(result.Rows.First().Elements.First().Distance); - Assert.IsNotNull(result.Rows.First().Elements.First().Duration); + Assert.That(result.Status, Is.EqualTo(DistanceMatrixStatusCodes.OK), result.ErrorMessage); + 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" })); + Assert.That(result.Rows.First().Elements.First().Status, Is.EqualTo(DistanceMatrixElementStatusCodes.OK)); + Assert.That(result.Rows.First().Elements.First().Distance, Is.Not.Null); + Assert.That(result.Rows.First().Elements.First().Duration, Is.Not.Null); } [Test] @@ -52,16 +48,12 @@ public async Task ShouldReturnValidValueWhenTwoOriginsSpecified() var result = await GoogleMaps.DistanceMatrix.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); - CollectionAssert.AreEqual( - new[] { "Alter Sirksfelder Weg 10, 23881 Koberg, Germany" }, - result.DestinationAddresses); - CollectionAssert.AreEqual( - new[] { "St2154 18, 92726 Waidhaus, Germany", "Böhmerwaldstraße 19, 93444 Bad Kötzting, Germany" }, - result.OriginAddresses); - Assert.AreEqual(2, result.Rows.Count()); - Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.First().Elements.First().Status); - Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.Last().Elements.First().Status); + Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage); + 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)); } [Test] @@ -78,9 +70,8 @@ public async Task ShouldReturnDurationInTrafficWhenDepartureTimeAndApiKeySpecifi var result = await GoogleMaps.DistanceMatrix.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); - - Assert.IsNotNull(result.Rows.First().Elements.First().DurationInTraffic); + Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage); + Assert.That(result.Rows.First().Elements.First().DurationInTraffic, Is.Not.Null); } [Test] @@ -189,7 +180,7 @@ public async Task ShouldReturnImperialUnitsIfImperialPassedAsParameter() var result = await GoogleMaps.DistanceMatrix.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.True(result.Rows.First().Elements.First().Distance.Text.Contains("mi")); + Assert.That(result.Rows.First().Elements.First().Distance.Text.Contains("mi"), Is.True); } [Test] @@ -216,8 +207,8 @@ static Uri onUriCreated(Uri uri) var result = await GoogleMaps.DistanceMatrix.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); - Assert.AreEqual("1,2", result.OriginAddresses.First()); + Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage); + Assert.That("1,2", Is.EqualTo(result.OriginAddresses.First())); } finally { @@ -246,8 +237,8 @@ public async Task ShouldPassRawDataToOnRawResponseRecivied() var result = await GoogleMaps.DistanceMatrix.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); - CollectionAssert.IsNotEmpty(rawData); + Assert.That(DistanceMatrixStatusCodes.OK, Is.EqualTo(result.Status), result.ErrorMessage); + Assert.That(rawData, Is.Not.Empty); } finally { diff --git a/GoogleMapsApi.Test/IntegrationTests/ElevationTests.cs b/GoogleMapsApi.Test/IntegrationTests/ElevationTests.cs index ef9553c..3482eb2 100644 --- a/GoogleMapsApi.Test/IntegrationTests/ElevationTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/ElevationTests.cs @@ -22,8 +22,8 @@ public async Task Elevation_ReturnsCorrectElevation() var result = await GoogleMaps.Elevation.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Entities.Elevation.Response.Status.OK, result.Status); - Assert.AreEqual(16.92, result.Results.First().Elevation, 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)); } [Test] @@ -38,8 +38,8 @@ public void ElevationAsync_ReturnsCorrectElevation() var result = GoogleMaps.Elevation.QueryAsync(request).Result; AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Entities.Elevation.Response.Status.OK, result.Status); - Assert.AreEqual(16.92, result.Results.First().Elevation, 1.0); + Assert.That(Entities.Elevation.Response.Status.OK, Is.EqualTo(result.Status)); + Assert.That(16.92, Is.EqualTo(result.Results.First().Elevation).Within(1.0)); } } } diff --git a/GoogleMapsApi.Test/IntegrationTests/GeocodingTests.cs b/GoogleMapsApi.Test/IntegrationTests/GeocodingTests.cs index 723f43d..61e8982 100644 --- a/GoogleMapsApi.Test/IntegrationTests/GeocodingTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/GeocodingTests.cs @@ -26,9 +26,8 @@ public async Task Geocoding_ReturnsCorrectLocation() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - // 40.{*}, -73.{*} - StringAssert.IsMatch("40\\.\\d*,-73\\.\\d*", result.Results.First().Geometry.Location.LocationString); + Assert.That(result.Status, Is.EqualTo(Status.OK)); + Assert.That(result.Results.First().Geometry.Location.LocationString, Does.Match("40\\.\\d*,-73\\.\\d*")); } [Test] @@ -43,9 +42,9 @@ public void GeocodingAsync_ReturnsCorrectLocation() var result = GoogleMaps.Geocode.QueryAsync(request).Result; AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); // 40.{*}, -73.{*} - StringAssert.IsMatch("40\\.\\d*,-73\\.\\d*", result.Results.First().Geometry.Location.LocationString); + Assert.That(result.Results.First().Geometry.Location.LocationString, Does.Match("40\\.\\d*,-73\\.\\d*")); } [Test] @@ -103,8 +102,8 @@ public async Task ReverseGeocoding_LatLng_ReturnsCorrectAddress() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } [Test] @@ -119,8 +118,8 @@ public async Task ReverseGeocoding_PlaceId_ReturnsCorrectAddress() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } [Test] @@ -136,8 +135,8 @@ public async Task ReverseGeocoding_PlaceIdAndRegion_ReturnsCorrectAddress() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } [Test] @@ -157,8 +156,8 @@ public async Task ReverseGeocoding_PlaceIdAndBounds_ReturnsCorrectAddress() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } [Test] @@ -174,8 +173,8 @@ public async Task ReverseGeocoding_PlaceIdAndComponents_ReturnsCorrectAddress() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } [Test] @@ -191,8 +190,8 @@ public async Task ReverseGeocoding_PlaceIdAndAddress_ReturnsCorrectAddress() var result = await GoogleMaps.Geocode.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } [Test] @@ -207,8 +206,8 @@ public void ReverseGeocodingAsync_ReturnsCorrectAddress() var result = GoogleMaps.Geocode.QueryAsync(request).Result; AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - StringAssert.Contains("Bedford Ave, Brooklyn, NY 11211, USA", result.Results.First().FormattedAddress); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.First().FormattedAddress, Does.Contain("Bedford Ave, Brooklyn, NY 11211, USA")); } } } \ No newline at end of file diff --git a/GoogleMapsApi.Test/IntegrationTests/PlaceAutocompleteTests.cs b/GoogleMapsApi.Test/IntegrationTests/PlaceAutocompleteTests.cs index d91803f..ed7d572 100644 --- a/GoogleMapsApi.Test/IntegrationTests/PlaceAutocompleteTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/PlaceAutocompleteTests.cs @@ -25,7 +25,7 @@ public async Task ReturnsNoResults() PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.ZERO_RESULTS, result.Status); + Assert.That(result.Status, Is.EqualTo(Status.ZERO_RESULTS)); } [Test] @@ -42,7 +42,7 @@ public async Task OffsetTest() PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.ZERO_RESULTS, result.Status, "results for jibberish"); + Assert.That(Status.ZERO_RESULTS, Is.EqualTo(result.Status), "results for jibberish"); var offsetRequest = new PlaceAutocompleteRequest { @@ -55,7 +55,7 @@ public async Task OffsetTest() PlaceAutocompleteResponse offsetResult = await GoogleMaps.PlaceAutocomplete.QueryAsync(offsetRequest); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, offsetResult.Status, "results using offset"); + Assert.That(Status.OK, Is.EqualTo(offsetResult.Status), "results using offset"); } [Test] @@ -73,12 +73,12 @@ public async Task TypeTest() PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); foreach (var oneResult in result.Results) { - Assert.IsNotNull(oneResult.Types, "result with no type classification"); - Assert.IsTrue(new List(oneResult.Types).Contains("geocode"), "non-geocode result"); + Assert.That(oneResult.Types, Is.Not.Null, "result with no type classification"); + Assert.That(new List(oneResult.Types).Contains("geocode"), "non-geocode result"); } } @@ -98,7 +98,7 @@ public async Task CheckForExpectedRoad( string aSearch, string anExpected) PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreNotEqual(Status.ZERO_RESULTS, result.Status); + Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status)); Assert.That(result.Results.Any(t => t.Description.ToUpper().Contains(anExpected))); } @@ -109,7 +109,7 @@ public async Task CheckZeroRadius() var request = CreatePlaceAutocompleteRequest("RIX", 0); PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreNotEqual(Status.ZERO_RESULTS, result.Status); + Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status)); } [Test(Description = "Ensures that it is ok to sent negative value as a radius")] public async Task CheckNegativeRadius() @@ -117,7 +117,7 @@ public async Task CheckNegativeRadius() var request = CreatePlaceAutocompleteRequest("RIX", -1); PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreNotEqual(Status.ZERO_RESULTS, result.Status); + Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status)); } [Test(Description = "Ensures that it is ok to sent huge value as a radius")] @@ -126,7 +126,7 @@ public async Task CheckLargerThenEarthRadius() var request = CreatePlaceAutocompleteRequest("RIX", 30000000); PlaceAutocompleteResponse result = await GoogleMaps.PlaceAutocomplete.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreNotEqual(Status.ZERO_RESULTS, result.Status); + Assert.That(Status.ZERO_RESULTS, Is.Not.EqualTo(result.Status)); } private PlaceAutocompleteRequest CreatePlaceAutocompleteRequest(string query, double? radius) diff --git a/GoogleMapsApi.Test/IntegrationTests/PlacesDetailsTests.cs b/GoogleMapsApi.Test/IntegrationTests/PlacesDetailsTests.cs index 304ae9b..995e0d9 100644 --- a/GoogleMapsApi.Test/IntegrationTests/PlacesDetailsTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/PlacesDetailsTests.cs @@ -23,8 +23,8 @@ public async Task ReturnsPhotos() PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.IsNotEmpty(result.Result.Photos); + Assert.That(result.Status, Is.EqualTo(Status.OK)); + Assert.That(result.Result.Photos, Is.Not.Empty); } [Test] @@ -40,7 +40,7 @@ public async Task ReturnsNotFoundForWrongReferenceString() PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.NOT_FOUND, result.Status); + Assert.That(Status.NOT_FOUND, Is.EqualTo(result.Status)); } readonly PriceLevel[] anyPriceLevel = new PriceLevel[] { PriceLevel.Free, PriceLevel.Inexpensive, PriceLevel.Moderate, PriceLevel.Expensive, PriceLevel.VeryExpensive }; @@ -57,7 +57,7 @@ public async Task ReturnsStronglyTypedPriceLevel() PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); Assert.That(new PriceLevel[] { result.Result.PriceLevel.Value }, Is.SubsetOf(anyPriceLevel)); } @@ -73,7 +73,7 @@ public async Task ReturnsOpeningTimes() PlacesDetailsResponse result = await GoogleMaps.PlacesDetails.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); // commented out because seems like google doesn't have opening hours for this place anymore /* diff --git a/GoogleMapsApi.Test/IntegrationTests/PlacesFindTests.cs b/GoogleMapsApi.Test/IntegrationTests/PlacesFindTests.cs index 555e208..e38ec57 100644 --- a/GoogleMapsApi.Test/IntegrationTests/PlacesFindTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/PlacesFindTests.cs @@ -26,8 +26,8 @@ public async Task ReturnsResults() PlacesFindResponse result = await GoogleMaps.PlacesFind.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.IsNotEmpty(result.Candidates); + Assert.That(result.Status, Is.EqualTo(Status.OK)); + Assert.That(result.Candidates, Is.Not.Empty); } [Test] @@ -44,8 +44,8 @@ public async Task DoesNotReturnFieldsWhenNotRequested() PlacesFindResponse result = await GoogleMaps.PlacesFind.QueryAsync(request); //FormattedAddress should be null since it wasn't requested - Assert.IsNotEmpty(result.Candidates); - Assert.IsNull(result.Candidates.FirstOrDefault()?.FormattedAddress); + Assert.That(result.Candidates, Is.Not.Empty); + Assert.That(result.Candidates.FirstOrDefault()?.FormattedAddress, Is.Null); } } } diff --git a/GoogleMapsApi.Test/IntegrationTests/PlacesNearByTests.cs b/GoogleMapsApi.Test/IntegrationTests/PlacesNearByTests.cs index 5e92a2c..a8f778d 100644 --- a/GoogleMapsApi.Test/IntegrationTests/PlacesNearByTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/PlacesNearByTests.cs @@ -27,8 +27,8 @@ public async Task ReturnsNearbySearchRequest() PlacesNearByResponse result = await GoogleMaps.PlacesNearBy.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.IsTrue(result.Results.Count() > 5); + Assert.That(result.Status, Is.EqualTo(Status.OK)); + Assert.That(result.Results.Count(), Is.GreaterThan(5)); } [Test] @@ -46,9 +46,9 @@ public async Task TestNearbySearchType() PlacesNearByResponse result = await GoogleMaps.PlacesNearBy.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.IsTrue(result.Results.Any()); - Assert.IsTrue(result.Results.Any(t => t.Name.Contains("John F. Kennedy"))); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.Any(), Is.True); + Assert.That(result.Results.Any(t => t.Name.Contains("John F. Kennedy")), Is.True); } [Test] @@ -65,11 +65,11 @@ public async Task TestNearbySearchPagination() PlacesNearByResponse result = await GoogleMaps.PlacesNearBy.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); //we should have more than one page of pizza results from the NearBy Search - Assert.IsTrue(!String.IsNullOrEmpty(result.NextPage)); + Assert.That(!String.IsNullOrEmpty(result.NextPage), Is.True); //a full page of results is always 20 - Assert.IsTrue(result.Results.Count() == 20); + Assert.That(result.Results.Count(), Is.EqualTo(20)); var resultFromFirstPage = result.Results.FirstOrDefault(); //hold onto this //get the second page of results. Delay request by 2 seconds @@ -85,11 +85,11 @@ public async Task TestNearbySearchPagination() PageToken = result.NextPage }; result = await GoogleMaps.PlacesNearBy.QueryAsync(request); - Assert.AreEqual(GoogleMapsApi.Entities.PlacesNearBy.Response.Status.OK, result.Status); + Assert.That(GoogleMapsApi.Entities.PlacesNearBy.Response.Status.OK, Is.EqualTo(result.Status)); //make sure the second page has some results - Assert.IsTrue(result.Results != null && result.Results.Any()); + 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.IsFalse(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId)); + Assert.That(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId), Is.False); } } } diff --git a/GoogleMapsApi.Test/IntegrationTests/PlacesSearchTests.cs b/GoogleMapsApi.Test/IntegrationTests/PlacesSearchTests.cs index 18127af..51d123e 100644 --- a/GoogleMapsApi.Test/IntegrationTests/PlacesSearchTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/PlacesSearchTests.cs @@ -27,8 +27,8 @@ public async Task ReturnsNearbySearchRequest() PlacesResponse result = await GoogleMaps.Places.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.IsTrue(result.Results.Count() > 5); + Assert.That(result.Status, Is.EqualTo(Status.OK)); + Assert.That(result.Results.Count(), Is.GreaterThan(5)); } [Test] @@ -46,9 +46,9 @@ public async Task TestNearbySearchType() PlacesResponse result = await GoogleMaps.Places.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.IsTrue(result.Results.Any()); - Assert.IsTrue(result.Results.Any(t => t.Name.Contains("John F. Kennedy"))); + Assert.That(Status.OK, Is.EqualTo(result.Status)); + Assert.That(result.Results.Any(), Is.True); + Assert.That(result.Results.Any(t => t.Name.Contains("John F. Kennedy")), Is.True); } [Test] @@ -65,11 +65,11 @@ public async Task TestNearbySearchPagination() PlacesResponse result = await GoogleMaps.Places.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); //we should have more than one page of pizza results from the NearBy Search - Assert.IsTrue(!String.IsNullOrEmpty(result.NextPage)); + Assert.That(!String.IsNullOrEmpty(result.NextPage), Is.True); //a full page of results is always 20 - Assert.IsTrue(result.Results.Count() == 20); + Assert.That(result.Results.Count(), Is.EqualTo(20)); var resultFromFirstPage = result.Results.FirstOrDefault(); //hold onto this //get the second page of results. Delay request by 2 seconds @@ -87,11 +87,11 @@ public async Task TestNearbySearchPagination() result = await GoogleMaps.Places.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(Status.OK, Is.EqualTo(result.Status)); //make sure the second page has some results - Assert.IsTrue(result.Results != null && result.Results.Any()); + 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.IsFalse(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId)); + Assert.That(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId), Is.False); } } } diff --git a/GoogleMapsApi.Test/IntegrationTests/PlacesTextTests.cs b/GoogleMapsApi.Test/IntegrationTests/PlacesTextTests.cs index df634a3..65c0876 100644 --- a/GoogleMapsApi.Test/IntegrationTests/PlacesTextTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/PlacesTextTests.cs @@ -23,8 +23,8 @@ public async Task ReturnsFormattedAddress() PlacesTextResponse result = await GoogleMaps.PlacesText.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); - Assert.AreEqual("1 Smith St, Parramatta NSW 2150, Australia", result.Results.First().FormattedAddress); + Assert.That(result.Status, Is.EqualTo(Status.OK)); + Assert.That(result.Results.First().FormattedAddress, Is.EqualTo("1 Smith St, Parramatta NSW 2150, Australia")); } [Test] @@ -40,7 +40,7 @@ public async Task ReturnsPhotos() PlacesTextResponse result = await GoogleMaps.PlacesText.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(result.Status, Is.EqualTo(Status.OK)); Assert.That(result.Results, Is.Not.Null.And.Not.Empty); } } diff --git a/GoogleMapsApi.Test/IntegrationTests/TimeZoneTests.cs b/GoogleMapsApi.Test/IntegrationTests/TimeZoneTests.cs index 2a5af52..a2cf855 100644 --- a/GoogleMapsApi.Test/IntegrationTests/TimeZoneTests.cs +++ b/GoogleMapsApi.Test/IntegrationTests/TimeZoneTests.cs @@ -24,7 +24,7 @@ public async Task TimeZone_Correct_OverviewPath() TimeZoneResponse result = await GoogleMaps.TimeZone.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); - Assert.AreEqual(Status.OK, result.Status); + Assert.That(result.Status, Is.EqualTo(Status.OK)); } } } \ No newline at end of file diff --git a/GoogleMapsApi.Test/LocationToStringTest.cs b/GoogleMapsApi.Test/LocationToStringTest.cs index 55f1955..0ed0cc8 100644 --- a/GoogleMapsApi.Test/LocationToStringTest.cs +++ b/GoogleMapsApi.Test/LocationToStringTest.cs @@ -11,7 +11,7 @@ public void WhenNearZeroLongitude_ExpectCorrectToString() { // Longitude of 0.000009 is converted to 9E-06 using Invariant ToString, but we need 0.000009 var location = new Location(57.231d, 0.000009d); - Assert.AreEqual("57.231,0.000009", location.ToString()); + Assert.That("57.231,0.000009", Is.EqualTo(location.ToString())); } [Test] @@ -19,7 +19,7 @@ public void WhenZeroLongitude_ExpectCorrectToString() { // Longitude of 0.000009 is converted to 9E-06 using Invariant ToString, but we need 0.000009 var location = new Location(52.123123d, 0.0d); - Assert.AreEqual("52.123123,0.0", location.ToString()); + Assert.That("52.123123,0.0", Is.EqualTo(location.ToString())); } } } diff --git a/GoogleMapsApi.Test/StaticMaps.cs b/GoogleMapsApi.Test/StaticMaps.cs index 745fa31..79fc5e3 100644 --- a/GoogleMapsApi.Test/StaticMaps.cs +++ b/GoogleMapsApi.Test/StaticMaps.cs @@ -48,7 +48,8 @@ public void BasicTest() string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request); - Assert.AreEqual(expectedResult, generateStaticMapURL); + // Updated Assertion + Assert.That(generateStaticMapURL, Is.EqualTo(expectedResult)); } [Test] @@ -60,7 +61,8 @@ public void AddressTest() string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request); - Assert.AreEqual(expectedResult, generateStaticMapURL); + // Updated Assertion + Assert.That(generateStaticMapURL, Is.EqualTo(expectedResult)); } [Test] @@ -72,7 +74,8 @@ public void ZoomLevels() string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request); - Assert.AreEqual(expectedResult, generateStaticMapURL); + // Updated Assertion + Assert.That(generateStaticMapURL, Is.EqualTo(expectedResult)); } [Test] @@ -84,7 +87,8 @@ public void ImageSize() string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request); - Assert.AreEqual(expectedResult, generateStaticMapURL); + // Updated Assertion + Assert.That(generateStaticMapURL, Is.EqualTo(expectedResult)); } @@ -101,7 +105,8 @@ public void MapTypes() string actualResult = new StaticMapsEngine().GenerateStaticMapURL(request); - Assert.AreEqual(expectedResult, actualResult); + // Updated Assertion + Assert.That(actualResult, Is.EqualTo(expectedResult)); } } } diff --git a/GoogleMapsApi.Test/UnixTimeConverterTest.cs b/GoogleMapsApi.Test/UnixTimeConverterTest.cs index 5b572a4..6295afd 100644 --- a/GoogleMapsApi.Test/UnixTimeConverterTest.cs +++ b/GoogleMapsApi.Test/UnixTimeConverterTest.cs @@ -12,8 +12,10 @@ public void DateTimeToUnixTimestamp_Zero_ExpectedResult() { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); const int expected = 0; - Assert.AreEqual(UnixTimeConverter.DateTimeToUnixTimestamp(epoch), expected); - Assert.AreEqual(UnixTimeConverter.DateTimeToUnixTimestamp(epoch.ToLocalTime()), expected); + + // Updated Assertions + Assert.That(UnixTimeConverter.DateTimeToUnixTimestamp(epoch), Is.EqualTo(expected)); + Assert.That(UnixTimeConverter.DateTimeToUnixTimestamp(epoch.ToLocalTime()), Is.EqualTo(expected)); } [Test] @@ -21,8 +23,10 @@ public void DateTimeToUnixTimestamp_DST_ExpectedResult() { var dst = new DateTime(2016, 4, 4, 10, 0, 0, DateTimeKind.Utc); const int expected = 1459764000; - Assert.AreEqual(UnixTimeConverter.DateTimeToUnixTimestamp(dst), expected); - Assert.AreEqual(UnixTimeConverter.DateTimeToUnixTimestamp(dst.ToLocalTime()), expected); + + // Updated Assertions + Assert.That(UnixTimeConverter.DateTimeToUnixTimestamp(dst), Is.EqualTo(expected)); + Assert.That(UnixTimeConverter.DateTimeToUnixTimestamp(dst.ToLocalTime()), Is.EqualTo(expected)); } [Test] @@ -30,8 +34,10 @@ public void DateTimeToUnixTimestamp_NonDST_ExpectedResult() { var nonDst = new DateTime(2016, 3, 1, 11, 0, 0, DateTimeKind.Utc); const int expected = 1456830000; - Assert.AreEqual(UnixTimeConverter.DateTimeToUnixTimestamp(nonDst), expected); - Assert.AreEqual(UnixTimeConverter.DateTimeToUnixTimestamp(nonDst.ToLocalTime()), expected); + + // Updated Assertions + Assert.That(UnixTimeConverter.DateTimeToUnixTimestamp(nonDst), Is.EqualTo(expected)); + Assert.That(UnixTimeConverter.DateTimeToUnixTimestamp(nonDst.ToLocalTime()), Is.EqualTo(expected)); } } } \ No newline at end of file diff --git a/GoogleMapsApi.Test/appsettings.json b/GoogleMapsApi.Test/appsettings.json deleted file mode 100644 index f63fa64..0000000 --- a/GoogleMapsApi.Test/appsettings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "GOOGLE_API_KEY": "AIzaSyARhCefx-8m0rifawtrrX9_FJlYIddJdGE" -} \ No newline at end of file diff --git a/GoogleMapsApi.Test/appsettings.template.json b/GoogleMapsApi.Test/appsettings.template.json new file mode 100644 index 0000000..45d6b61 --- /dev/null +++ b/GoogleMapsApi.Test/appsettings.template.json @@ -0,0 +1,3 @@ +{ + "GOOGLE_API_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +} \ No newline at end of file