test(prime): restore the PrimeScheduleRepository tests dropped in 022eaf38

This commit is contained in:
mika kuns
2026-08-25 08:31:11 +02:00
parent 022eaf385c
commit c02a4cf871
@@ -18,6 +18,75 @@ public class PrimeScheduleRepositoryTests : IDisposable
Kind = kind, Kind = kind,
}; };
[Fact]
public async Task Upsert_Then_List_RoundTrips()
{
var id = Guid.NewGuid();
using (var ctx = _db.CreateContext())
{
await new PrimeScheduleRepository(ctx).UpsertAsync(new PrimeScheduleEntity
{
Id = id,
Days = PrimeDays.Weekdays,
TimeOfDay = new TimeSpan(7, 0, 0),
Enabled = true,
CreatedAt = DateTimeOffset.UtcNow,
});
}
using var read = _db.CreateContext();
var rows = await new PrimeScheduleRepository(read).ListAsync();
Assert.Single(rows);
Assert.Equal(id, rows[0].Id);
Assert.Equal(new TimeSpan(7, 0, 0), rows[0].TimeOfDay);
Assert.Equal(PrimeDays.Weekdays, rows[0].Days);
}
[Fact]
public async Task UpdateLastRunAt_Persists()
{
var id = Guid.NewGuid();
var when = new DateTimeOffset(2026, 5, 5, 7, 1, 0, TimeSpan.FromHours(2));
using (var ctx = _db.CreateContext())
{
await new PrimeScheduleRepository(ctx).UpsertAsync(new PrimeScheduleEntity
{
Id = id,
Days = PrimeDays.Weekdays,
TimeOfDay = new TimeSpan(7, 0, 0),
Enabled = true,
CreatedAt = DateTimeOffset.UtcNow,
});
}
using (var ctx = _db.CreateContext())
await new PrimeScheduleRepository(ctx).UpdateLastRunAsync(id, when);
using var read = _db.CreateContext();
var row = await new PrimeScheduleRepository(read).GetAsync(id);
Assert.NotNull(row);
Assert.Equal(when, row!.LastRunAt);
}
[Fact]
public async Task Delete_Removes_Row()
{
var id = Guid.NewGuid();
using (var ctx = _db.CreateContext())
await new PrimeScheduleRepository(ctx).UpsertAsync(new PrimeScheduleEntity
{
Id = id,
Days = PrimeDays.All,
TimeOfDay = TimeSpan.Zero,
Enabled = true,
CreatedAt = DateTimeOffset.UtcNow,
});
using (var ctx = _db.CreateContext())
await new PrimeScheduleRepository(ctx).DeleteAsync(id);
using var read = _db.CreateContext();
Assert.Empty(await new PrimeScheduleRepository(read).ListAsync());
}
[Fact] [Fact]
public void Kind_defaults_to_ping_on_a_new_entity() public void Kind_defaults_to_ping_on_a_new_entity()
{ {