added more configurations for test with custom addresses data
This commit is contained in:
parent
70d52fbe36
commit
a7d2d8d872
@ -0,0 +1,35 @@
|
||||
namespace Svrnty.GeoManagement.Tests.Configuration;
|
||||
|
||||
public class TestDataConfiguration
|
||||
{
|
||||
public AddressTestData ValidAddress { get; set; } = new();
|
||||
public GeoPointTestData ValidGeoPoint { get; set; } = new();
|
||||
public AddressTestData InvalidAddress { get; set; } = new();
|
||||
public GeoPointTestData OceanGeoPoint { get; set; } = new();
|
||||
public CoordinateRange ExpectedLatRange { get; set; } = new();
|
||||
public CoordinateRange ExpectedLongRange { get; set; } = new();
|
||||
public string AddressString { get; set; } = string.Empty;
|
||||
public AddressTestData NormalizeTestAddress { get; set; } = new();
|
||||
}
|
||||
|
||||
public class AddressTestData
|
||||
{
|
||||
public string Line1 { get; set; } = string.Empty;
|
||||
public string? Line2 { get; set; }
|
||||
public string City { get; set; } = string.Empty;
|
||||
public string Subdivision { get; set; } = string.Empty;
|
||||
public string PostalCode { get; set; } = string.Empty;
|
||||
public string Country { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class GeoPointTestData
|
||||
{
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
}
|
||||
|
||||
public class CoordinateRange
|
||||
{
|
||||
public double Min { get; set; }
|
||||
public double Max { get; set; }
|
||||
}
|
@ -4,6 +4,7 @@ using Microsoft.Extensions.Options;
|
||||
using Svrnty.GeoManagement.Abstractions.Models;
|
||||
using Svrnty.GeoManagement.Google;
|
||||
using Svrnty.GeoManagement.Google.Configuration;
|
||||
using Svrnty.GeoManagement.Tests.Configuration;
|
||||
|
||||
namespace Svrnty.GeoManagement.Tests;
|
||||
|
||||
@ -12,6 +13,7 @@ public class GoogleProviderTests : IDisposable
|
||||
private readonly GeoManagementGoogleProvider _provider;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<GeoManagementGoogleProvider> _logger;
|
||||
private readonly TestDataConfiguration _testData;
|
||||
|
||||
public GoogleProviderTests()
|
||||
{
|
||||
@ -38,6 +40,11 @@ public class GoogleProviderTests : IDisposable
|
||||
"Google API key not configured. Please add your API key to appsettings.Development.json");
|
||||
}
|
||||
|
||||
// Load test data from configuration
|
||||
_testData = _configuration.GetSection("TestData").Get<TestDataConfiguration>()
|
||||
?? throw new InvalidOperationException(
|
||||
"Test data not configured. Please add TestData section to appsettings.Development.json");
|
||||
|
||||
_provider = new GeoManagementGoogleProvider(
|
||||
Options.Create(options),
|
||||
_logger);
|
||||
@ -48,12 +55,12 @@ public class GoogleProviderTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
var address = new Address(
|
||||
Line1: "1600 Amphitheatre Parkway",
|
||||
Line2: null,
|
||||
City: "Mountain View",
|
||||
Subdivision: "CA",
|
||||
PostalCode: "94043",
|
||||
Country: "US",
|
||||
Line1: _testData.ValidAddress.Line1,
|
||||
Line2: _testData.ValidAddress.Line2,
|
||||
City: _testData.ValidAddress.City,
|
||||
Subdivision: _testData.ValidAddress.Subdivision,
|
||||
PostalCode: _testData.ValidAddress.PostalCode,
|
||||
Country: _testData.ValidAddress.Country,
|
||||
Location: null,
|
||||
Note: null);
|
||||
|
||||
@ -62,15 +69,17 @@ public class GoogleProviderTests : IDisposable
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.InRange(result.Latitude, 37.0, 38.0); // Approximate range for Mountain View, CA
|
||||
Assert.InRange(result.Longitude, -123.0, -122.0);
|
||||
Assert.InRange(result.Latitude, _testData.ExpectedLatRange.Min, _testData.ExpectedLatRange.Max);
|
||||
Assert.InRange(result.Longitude, _testData.ExpectedLongRange.Min, _testData.ExpectedLongRange.Max);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReverseGeocodeAsync_WithValidCoordinates_ReturnsAddress()
|
||||
{
|
||||
// Arrange - Google HQ coordinates
|
||||
var geoPoint = new GeoPoint(37.4224764, -122.0842499);
|
||||
// Arrange
|
||||
var geoPoint = new GeoPoint(
|
||||
_testData.ValidGeoPoint.Latitude,
|
||||
_testData.ValidGeoPoint.Longitude);
|
||||
|
||||
// Act
|
||||
var result = await _provider.ReverseGeocodeAsync(geoPoint);
|
||||
@ -89,12 +98,12 @@ public class GoogleProviderTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
var address = new Address(
|
||||
Line1: "1600 Amphitheatre Pkwy", // Abbreviated
|
||||
Line2: null,
|
||||
City: "Mountain View",
|
||||
Subdivision: "California",
|
||||
PostalCode: "94043",
|
||||
Country: "USA",
|
||||
Line1: _testData.NormalizeTestAddress.Line1,
|
||||
Line2: _testData.NormalizeTestAddress.Line2,
|
||||
City: _testData.NormalizeTestAddress.City,
|
||||
Subdivision: _testData.NormalizeTestAddress.Subdivision,
|
||||
PostalCode: _testData.NormalizeTestAddress.PostalCode,
|
||||
Country: _testData.NormalizeTestAddress.Country,
|
||||
Location: null,
|
||||
Note: null);
|
||||
|
||||
@ -113,7 +122,7 @@ public class GoogleProviderTests : IDisposable
|
||||
public async Task NormalizeAddressAsync_WithAddressString_ReturnsNormalizedAddress()
|
||||
{
|
||||
// Arrange
|
||||
var addressString = "1600 Amphitheatre Parkway, Mountain View, CA";
|
||||
var addressString = _testData.AddressString;
|
||||
|
||||
// Act
|
||||
var result = await _provider.NormalizeAddressAsync(addressString);
|
||||
@ -131,12 +140,12 @@ public class GoogleProviderTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
var address = new Address(
|
||||
Line1: "This is not a real address at all",
|
||||
Line2: null,
|
||||
City: "Fake City",
|
||||
Subdivision: "XX",
|
||||
PostalCode: "00000",
|
||||
Country: "Nowhere",
|
||||
Line1: _testData.InvalidAddress.Line1,
|
||||
Line2: _testData.InvalidAddress.Line2,
|
||||
City: _testData.InvalidAddress.City,
|
||||
Subdivision: _testData.InvalidAddress.Subdivision,
|
||||
PostalCode: _testData.InvalidAddress.PostalCode,
|
||||
Country: _testData.InvalidAddress.Country,
|
||||
Location: null,
|
||||
Note: null);
|
||||
|
||||
@ -151,8 +160,10 @@ public class GoogleProviderTests : IDisposable
|
||||
[Fact]
|
||||
public async Task ReverseGeocodeAsync_WithOceanCoordinates_ReturnsAddress()
|
||||
{
|
||||
// Arrange - Coordinates in the middle of the Pacific Ocean
|
||||
var geoPoint = new GeoPoint(0, -160);
|
||||
// Arrange
|
||||
var geoPoint = new GeoPoint(
|
||||
_testData.OceanGeoPoint.Latitude,
|
||||
_testData.OceanGeoPoint.Longitude);
|
||||
|
||||
// Act
|
||||
var result = await _provider.ReverseGeocodeAsync(geoPoint);
|
||||
|
@ -3,5 +3,48 @@
|
||||
"ApiKey": "YOUR_GOOGLE_API_KEY_HERE",
|
||||
"Language": "en",
|
||||
"Region": "ca"
|
||||
},
|
||||
"TestData": {
|
||||
"ValidAddress": {
|
||||
"Line1": "1600 Amphitheatre Parkway",
|
||||
"Line2": null,
|
||||
"City": "Mountain View",
|
||||
"Subdivision": "CA",
|
||||
"PostalCode": "94043",
|
||||
"Country": "US"
|
||||
},
|
||||
"ValidGeoPoint": {
|
||||
"Latitude": 37.4224764,
|
||||
"Longitude": -122.0842499
|
||||
},
|
||||
"InvalidAddress": {
|
||||
"Line1": "This is not a real address at all",
|
||||
"Line2": null,
|
||||
"City": "Fake City",
|
||||
"Subdivision": "XX",
|
||||
"PostalCode": "00000",
|
||||
"Country": "Nowhere"
|
||||
},
|
||||
"OceanGeoPoint": {
|
||||
"Latitude": 0,
|
||||
"Longitude": -160
|
||||
},
|
||||
"ExpectedLatRange": {
|
||||
"Min": 37.0,
|
||||
"Max": 38.0
|
||||
},
|
||||
"ExpectedLongRange": {
|
||||
"Min": -123.0,
|
||||
"Max": -122.0
|
||||
},
|
||||
"AddressString": "1600 Amphitheatre Parkway, Mountain View, CA",
|
||||
"NormalizeTestAddress": {
|
||||
"Line1": "1600 Amphitheatre Pkwy",
|
||||
"Line2": null,
|
||||
"City": "Mountain View",
|
||||
"Subdivision": "California",
|
||||
"PostalCode": "94043",
|
||||
"Country": "USA"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user