62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using ClaudeDo.Data.Models;
|
|
using ClaudeDo.Data.Repositories;
|
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
|
|
|
namespace ClaudeDo.Worker.Tests.Repositories;
|
|
|
|
public class PrimeScheduleRepositoryTests : IDisposable
|
|
{
|
|
private readonly DbFixture _db = new();
|
|
public void Dispose() => _db.Dispose();
|
|
|
|
private static PrimeScheduleEntity Row(PrimeActionKind kind) => new()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Days = PrimeDays.Weekdays,
|
|
TimeOfDay = new TimeSpan(7, 0, 0),
|
|
Enabled = true,
|
|
Kind = kind,
|
|
};
|
|
|
|
[Fact]
|
|
public void Kind_defaults_to_ping_on_a_new_entity()
|
|
{
|
|
Assert.Equal(PrimeActionKind.Ping, new PrimeScheduleEntity().Kind);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Kind_round_trips_through_the_database()
|
|
{
|
|
using var ctx = _db.CreateContext();
|
|
var repo = new PrimeScheduleRepository(ctx);
|
|
var row = Row(PrimeActionKind.Custom);
|
|
|
|
await repo.UpsertAsync(row);
|
|
var reloaded = await repo.GetAsync(row.Id);
|
|
|
|
Assert.NotNull(reloaded);
|
|
Assert.Equal(PrimeActionKind.Custom, reloaded!.Kind);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpsertAsync_updates_kind_on_an_existing_row()
|
|
{
|
|
using var ctx = _db.CreateContext();
|
|
var repo = new PrimeScheduleRepository(ctx);
|
|
var row = Row(PrimeActionKind.Ping);
|
|
await repo.UpsertAsync(row);
|
|
|
|
await repo.UpsertAsync(new PrimeScheduleEntity
|
|
{
|
|
Id = row.Id,
|
|
Days = row.Days,
|
|
TimeOfDay = row.TimeOfDay,
|
|
Enabled = row.Enabled,
|
|
Kind = PrimeActionKind.FillMyDay,
|
|
});
|
|
|
|
var reloaded = await repo.GetAsync(row.Id);
|
|
Assert.Equal(PrimeActionKind.FillMyDay, reloaded!.Kind);
|
|
}
|
|
}
|