New Schaad.OpenData.Watercraft library that discovers the yearly "immatrikulierte Wasserfahrzeuge" datasets (2021–2025) on data.tg.ch, caches them and aggregates boats per harbour location by type, propulsion, fuel, emission group and use, with length/power bins. API under /api/watercraft, new page /schifffahrt/thurgau with donut markers per location, year playback, toggleable categories and a location/canton panel. Swisstopo base layers moved to map/baseLayers.ts for both maps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using Microsoft.Extensions.Options;
|
|
using Schaad.OpenData.Watercraft;
|
|
using Schaad.OpenData.Watercraft.Storage;
|
|
using static Schaad.OpenData.Tests.WatercraftTestData;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public sealed class WatercraftCacheStorageTestShould : IDisposable
|
|
{
|
|
private readonly string dataPath = Path.Combine(Path.GetTempPath(), "odv-tests-" + Guid.NewGuid().ToString("N"));
|
|
private readonly WatercraftCacheStorage storage;
|
|
|
|
public WatercraftCacheStorageTestShould()
|
|
{
|
|
storage = new WatercraftCacheStorage(Options.Create(new WatercraftOptions { DataPath = dataPath }));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Directory.Exists(dataPath))
|
|
{
|
|
Directory.Delete(dataPath, true);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ReturnEmptySnapshotWhenCacheDoesNotExist()
|
|
{
|
|
var snapshot = await storage.LoadAsync(CancellationToken.None);
|
|
|
|
snapshot.Years.ShouldBeEmpty();
|
|
snapshot.LastRefresh.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RestoreSavedYearsWhenLoading()
|
|
{
|
|
var refreshedAt = new DateTimeOffset(2026, 11, 6, 12, 0, 0, TimeSpan.Zero);
|
|
var snapshot = new WatercraftSnapshot([Year(2023, Vessel("Güttingen", fuel: "Elektrizität"))], refreshedAt);
|
|
|
|
await storage.SaveAsync(snapshot, [2023], CancellationToken.None);
|
|
var loaded = await storage.LoadAsync(CancellationToken.None);
|
|
|
|
var year = loaded.Years.ShouldHaveSingleItem();
|
|
year.Year.ShouldBe(2023);
|
|
year.DatasetId.ShouldBe("djs-kpo-2023");
|
|
year.ReferenceDate.ShouldBe(new DateOnly(2023, 12, 31));
|
|
year.Vessels.ShouldHaveSingleItem().ShouldBe(Vessel("Güttingen", fuel: "Elektrizität"));
|
|
loaded.LastRefresh.ShouldBe(refreshedAt);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task WriteOnlyChangedYearsWhenSaving()
|
|
{
|
|
var snapshot = new WatercraftSnapshot([Year(2022, Vessel()), Year(2023, Vessel())], null);
|
|
|
|
await storage.SaveAsync(snapshot, [2023], CancellationToken.None);
|
|
|
|
var yearsPath = Path.Combine(dataPath, "watercraft", "thurgau", "years");
|
|
File.Exists(Path.Combine(yearsPath, "2023.json")).ShouldBeTrue();
|
|
File.Exists(Path.Combine(yearsPath, "2022.json")).ShouldBeFalse();
|
|
}
|
|
}
|