OpenDataVisualizer/Schaad.OpenData.Tests/ThurgauTrafficMapperTestShould.cs
Claudio Schaad 7b65926aa2 Add Thurgau traffic visualizer and start page (#1)
- Thurgau hourly traffic counts (data.tg.ch) refreshed every 6 h into a per-day JSON cache
- Road geometry per station direction from swisstopo swissTLM3D; roundabout arms run outward from the roundabout centre
- Leaflet map with animated vehicles by class, time controls and base map switcher (grey, colour, aerial)
- Station panel with per-class counts and Chart.js charts
- Start page with map tiles; traffic map at /verkehr/thurgau
- Dockerfile and docker-compose, xUnit tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
2026-11-06 20:17:26 +00:00

62 lines
1.9 KiB
C#

using Schaad.OpenData.Traffic.Source;
namespace Schaad.OpenData.Tests;
public class ThurgauTrafficMapperTestShould
{
[Fact]
public void CreateOneStationWithAllDirectionsWhenRecordsShareTheStationCode()
{
var import = ThurgauTrafficMapper.Map([
TestData.Record(direction: "nach Diessenhofen"),
TestData.Record(direction: "nach Wagenhausen"),
TestData.Record(direction: "nach Diessenhofen", hour: 14),
]);
import.Stations.Count.ShouldBe(1);
import.Stations[0].Directions.ShouldBe(["nach Diessenhofen", "nach Wagenhausen"]);
import.Counts.Count.ShouldBe(3);
}
[Fact]
public void MapVehicleClassesWhenRecordIsValid()
{
var count = ThurgauTrafficMapper.Map([TestData.Record()]).Counts.Single();
count.Date.ShouldBe(new DateOnly(2026, 10, 27));
count.Hour.ShouldBe(13);
count.Counts.Car.ShouldBe(220);
count.Counts.Truck.ShouldBe(6);
count.Counts.Total.ShouldBe(1 + 12 + 220 + 6 + 5);
}
[Fact]
public void TreatMissingClassCountsAsZeroWhenMapping()
{
var count = ThurgauTrafficMapper.Map([TestData.Record(cars: null)]).Counts.Single();
count.Counts.Car.ShouldBe(0);
}
[Fact]
public void SkipRecordWhenDateIsInvalid()
{
ThurgauTrafficMapper.Map([TestData.Record(date: "unknown")]).Counts.ShouldBeEmpty();
}
[Fact]
public void CollapseWhitespaceWhenMappingStationName()
{
var station = ThurgauTrafficMapper.Map([TestData.Record()]).Stations.Single();
station.Name.ShouldBe("WAGENHAUSEN Wagenhausen - Diessenhofen");
}
[Fact]
public void AcceptTimestampWhenDateContainsTime()
{
var count = ThurgauTrafficMapper.Map([TestData.Record(date: "2026-10-27T00:00:00+00:00")]).Counts.Single();
count.Date.ShouldBe(new DateOnly(2026, 10, 27));
}
}