- New Schaad.OpenData.Weather project: MeteoSwissClient reads the
10-minute CSV of the five SwissMetNet stations in Thurgau every 10
minutes (station list once a day) and backfills the last 7 days from
the yearly file when the cache has less than 6 days
- History kept as JSON per day (60 days); a failing station does not
stop the others
- API: /api/weather/meta, /stations (current values, 1 h/24 h rain,
24 h min/max, strongest gust), /stations/{abbr}/history
- Combined map: "Wetter (live)" layer with station badges (temperature,
24 h rain or wind), wind arrows, rain marker, station panel with
hourly 7-day chart, overview and municipality context entries
- Docs: docs/datasets/wetter.md, overview in docs/datasets.md,
CLAUDE.md; Docker and appsettings wiring
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using Microsoft.Extensions.Options;
|
|
using Schaad.OpenData.Weather;
|
|
using Schaad.OpenData.Weather.Storage;
|
|
using static Schaad.OpenData.Tests.WeatherTestData;
|
|
|
|
namespace Schaad.OpenData.Tests;
|
|
|
|
public sealed class WeatherCacheStorageTestShould : IDisposable
|
|
{
|
|
private readonly string dataPath = Path.Combine(Path.GetTempPath(), "odv-tests-" + Guid.NewGuid().ToString("N"));
|
|
private readonly WeatherCacheStorage storage;
|
|
|
|
public WeatherCacheStorageTestShould()
|
|
{
|
|
storage = new WeatherCacheStorage(Options.Create(new WeatherOptions { 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.Stations.ShouldBeEmpty();
|
|
snapshot.Readings.ShouldBeEmpty();
|
|
snapshot.StationsFetched.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RestoreStationsReadingsAndTimesWhenLoading()
|
|
{
|
|
var readings = new[] { Reading("GUT", Now.AddDays(-1)), Reading("STK", Now, temperature: null) };
|
|
var snapshot = new WeatherSnapshot([Station(), Station("STK", "Steckborn")], readings, Now, Now.AddHours(-3));
|
|
|
|
await storage.SaveAsync(snapshot, [new DateOnly(2026, 11, 17), new DateOnly(2026, 11, 18)], CancellationToken.None);
|
|
var loaded = await storage.LoadAsync(CancellationToken.None);
|
|
|
|
loaded.Stations.ShouldBe([Station(), Station("STK", "Steckborn")]);
|
|
loaded.Readings.ShouldBe(readings);
|
|
loaded.LastRefresh.ShouldBe(Now);
|
|
loaded.StationsFetched.ShouldBe(Now.AddHours(-3));
|
|
Directory.GetFiles(Path.Combine(dataPath, "weather", "thurgau", "days")).Length.ShouldBe(2);
|
|
}
|
|
}
|