Choropleth of the 80 Thurgau municipalities from the road vehicle stock dataset (djs-stv-17): vehicles per 1000 inhabitants by vehicle group or share of a car brand among passenger cars, with year controls and a municipality panel. Population comes from sk-stat-56, outlines from swisstopo swissBOUNDARIES3D. Also fixes the broken ENV line in the Dockerfile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
using System.Net;
|
|
using System.Text;
|
|
using Microsoft.Extensions.Options;
|
|
using Schaad.OpenData.Vehicles;
|
|
using Schaad.OpenData.Vehicles.Source;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public class MunicipalityBoundaryClientTestShould
|
|
{
|
|
private sealed class StubHandler(HttpStatusCode status, string body) : HttpMessageHandler
|
|
{
|
|
public List<Uri> Requests { get; } = [];
|
|
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
Requests.Add(request.RequestUri!);
|
|
return Task.FromResult(new HttpResponseMessage(status) { Content = new StringContent(body, Encoding.UTF8, "application/json") });
|
|
}
|
|
}
|
|
|
|
private static MunicipalityBoundaryClient Client(StubHandler handler) =>
|
|
new(new HttpClient(handler), Options.Create(new VehicleOptions { BoundaryUrl = "https://geo.example/boundaries" }));
|
|
|
|
[Fact]
|
|
public async Task ReturnRoundedPolygonsWhenFeatureIsMultiPolygon()
|
|
{
|
|
var body = """
|
|
{"feature":{"type":"Feature","id":"4566","geometry":{"type":"MultiPolygon","coordinates":[
|
|
[[[8.887602,47.528387],[8.88636,47.527927],[8.886348,47.527906],[8.887602,47.528387]]],
|
|
[[[8.9,47.5],[8.91,47.5],[8.91,47.51],[8.9,47.5]]]
|
|
]}}}
|
|
""";
|
|
var handler = new StubHandler(HttpStatusCode.OK, body);
|
|
|
|
var outline = await Client(handler).FetchAsync("4566", CancellationToken.None);
|
|
|
|
handler.Requests.ShouldHaveSingleItem().AbsoluteUri.ShouldBe("https://geo.example/boundaries/4566?geometryFormat=geojson&sr=4326");
|
|
outline.ShouldNotBeNull();
|
|
outline.Id.ShouldBe("4566");
|
|
outline.Polygons.Length.ShouldBe(2);
|
|
outline.Polygons[0][0][0].ShouldBe([8.8876, 47.52839]);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ReturnSinglePolygonWhenFeatureIsPolygon()
|
|
{
|
|
var body = """{"feature":{"geometry":{"type":"Polygon","coordinates":[[[8.9,47.5],[8.91,47.5],[8.91,47.51],[8.9,47.5]]]}}}""";
|
|
|
|
var outline = await Client(new StubHandler(HttpStatusCode.OK, body)).FetchAsync("4401", CancellationToken.None);
|
|
|
|
outline.ShouldNotBeNull().Polygons.ShouldHaveSingleItem().ShouldHaveSingleItem().Length.ShouldBe(4);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ReturnNullWhenMunicipalityIsUnknown()
|
|
{
|
|
var outline = await Client(new StubHandler(HttpStatusCode.NotFound, "{}")).FetchAsync("1", CancellationToken.None);
|
|
|
|
outline.ShouldBeNull();
|
|
}
|
|
}
|