CI / Build and test (SQLite) (pull_request) Canceled after 0s
CI / PostgreSQL 16 integration (pull_request) Canceled after 0s
CI / PostgreSQL 17 integration (pull_request) Canceled after 0s
CI / Docker image (pull_request) Canceled after 0s
CI / YAML check (pull_request) Canceled after 0s
The wiki becomes a guide for the people who use Khaemhat: a new "Guida all'uso" page walks from sign-in to an invoice sent by e-mail, and Vendite is rewritten around the real screens of 0.5.0 (radars, document mask, Crea …, deferred invoicing, print preview, mail). Primi passi, Dati di esempio, Allegati, Log and Impostazioni describe what this version does, including the SMTP variables. README.md turns into the installation guide for developers: prerequisites, run-dev, tests with PostgreSQL, migrations, image and wiki publishing. The engine now writes confirmations, changes of state and deletions to the Documents log section, the last step of #53. ADR 0034 records the print and mail decisions; CHANGELOG 0.5.0 and STATUS close the milestone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
3.7 KiB
C#
80 lines
3.7 KiB
C#
using Khaemhat.Core.Logging;
|
|
using Khaemhat.Core.Scheduling;
|
|
|
|
namespace Khaemhat.Core.Tests.Common;
|
|
|
|
/// <summary>The five-field cron of the scheduled tasks (SPEC §9.6) and the log sections (SPEC §9.5).</summary>
|
|
[TestClass]
|
|
public sealed class CronExpressionTests
|
|
{
|
|
private static readonly TimeZoneInfo Rome = TimeZoneInfo.FindSystemTimeZoneById("Europe/Rome");
|
|
|
|
[TestMethod]
|
|
[DataRow("15 * * * *", "2026-11-11T10:20:00Z", "2026-11-11T11:15:00Z")]
|
|
[DataRow("*/10 * * * *", "2026-11-11T10:20:00Z", "2026-11-11T10:30:00Z")]
|
|
[DataRow("0 9-17/4 * * *", "2026-11-11T10:00:00Z", "2026-11-11T13:00:00Z")]
|
|
[DataRow("30 3 1,15 * *", "2026-11-11T00:00:00Z", "2026-11-15T03:30:00Z")]
|
|
[DataRow("0 0 * * 7", "2026-11-11T00:00:00Z", "2026-11-15T00:00:00Z")]
|
|
[DataRow("0 0 29 2 *", "2026-03-01T00:00:00Z", "2028-02-29T00:00:00Z")]
|
|
public void NextAfter_InUtc(string cron, string after, string expected)
|
|
{
|
|
var next = CronExpression.Parse(cron).NextAfter(DateTime.Parse(after, null, System.Globalization.DateTimeStyles.AdjustToUniversal), TimeZoneInfo.Utc);
|
|
|
|
Assert.AreEqual(DateTime.Parse(expected, null, System.Globalization.DateTimeStyles.AdjustToUniversal), next);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void DayOfMonthAndDayOfWeek_MatchEither()
|
|
{
|
|
// The 13th or any Friday: after Wednesday 11 November 2026 comes Friday the 13th, then Friday the 20th.
|
|
var cron = CronExpression.Parse("0 12 13 * 5");
|
|
var first = cron.NextAfter(new DateTime(2026, 11, 11, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Utc);
|
|
var second = cron.NextAfter(first!.Value, TimeZoneInfo.Utc);
|
|
|
|
Assert.AreEqual(new DateTime(2026, 11, 13, 12, 0, 0, DateTimeKind.Utc), first);
|
|
Assert.AreEqual(new DateTime(2026, 11, 20, 12, 0, 0, DateTimeKind.Utc), second);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LocalTimes_FollowTheTimeZone_AndSkipTheMissingHour()
|
|
{
|
|
var cron = CronExpression.Parse("30 2 * * *");
|
|
|
|
// 29 March 2026: in Rome clocks jump from 02:00 to 03:00, so 02:30 does not exist that night.
|
|
var spring = cron.NextAfter(new DateTime(2026, 3, 28, 12, 0, 0, DateTimeKind.Utc), Rome);
|
|
Assert.AreEqual(new DateTime(2026, 3, 30, 0, 30, 0, DateTimeKind.Utc), spring);
|
|
|
|
// In winter Rome is UTC+1.
|
|
var winter = cron.NextAfter(new DateTime(2026, 11, 11, 12, 0, 0, DateTimeKind.Utc), Rome);
|
|
Assert.AreEqual(new DateTime(2026, 11, 12, 1, 30, 0, DateTimeKind.Utc), winter);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("")]
|
|
[DataRow("* * * *")]
|
|
[DataRow("60 * * * *")]
|
|
[DataRow("* 24 * * *")]
|
|
[DataRow("* * 0 * *")]
|
|
[DataRow("* * * 13 *")]
|
|
[DataRow("* * * * 8")]
|
|
[DataRow("*/0 * * * *")]
|
|
[DataRow("a * * * *")]
|
|
public void InvalidExpressions_AreRefused(string text)
|
|
{
|
|
Assert.IsFalse(CronExpression.TryParse(text, out _, out var error));
|
|
Assert.IsFalse(string.IsNullOrEmpty(error));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LogSections_ComeFromTheCategory()
|
|
{
|
|
Assert.AreEqual(LogSection.Migrations, LogSections.FromCategory("Khaemhat.Data.Migrations.MigrationRunner"));
|
|
Assert.AreEqual("Sistema", LogSections.Label(LogSection.System));
|
|
Assert.AreEqual(LogSection.Authentication, LogSections.FromCategory("Khaemhat.Application.Security.SignInService"));
|
|
Assert.AreEqual(LogSection.ScheduledJobs, LogSections.FromCategory("Khaemhat.Application.Jobs.JobScheduler"));
|
|
Assert.AreEqual(LogSection.Documents, LogSections.FromCategory("Khaemhat.Application.Documents.DocumentEngine"));
|
|
Assert.AreEqual(LogSection.Email, LogSections.FromCategory("Khaemhat.Infrastructure.Mail.MailQueue"));
|
|
Assert.AreEqual("Performance", LogSections.Scope(LogSection.Performance).Single().Value);
|
|
}
|
|
}
|