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.Abstractions.Models;
|
||||||
using Svrnty.GeoManagement.Google;
|
using Svrnty.GeoManagement.Google;
|
||||||
using Svrnty.GeoManagement.Google.Configuration;
|
using Svrnty.GeoManagement.Google.Configuration;
|
||||||
|
using Svrnty.GeoManagement.Tests.Configuration;
|
||||||
|
|
||||||
namespace Svrnty.GeoManagement.Tests;
|
namespace Svrnty.GeoManagement.Tests;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ public class GoogleProviderTests : IDisposable
|
|||||||
private readonly GeoManagementGoogleProvider _provider;
|
private readonly GeoManagementGoogleProvider _provider;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly ILogger<GeoManagementGoogleProvider> _logger;
|
private readonly ILogger<GeoManagementGoogleProvider> _logger;
|
||||||
|
private readonly TestDataConfiguration _testData;
|
||||||
|
|
||||||
public GoogleProviderTests()
|
public GoogleProviderTests()
|
||||||
{
|
{
|
||||||
@ -38,6 +40,11 @@ public class GoogleProviderTests : IDisposable
|
|||||||
"Google API key not configured. Please add your API key to appsettings.Development.json");
|
"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(
|
_provider = new GeoManagementGoogleProvider(
|
||||||
Options.Create(options),
|
Options.Create(options),
|
||||||
_logger);
|
_logger);
|
||||||
@ -48,12 +55,12 @@ public class GoogleProviderTests : IDisposable
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var address = new Address(
|
var address = new Address(
|
||||||
Line1: "1600 Amphitheatre Parkway",
|
Line1: _testData.ValidAddress.Line1,
|
||||||
Line2: null,
|
Line2: _testData.ValidAddress.Line2,
|
||||||
City: "Mountain View",
|
City: _testData.ValidAddress.City,
|
||||||
Subdivision: "CA",
|
Subdivision: _testData.ValidAddress.Subdivision,
|
||||||
PostalCode: "94043",
|
PostalCode: _testData.ValidAddress.PostalCode,
|
||||||
Country: "US",
|
Country: _testData.ValidAddress.Country,
|
||||||
Location: null,
|
Location: null,
|
||||||
Note: null);
|
Note: null);
|
||||||
|
|
||||||
@ -62,15 +69,17 @@ public class GoogleProviderTests : IDisposable
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.InRange(result.Latitude, 37.0, 38.0); // Approximate range for Mountain View, CA
|
Assert.InRange(result.Latitude, _testData.ExpectedLatRange.Min, _testData.ExpectedLatRange.Max);
|
||||||
Assert.InRange(result.Longitude, -123.0, -122.0);
|
Assert.InRange(result.Longitude, _testData.ExpectedLongRange.Min, _testData.ExpectedLongRange.Max);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ReverseGeocodeAsync_WithValidCoordinates_ReturnsAddress()
|
public async Task ReverseGeocodeAsync_WithValidCoordinates_ReturnsAddress()
|
||||||
{
|
{
|
||||||
// Arrange - Google HQ coordinates
|
// Arrange
|
||||||
var geoPoint = new GeoPoint(37.4224764, -122.0842499);
|
var geoPoint = new GeoPoint(
|
||||||
|
_testData.ValidGeoPoint.Latitude,
|
||||||
|
_testData.ValidGeoPoint.Longitude);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await _provider.ReverseGeocodeAsync(geoPoint);
|
var result = await _provider.ReverseGeocodeAsync(geoPoint);
|
||||||
@ -89,12 +98,12 @@ public class GoogleProviderTests : IDisposable
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var address = new Address(
|
var address = new Address(
|
||||||
Line1: "1600 Amphitheatre Pkwy", // Abbreviated
|
Line1: _testData.NormalizeTestAddress.Line1,
|
||||||
Line2: null,
|
Line2: _testData.NormalizeTestAddress.Line2,
|
||||||
City: "Mountain View",
|
City: _testData.NormalizeTestAddress.City,
|
||||||
Subdivision: "California",
|
Subdivision: _testData.NormalizeTestAddress.Subdivision,
|
||||||
PostalCode: "94043",
|
PostalCode: _testData.NormalizeTestAddress.PostalCode,
|
||||||
Country: "USA",
|
Country: _testData.NormalizeTestAddress.Country,
|
||||||
Location: null,
|
Location: null,
|
||||||
Note: null);
|
Note: null);
|
||||||
|
|
||||||
@ -113,7 +122,7 @@ public class GoogleProviderTests : IDisposable
|
|||||||
public async Task NormalizeAddressAsync_WithAddressString_ReturnsNormalizedAddress()
|
public async Task NormalizeAddressAsync_WithAddressString_ReturnsNormalizedAddress()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var addressString = "1600 Amphitheatre Parkway, Mountain View, CA";
|
var addressString = _testData.AddressString;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await _provider.NormalizeAddressAsync(addressString);
|
var result = await _provider.NormalizeAddressAsync(addressString);
|
||||||
@ -131,12 +140,12 @@ public class GoogleProviderTests : IDisposable
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var address = new Address(
|
var address = new Address(
|
||||||
Line1: "This is not a real address at all",
|
Line1: _testData.InvalidAddress.Line1,
|
||||||
Line2: null,
|
Line2: _testData.InvalidAddress.Line2,
|
||||||
City: "Fake City",
|
City: _testData.InvalidAddress.City,
|
||||||
Subdivision: "XX",
|
Subdivision: _testData.InvalidAddress.Subdivision,
|
||||||
PostalCode: "00000",
|
PostalCode: _testData.InvalidAddress.PostalCode,
|
||||||
Country: "Nowhere",
|
Country: _testData.InvalidAddress.Country,
|
||||||
Location: null,
|
Location: null,
|
||||||
Note: null);
|
Note: null);
|
||||||
|
|
||||||
@ -151,8 +160,10 @@ public class GoogleProviderTests : IDisposable
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task ReverseGeocodeAsync_WithOceanCoordinates_ReturnsAddress()
|
public async Task ReverseGeocodeAsync_WithOceanCoordinates_ReturnsAddress()
|
||||||
{
|
{
|
||||||
// Arrange - Coordinates in the middle of the Pacific Ocean
|
// Arrange
|
||||||
var geoPoint = new GeoPoint(0, -160);
|
var geoPoint = new GeoPoint(
|
||||||
|
_testData.OceanGeoPoint.Latitude,
|
||||||
|
_testData.OceanGeoPoint.Longitude);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await _provider.ReverseGeocodeAsync(geoPoint);
|
var result = await _provider.ReverseGeocodeAsync(geoPoint);
|
||||||
|
|||||||
@ -3,5 +3,48 @@
|
|||||||
"ApiKey": "YOUR_GOOGLE_API_KEY_HERE",
|
"ApiKey": "YOUR_GOOGLE_API_KEY_HERE",
|
||||||
"Language": "en",
|
"Language": "en",
|
||||||
"Region": "ca"
|
"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