Adds the company tables of SPEC 11.1 behind one generic service so that every table gets the same rules, history, cache and CSV import/export, plus the company profile, fiscal years with monthly lock and the base-data seeder. - 26 coded tables, exchange rates, company profile, fiscal years and periods: entities, maps and migrations 010-014 - TableService + TableCatalog: unique codes, per-table rules (VAT codes are checked by the fiscal pack), delete or disable when in use, single default, CSV export/import all-or-nothing, cache with cross-instance invalidation - CompanyProfileService (Italian identifiers through the pack), FiscalYearService with the date check used by every dated record - EcbRatesClient and the ECB rates system task; CsvReader - ISeeder/SeedRunner with the data version in company settings; base tables from the pack (IBaseTablesTemplate) and an embedded ISO country list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.7 KiB
C#
75 lines
3.7 KiB
C#
using Khaemhat.Application.Tables;
|
|
using Khaemhat.Core.Tables;
|
|
|
|
namespace Khaemhat.Application.Tests;
|
|
|
|
[TestClass]
|
|
public sealed class TableRulesTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("{number}/{year}", true)]
|
|
[DataRow("{prefix}/{year}/{number:D6}", true)]
|
|
[DataRow("{section}-{number:D4}", true)]
|
|
[DataRow("{year}", false)]
|
|
[DataRow("{number}/{anno}", false)]
|
|
[DataRow("", false)]
|
|
public void NumberFormat_NeedsTheNumberAndKnownPlaceholders(string format, bool valid) =>
|
|
Assert.AreEqual(valid, DocumentNumberFormat.IsValid(format));
|
|
|
|
[TestMethod]
|
|
public void NumberFormat_WritesTheNumber()
|
|
{
|
|
Assert.AreEqual("FV/2026/000123", DocumentNumberFormat.Apply("{prefix}/{year}/{number:D6}", 123, 2026, "FV", null));
|
|
Assert.AreEqual("7/AF/2026", DocumentNumberFormat.Apply("{number}/{section}/{year}", 7, 2026, null, "AF"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void DiscountFormula_ChainsTheSteps()
|
|
{
|
|
Assert.IsTrue(DiscountFormula.TryParse("10 + 5", out var steps));
|
|
Assert.AreEqual("10+5", DiscountFormula.Format(steps));
|
|
Assert.AreEqual(14.5m, DiscountFormula.Equivalent(steps));
|
|
Assert.IsTrue(DiscountFormula.TryParse("2,5", out var single));
|
|
Assert.AreEqual("2,5", DiscountFormula.Format(single));
|
|
Assert.IsFalse(DiscountFormula.TryParse("10+abc", out _));
|
|
Assert.IsFalse(DiscountFormula.TryParse("120", out _));
|
|
Assert.IsFalse(DiscountFormula.TryParse("-5", out _));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void PeriodState_FollowsYearAndMonth()
|
|
{
|
|
var year = new FiscalYear { Id = 1, StartDate = new(2026, 1, 1), EndDate = new(2026, 12, 31) };
|
|
var march = new FiscalPeriod { FiscalYearId = 1, Number = 3, StartDate = new(2026, 3, 1), EndDate = new(2026, 3, 31), Status = FiscalPeriodStatus.Locked };
|
|
var april = new FiscalPeriod { FiscalYearId = 1, Number = 4, StartDate = new(2026, 4, 1), EndDate = new(2026, 4, 30), Status = FiscalPeriodStatus.Settled };
|
|
FiscalYearView[] calendar = [new(year, [march, april])];
|
|
|
|
Assert.AreEqual(PeriodState.Open, FiscalYearService.StateOf(calendar, new(2026, 5, 2), PeriodUse.Vat));
|
|
Assert.AreEqual(PeriodState.Locked, FiscalYearService.StateOf(calendar, new(2026, 3, 31), PeriodUse.NoVat));
|
|
Assert.AreEqual(PeriodState.Settled, FiscalYearService.StateOf(calendar, new(2026, 4, 10), PeriodUse.Vat));
|
|
Assert.AreEqual(PeriodState.Open, FiscalYearService.StateOf(calendar, new(2026, 4, 10), PeriodUse.NoVat));
|
|
Assert.AreEqual(PeriodState.NoYear, FiscalYearService.StateOf(calendar, new(2027, 1, 1), PeriodUse.NoVat));
|
|
|
|
year.Status = FiscalYearStatus.Closed;
|
|
Assert.AreEqual(PeriodState.YearClosed, FiscalYearService.StateOf(calendar, new(2026, 5, 2), PeriodUse.NoVat));
|
|
Assert.AreEqual("fiscal.date.locked", FiscalYearService.ErrorOf(PeriodState.Locked));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Catalog_HasEveryTableOnce_WithCsvColumnsStartingWithTheCode()
|
|
{
|
|
var catalog = new TableCatalog();
|
|
|
|
Assert.HasCount(26, catalog.All.ToList());
|
|
foreach (var table in catalog.All)
|
|
{
|
|
Assert.AreEqual("code", table.CsvColumns[0].Header, table.Key);
|
|
Assert.AreEqual("description", table.CsvColumns[1].Header, table.Key);
|
|
Assert.IsFalse(table.CsvColumns.Any(c => c.Header is "id" or "row_version" or "is_demo" || c.Header.EndsWith("_id", StringComparison.Ordinal)), table.Key);
|
|
}
|
|
|
|
CollectionAssert.Contains(catalog.Get<TaxCode>().CsvColumns.Select(c => c.Header).ToList(), "non_deductible_percent");
|
|
CollectionAssert.Contains(catalog.Get<PaymentMethod>().CsvColumns.Select(c => c.Header).ToList(), "e_invoice_code");
|
|
}
|
|
}
|