ASP.NET Core 10 API and React client that visualize the canton of Thurgau's hourly traffic counts by vehicle class (data.tg.ch, CC0). - Background refresh from data.tg.ch every 6 h into a per-day JSON cache, so history grows beyond the source's two-week window - Road geometry per station direction from swisstopo swissTLM3D, oriented by geocoding the direction's target town; roundabout arms follow the road outward only - Leaflet map with canvas animation: dots drive along the road in both directions, density by hourly count, colour by vehicle class, right-hand traffic; play/pause, time slider and day selection - Station panel with per-class counts and Chart.js charts (hourly, weekday/weekend profile, daily totals, class mix) - swisstopo base map switcher (grey, colour, aerial) - Dockerfile and docker-compose with a data volume - xUnit tests for mapping, cache, geometry, geocoding and analysis Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
using NSubstitute;
|
|
using Schaad.OpenData.Traffic.Geometry;
|
|
using Schaad.OpenData.Traffic.Models;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public class StationGeometryServiceTestShould
|
|
{
|
|
private readonly SwisstopoClient swisstopoClient = Substitute.For<SwisstopoClient>(new HttpClient());
|
|
private readonly StationGeometryService service;
|
|
|
|
public StationGeometryServiceTestShould()
|
|
{
|
|
service = new StationGeometryService(swisstopoClient);
|
|
swisstopoClient.GetRoadSegmentsAsync(default, default, default).ReturnsForAnyArgs([]);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task LookUpEachPartWhenPlaceNameContainsSlash()
|
|
{
|
|
swisstopoClient.FindPlaceAsync("Wilen", Arg.Any<GeoPoint>(), Arg.Any<CancellationToken>()).Returns((GeoPoint?)null);
|
|
swisstopoClient.FindPlaceAsync("Busswil", Arg.Any<GeoPoint>(), Arg.Any<CancellationToken>()).Returns(TestData.Meters(0, 2000));
|
|
|
|
var geometry = await service.BuildAsync(TestData.Station(413, "Wilen/Busswil", "Gloten"), CancellationToken.None);
|
|
|
|
await swisstopoClient.DidNotReceive().FindPlaceAsync("Wilen/Busswil", Arg.Any<GeoPoint>(), Arg.Any<CancellationToken>());
|
|
geometry.Directions[0].Path[^1].Lat.ShouldBeGreaterThan(TestData.Origin.Lat);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UseStraightPathWhenNoRoadIsFound()
|
|
{
|
|
swisstopoClient.FindPlaceAsync(default!, default, default).ReturnsForAnyArgs(TestData.Meters(1000, 0));
|
|
|
|
var geometry = await service.BuildAsync(TestData.Station(1, "nach A", "von A"), CancellationToken.None);
|
|
|
|
geometry.FollowsRoad.ShouldBeFalse();
|
|
geometry.Directions.Count.ShouldBe(2);
|
|
}
|
|
}
|