Documents need attachments and generated files (SPEC 9.4) before the UI of M3 can show them, and the spec forbids external libraries for PDF and spreadsheets. - VolumeFileStore keeps files under <data>/files/<COMPANY>/<yyyy>/<guid>, writing a .part file in the same folder with size limit and SHA-256, then quota and scanner checks (IFileScanner hook, no-op by default). - attachments table (migration 007) with kind, version series, lock, trash and the uploading user; AttachmentService uploads, adds generated files as the next version, lists, opens, zips, locks, trashes, restores and purges after 30 days (new system job system.attachments-trash). - FileGenerationService runs IFileGenerator implementations into the store; three generators for the fictitious test document (PDF, CSV, XLSX). - CsvWriter (Italian Excel defaults, formula-injection guard), XlsxWriter, ZipStreamWriter and PdfWriter (standard Type1 fonts, WinAnsi, AFM widths, JPEG, Flate, xref) only write asynchronously, so they can stream to an HTTP response. - ADR 0021 records versioning, storage layout, PDF scope and CSV defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.5 KiB
C#
89 lines
3.5 KiB
C#
using Khaemhat.Core.Instance;
|
|
using Khaemhat.Data.Mapping;
|
|
using Khaemhat.Data.Schema;
|
|
using Khaemhat.Data.SystemDatabase;
|
|
using Khaemhat.Data.Tests.Support;
|
|
|
|
namespace Khaemhat.Data.Tests;
|
|
|
|
[TestClass]
|
|
public sealed class MappingTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("RowVersion", "row_version")]
|
|
[DataRow("IsDemo", "is_demo")]
|
|
[DataRow("VatID", "vat_id")]
|
|
[DataRow("HTTPCode", "http_code")]
|
|
[DataRow("Address2", "address2")]
|
|
[DataRow("Id", "id")]
|
|
public void SnakeCase(string name, string expected) => Assert.AreEqual(expected, SqlNames.ToSnakeCase(name));
|
|
|
|
[TestMethod]
|
|
public void Conventions_KeyTypesNullabilityAndAudit()
|
|
{
|
|
var map = new TestItemMap();
|
|
map.Freeze();
|
|
|
|
Assert.AreEqual("id", map.Key.ColumnName);
|
|
Assert.IsTrue(map.Key.IsIdentity);
|
|
Assert.AreEqual("id", map.Columns[0].ColumnName);
|
|
Assert.AreEqual("row_version", map.Columns[^1].ColumnName);
|
|
Assert.AreSame(map.Columns[^1], map.RowVersion);
|
|
|
|
Assert.AreEqual("String(20)", map.Column(x => x.Code).TypeDescription);
|
|
Assert.IsFalse(map.Column(x => x.Code).IsNullable);
|
|
Assert.IsTrue(map.Column(x => x.Name).IsNullable);
|
|
Assert.AreEqual(ColumnType.Decimal, map.Column(x => x.Amount).Type);
|
|
Assert.AreEqual(ColumnType.Date, map.Column(x => x.Day).Type);
|
|
Assert.IsTrue(map.Column(x => x.Day).IsNullable);
|
|
Assert.AreEqual(ColumnType.Json, map.Column(x => x.Payload).Type);
|
|
Assert.AreEqual("String(40)", map.Column(x => x.Kind).TypeDescription);
|
|
Assert.AreEqual(ColumnType.Bool, map.Column(x => x.IsDemo).Type);
|
|
Assert.AreEqual(AuditRole.CreatedBy, map.Column(x => x.CreatedBy).Audit);
|
|
Assert.AreEqual("String(100)", map.Column(x => x.CreatedBy).TypeDescription);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Enums_AreStoredByName()
|
|
{
|
|
var map = new CompanyMap();
|
|
map.Freeze();
|
|
var status = map.Column(x => x.Status);
|
|
|
|
Assert.AreEqual("Maintenance", status.ToProvider(CompanyStatus.Maintenance));
|
|
Assert.AreEqual(CompanyStatus.ReadOnly, status.FromProvider("ReadOnly"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Registry_RejectsTwoMapsForOneEntity()
|
|
{
|
|
var registry = new MapRegistry().Add(new CompanyMap());
|
|
|
|
Assert.ThrowsExactly<InvalidOperationException>(() => registry.Add(new CompanyMap()));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Registry_FindsTheMapsOfBothDatabases()
|
|
{
|
|
var registry = new MapRegistry().AddFromAssembly(typeof(CompanyMap).Assembly);
|
|
|
|
string[] expected =
|
|
[
|
|
"sys_companies", "sys_data_protection_keys", "sys_job_locks", "sys_job_runs", "sys_license_activations", "sys_licenses", "sys_log",
|
|
"sys_notifications", "sys_roles_templates", "sys_scheduled_tasks", "sys_security_audit", "sys_sessions", "sys_settings", "sys_user_settings", "sys_users",
|
|
"attachments", "audit_log", "notifications", "role_permissions", "roles", "user_permission_overrides", "user_roles", "user_sessions", "user_settings", "users",
|
|
];
|
|
CollectionAssert.AreEquivalent(expected, registry.Maps.Select(m => m.Table).ToArray());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void StringWithoutLength_IsText_AndFrozenMapsCannotChange()
|
|
{
|
|
var map = new SystemSettingMap();
|
|
map.Freeze();
|
|
|
|
Assert.AreEqual(ColumnType.Text, map.Column(x => x.Value).Type);
|
|
Assert.ThrowsExactly<InvalidOperationException>(() => map.Column(x => x.Key).MaxLength(10));
|
|
}
|
|
}
|