using Chronos.Core.Imaging;
using Chronos.Core.Model;
using Chronos.Testing;
namespace Chronos.Data.Tests.Infrastructure;
/// Base of repository tests: a migrated per test.
public abstract class RepositoryTest(TestContext context) : DatabaseTest(context)
{
/// Opens a fresh migrated database; forces a SQLite file.
protected async Task OpenChronosAsync(bool multiConnection = false) =>
Own(await ChronosDatabase.OpenAsync(await NewOptionsAsync(multiConnection), Ct));
}
/// Builders of valid entities with distinct ids; override fields with with.
internal static class TestData
{
/// A fixed reference instant (microsecond precision, like the databases).
public static readonly DateTimeOffset Now = new(2026, 10, 2, 9, 0, 0, TimeSpan.Zero);
public static Archive Archive(string name = "Main") => new()
{
Id = Guid.CreateVersion7(),
Name = name,
RootPath = "/archive/" + name,
Created = Now,
};
public static Sequence Sequence(Guid archiveId, DateTime? firstCapture = null, string? title = null, string camera = "EOS R5") => new()
{
Id = Guid.CreateVersion7(),
ArchiveId = archiveId,
Title = title,
Folder = $"2026/{Guid.NewGuid():N}",
CameraMake = "Canon",
CameraModel = camera,
FirstCapture = firstCapture,
LastCapture = firstCapture?.AddHours(1),
UpdatedAt = Now,
};
public static Frame Frame(Guid sequenceId, int index, DateTime? capturedAt = null) => new()
{
Id = Guid.CreateVersion7(),
SequenceId = sequenceId,
Index = index,
RelativePath = $"2026/seq/originals/IMG_{index:0000}.CR3",
FileName = $"IMG_{index:0000}.CR3",
Size = 25_000_000 + index,
Sha256 = Convert.ToHexStringLower(BitConverter.GetBytes((long)index)).PadLeft(64, '0'),
CapturedAt = capturedAt ?? new DateTime(2026, 9, 28, 18, 0, 0).AddSeconds(5 * index),
TimestampSource = TimestampSource.ExifOriginal,
ExposureTime = 1 / 250.0,
FNumber = 8,
Iso = 100,
FocalLength = 24,
Width = 8192,
Height = 5464,
Format = ImageFileFormat.Cr3,
};
public static Job Job(JobKind kind = JobKind.Scan, JobPriority priority = JobPriority.Normal, DateTimeOffset? created = null) => new()
{
Id = Guid.CreateVersion7(),
Kind = kind,
Priority = priority,
State = JobState.Queued,
Created = created ?? Now,
};
public static User User(string username = "alice") => new()
{
Id = Guid.CreateVersion7(),
Username = username,
PasswordHash = "pbkdf2-sha512$210000$salt$hash",
Role = UserRole.Editor,
Permissions = RolePermissions.Default(UserRole.Editor),
Created = Now,
};
}