Files
Chronos/tests/Titano.Data.Tests/Infrastructure/TestData.cs
T
Claude 2fbb7bc179 test(data): cover migrations and every repository on both dialects
Shared abstract suites run against in-memory/temp-file SQLite and, with
TITANO_TEST_PG, a private PostgreSQL schema per test: migration
idempotency and version refusal, keyset paging with ties for every sort,
statistics, exclusive job claiming under 8 concurrent claimers, and the
100k-frame bulk insert under 15 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 10:05:43 +00:00

81 lines
2.9 KiB
C#

using Titano.Core.Imaging;
using Titano.Core.Model;
using Titano.Testing;
namespace Titano.Data.Tests.Infrastructure;
/// <summary>Base of repository tests: a migrated <see cref="TitanoDatabase"/> per test.</summary>
public abstract class RepositoryTest(TestContext context) : DatabaseTest(context)
{
/// <summary>Opens a fresh migrated database; <paramref name="multiConnection"/> forces a SQLite file.</summary>
protected async Task<TitanoDatabase> OpenTitanoAsync(bool multiConnection = false) =>
Own(await TitanoDatabase.OpenAsync(await NewOptionsAsync(multiConnection), Ct));
}
/// <summary>Builders of valid entities with distinct ids; override fields with <c>with</c>.</summary>
internal static class TestData
{
/// <summary>A fixed reference instant (microsecond precision, like the databases).</summary>
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,
};
}