Files
Chronos/tests/Chronos.Data.Tests/Core/ValueConversionTests.cs
T
Alby96andClaude Opus 5.5 5f27a86406
CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
refactor!: rename Titano to Chronos and move CI and releases to Gitea
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout. The release cross-compiles the Windows programs, checks their
  icon, version and DPI manifest, packs installers and zips, publishes the
  Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only
  tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow) and
  pe-check.

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 11:34:48 +02:00

91 lines
4.5 KiB
C#

using Chronos.Testing;
namespace Chronos.Data.Tests.Core;
/// <summary>Dialect-independent value handling: parameter normalisation, row conversions, text forms.</summary>
public sealed class ValueConversionTests
{
private static DbRow Row(params object?[] values) =>
new(new DbColumns(values.Select((_, i) => "c" + i).ToArray()), values);
[Test]
public void ParametersKeepTheirTypeEvenWhenNull()
{
Assert.Equal(DbValueType.Uuid, ((DbParam)(Guid?)null).Type);
Assert.Equal(DbValueType.LocalDateTime, ((DbParam)(DateTime?)null).Type);
Assert.Equal(DbValueType.Auto, DbParam.Null.Type);
Assert.Equal(DbValueType.Int64, new DbParam(DayOfWeek.Friday).Type);
Assert.Equal(5L, new DbParam(DayOfWeek.Friday).Value);
Assert.Equal(DbValueType.Timestamp, ((DbParam)new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Type);
Assert.Equal(DbValueType.LocalDateTime, ((DbParam)new DateTime(2020, 1, 1)).Type);
Assert.Equal(3, new DbParam((short)3).Value);
Assert.Throws<NotSupportedException>(() => new DbParam(new object()));
}
[Test]
public void RowGettersConvertBetweenProviderForms()
{
var guid = Guid.CreateVersion7();
var row = Row(42L, "0190a8b4-5c4e-7a1b-9c3d-0123456789ab", "2026-09-28T16:30:15.123456Z", "2024-02-29T23:59:58.500000", 1L, 3.0, guid, null);
Assert.Equal(42, row.GetInt32(0));
Assert.Equal(Guid.Parse("0190a8b4-5c4e-7a1b-9c3d-0123456789ab"), row.GetGuid(1));
Assert.Equal(new DateTimeOffset(2026, 9, 28, 16, 30, 15, 123, TimeSpan.Zero).AddTicks(4560), row.GetDateTimeOffset(2));
Assert.Equal(new DateTime(2024, 2, 29, 23, 59, 58, 500), row.GetDateTime(3));
Assert.True(row.GetBool(4));
Assert.Equal(3L, row.GetInt64(5));
Assert.Equal(guid.ToString(), row.GetString(6));
Assert.Null(row.GetInt32OrNull(7));
Assert.Equal(DayOfWeek.Wednesday, row.Get<DayOfWeek>(5));
Assert.Equal(42, row.Get<int?>(0));
Assert.Null(row.Get<string>(7));
Assert.Equal(1, row.GetOrdinal("C1"));
Assert.Throws<InvalidCastException>(() => row.GetGuid(0));
Assert.Throws<OverflowException>(() => Row(long.MaxValue).GetInt32(0));
Assert.Throws<IndexOutOfRangeException>(() => row.GetOrdinal("missing"));
}
[Theory]
[Case("2026-09-28 18:30:15.5+02", "2026-09-28T16:30:15.5000000+00:00")]
[Case("2026-09-28 18:30:15+05:30", "2026-09-28T13:00:15.0000000+00:00")]
[Case("2026-09-28T18:30:15.1234567Z", "2026-09-28T18:30:15.1234567+00:00")]
[Case("2026-09-28T18:30:15.12345678Z", "2026-09-28T18:30:15.1234567+00:00")]
[Case("2026-09-28 18:30", "2026-09-28T18:30:00.0000000+00:00")]
[Case("2026-09-28", "2026-09-28T00:00:00.0000000+00:00")]
[Case("1999-12-31 23:00:00-01", "2000-01-01T00:00:00.0000000+00:00")]
public void ParsesTimestampTextForms(string text, string expected) =>
Assert.Equal(expected, TextValues.ParseTimestamp(text).ToString("O"));
[Theory]
[Case("2026-02-30")]
[Case("2026-09-28 25:00:00")]
[Case("26-09-28")]
[Case("2026-09-28T10:00:00.Z")]
[Case("2026-09-28T10:00:00+1")]
public void RejectsMalformedTimestamps(string text) =>
Assert.Throws<FormatException>(() => TextValues.ParseTimestamp(text));
[Test]
public void StoredTextFormsSortChronologically()
{
var a = new DateTimeOffset(2026, 1, 1, 9, 0, 0, TimeSpan.Zero);
var values = new[] { a, a.AddTicks(10), a.AddSeconds(1), a.AddYears(-1), a.AddMilliseconds(999) };
var sorted = values.Select(TextValues.FormatTimestamp).OrderBy(s => s, StringComparer.Ordinal).ToList();
Assert.SequenceEqual(values.OrderBy(v => v).Select(TextValues.FormatTimestamp), sorted);
Assert.Equal("2026-01-01T09:00:00.000001Z", TextValues.FormatTimestamp(a.AddTicks(10)));
}
[Test]
public void BuildsUpsertsAndPatterns()
{
Assert.Equal(
"INSERT INTO t (a, b, c) VALUES ($1, $2, $3) ON CONFLICT (a) DO UPDATE SET b = excluded.b, c = excluded.c",
SqlDialect.Upsert("t", ["a", "b", "c"], 1));
Assert.Equal("INSERT INTO t (a, b) VALUES ($1, $2) ON CONFLICT (a, b) DO NOTHING", SqlDialect.Upsert("t", ["a", "b"], 2));
Assert.Equal(
"INSERT INTO t (a, b, c) VALUES ($1, $2, $3) ON CONFLICT (a) DO UPDATE SET c = excluded.c",
SqlDialect.Upsert("t", ["a", "b", "c"], 1, ["b"]));
Assert.Equal("%50\\%\\_off\\\\%", SqlDialect.ContainsPattern("50%_off\\"));
Assert.Equal("\"we\"\"ird\"", SqlDialect.QuoteIdentifier("we\"ird"));
}
}