dotnet-geo-management/Svrnty.GeoManagement.Tests
2025-10-06 14:51:58 -04:00
..
Configuration added more configurations for test with custom addresses data 2025-10-06 14:51:58 -04:00
appsettings.Example.json added more configurations for test with custom addresses data 2025-10-06 14:51:58 -04:00
GoogleProviderTests.cs added more configurations for test with custom addresses data 2025-10-06 14:51:58 -04:00
README.md added functional tests 2025-10-06 14:46:21 -04:00
Svrnty.GeoManagement.Tests.csproj added functional tests 2025-10-06 14:46:21 -04:00

Svrnty.GeoManagement.Tests

Integration tests for the Svrnty.GeoManagement library.

Setup

The tests require a Google Maps API key to run the integration tests.

Step 1: Get a Google Maps API Key

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Geocoding API
  4. Create credentials (API Key)
  5. (Optional) Restrict the API key to only allow Geocoding API calls

Step 2: Configure the API Key

  1. Copy appsettings.Example.json to appsettings.Development.json:

    cp appsettings.Example.json appsettings.Development.json
    
  2. Edit appsettings.Development.json and replace YOUR_GOOGLE_API_KEY_HERE with your actual API key:

    {
      "GoogleGeoManagement": {
        "ApiKey": "AIza...", // Your actual API key
        "Language": "en",
        "Region": "us"
      }
    }
    
  3. Important: appsettings.Development.json is in .gitignore and will not be committed to version control.

Alternative: Using Environment Variables

You can also set the API key via environment variables:

export GoogleGeoManagement__ApiKey="your-api-key-here"

Note: Use double underscores (__) to represent nested configuration sections.

Running Tests

dotnet test

The integration tests will make actual calls to the Google Geocoding API. Be aware of:

  • API Rate Limits: Google has rate limits on API calls
  • API Costs: While Google provides free tier usage, be aware of potential costs
  • Network Dependency: Tests require an internet connection

Test Coverage

The test suite includes:

  • Forward geocoding (address to coordinates)
  • Reverse geocoding (coordinates to address)
  • Address normalization (both object and string)
  • Edge cases (invalid addresses, ocean coordinates)

All tests use real Google API calls to ensure the integration works correctly.