MX.GeoLocation.Api.Client.Testing
1.2.1
See the version list below for details.
dotnet add package MX.GeoLocation.Api.Client.Testing --version 1.2.1
NuGet\Install-Package MX.GeoLocation.Api.Client.Testing -Version 1.2.1
<PackageReference Include="MX.GeoLocation.Api.Client.Testing" Version="1.2.1" />
<PackageVersion Include="MX.GeoLocation.Api.Client.Testing" Version="1.2.1" />
<PackageReference Include="MX.GeoLocation.Api.Client.Testing" />
paket add MX.GeoLocation.Api.Client.Testing --version 1.2.1
#r "nuget: MX.GeoLocation.Api.Client.Testing, 1.2.1"
#:package MX.GeoLocation.Api.Client.Testing@1.2.1
#addin nuget:?package=MX.GeoLocation.Api.Client.Testing&version=1.2.1
#tool nuget:?package=MX.GeoLocation.Api.Client.Testing&version=1.2.1
MX.GeoLocation.Api.Client.Testing
Test helpers for consumer applications that depend on the GeoLocation API client. Provides in-memory fakes of IGeoLocationApiClient, DTO factory methods, and DI extensions for integration tests.
Installation
dotnet add package MX.GeoLocation.Api.Client.Testing
Quick Start — Integration Tests
Replace the real client with fakes in your test DI container:
services.AddFakeGeoLocationApiClient(client =>
{
client.V1Lookup.AddResponse("8.8.8.8",
GeoLocationDtoFactory.CreateGeoLocation(
address: "8.8.8.8",
cityName: "Mountain View",
countryName: "United States"));
});
Quick Start — Unit Tests
Create and configure the fake client directly:
var fakeClient = new FakeGeoLocationApiClient();
fakeClient.V1Lookup.AddResponse("1.1.1.1",
GeoLocationDtoFactory.CreateGeoLocation(cityName: "San Francisco"));
fakeClient.V1_1Lookup.AddCityResponse("1.1.1.1",
GeoLocationDtoFactory.CreateCityGeoLocation(cityName: "San Francisco"));
var sut = new MyService(fakeClient);
var result = await sut.LookupAddress("1.1.1.1");
Assert.Equal("San Francisco", result?.CityName);
DTO Factories
GeoLocationDtoFactory provides static factory methods with sensible defaults:
GeoLocationDtoFactory.CreateGeoLocation(address: "10.0.0.1", cityName: "London");
GeoLocationDtoFactory.CreateCityGeoLocation(countryName: "UK");
GeoLocationDtoFactory.CreateInsightsGeoLocation(cityName: "Berlin");
GeoLocationDtoFactory.CreateNetworkTraits(isp: "Cloudflare");
GeoLocationDtoFactory.CreateAnonymizer(isAnonymousVpn: true);
GeoLocationDtoFactory.CreateApiInfo(version: "1.0.0");
Configuring Error Responses
fakeClient.V1Lookup.AddErrorResponse("invalid-host",
HttpStatusCode.NotFound, "NotFound", "Address not found");
fakeClient.V1Lookup.SetDefaultBehavior(DefaultLookupBehavior.ReturnError);
Tracking Calls
The fake APIs expose read-only collections to verify interactions:
Assert.Contains("8.8.8.8", fakeClient.V1Lookup.LookedUpAddresses);
Assert.Contains("old-record", fakeClient.V1Lookup.DeletedAddresses);
Assert.Contains("1.1.1.1", fakeClient.V1_1Lookup.CityLookedUpAddresses);
Resetting State Between Tests
fakeClient.Reset(); // Clears all configured responses and tracked calls
License
This project is licensed under the GPL-3.0-only license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- MX.Api.Abstractions (>= 2.3.25)
- MX.GeoLocation.Abstractions.V1 (>= 1.2.1)
- MX.GeoLocation.Api.Client.V1 (>= 1.2.1)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- MX.Api.Abstractions (>= 2.3.25)
- MX.GeoLocation.Abstractions.V1 (>= 1.2.1)
- MX.GeoLocation.Api.Client.V1 (>= 1.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.