Wetterdienst
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using LehrerApp.Core.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace LehrerApp.Api.Tests;
|
||||
|
||||
public sealed class SchoolWeatherStoreTests
|
||||
{
|
||||
[Fact]
|
||||
public void SaveLocation_TrenntNutzerUndErsetztVorhandenenStandort()
|
||||
{
|
||||
using var temp = new TempStore();
|
||||
temp.Store.SaveLocation("eins", Location("Köln", 50.9, 6.9));
|
||||
temp.Store.SaveLocation("zwei", Location("Berlin", 52.5, 13.4));
|
||||
temp.Store.SaveLocation("eins", Location("Bonn", 50.7, 7.1));
|
||||
|
||||
Assert.Equal("Bonn", temp.Store.GetLocation("eins")!.City);
|
||||
Assert.Equal("Berlin", temp.Store.GetLocation("zwei")!.City);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveLocation_AenderungEntferntWettercacheDesAltenOrts()
|
||||
{
|
||||
using var temp = new TempStore();
|
||||
temp.Store.SaveLocation("eins", Location("Köln", 50.9, 6.9));
|
||||
temp.Store.SaveWeather("eins", new WeatherSnapshot { StationId = "alt", RetrievedAt = DateTime.UtcNow });
|
||||
|
||||
temp.Store.SaveLocation("eins", Location("Bonn", 50.7, 7.1));
|
||||
|
||||
Assert.Null(temp.Store.GetWeather("eins"));
|
||||
}
|
||||
|
||||
private static SchoolLocationProfile Location(string city, double lat, double lon) => new()
|
||||
{
|
||||
SchoolName = "Testschule", Street = "Schulweg 1", PostalCode = "12345", City = city,
|
||||
Latitude = lat, Longitude = lon, ResolvedAddress = city, UpdatedAt = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
private sealed class TempStore : IDisposable
|
||||
{
|
||||
private readonly string _path = Path.Combine(Path.GetTempPath(), $"lehrerapp-weather-tests-{Guid.NewGuid():N}");
|
||||
public SchoolWeatherStore Store { get; }
|
||||
public TempStore() { Directory.CreateDirectory(_path); Store = new(_path); }
|
||||
public void Dispose()
|
||||
{
|
||||
Store.Dispose();
|
||||
if (Directory.Exists(_path)) Directory.Delete(_path, recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user