Files
Khaemhat/tests/Khaemhat.Core.Tests/Architecture/FiscalPackIsolationTests.cs
T
Alby96andClaude Opus 5.5 49d2bb166b feat: fiscal pack abstractions and the Italian pack (#37)
The rest of the product needs tax codes, natures, code lists and VAT rules
without knowing the country. IFiscalPack exposes the parts every country has
(tax code catalog, tax engine, calendar) and optional features by type, so a
module can tell a missing feature from a broken one. FiscalPackCatalog finds
the pack by country; only the composition root names the Italian pack, as an
architecture test now checks.

The Italian pack carries the FatturaPA 1.9.1 code lists, VAT natures and base
tax codes with their rules, summary rounding on the total per rate, the stamp
duty rule, VAT deadlines with the August and holiday shifts, withholding kinds,
basic depreciation rules and F24 codes. ADR 0025 records the design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 21:48:09 +01:00

65 lines
3.1 KiB
C#

namespace Khaemhat.Core.Tests.Architecture;
/// <summary>
/// ADR 0007 and ADR 0025: the Italian pack is reached only through the interfaces of <c>Khaemhat.Fiscal.Abstractions</c>.
/// Project references already keep it out of <c>Application</c>; these tests keep it out of the sources of
/// <c>Web</c> too, except for the composition root.
/// </summary>
[TestClass]
public sealed class FiscalPackIsolationTests
{
private const string ItalianNamespace = "Khaemhat.Fiscal.Italy";
// The composition root registers the pack; nothing else names it.
private static readonly HashSet<string> AllowedOutsideThePack = new(StringComparer.Ordinal)
{
"src/Khaemhat.Web/Hosting/KhaemhatServices.cs",
};
[TestMethod]
public void OnlyTheCompositionRoot_NamesTheItalianPack()
{
var violations = SourceFiles()
.Where(f => !f.Relative.StartsWith("src/Khaemhat.Fiscal.Italy/", StringComparison.Ordinal))
.Where(f => !AllowedOutsideThePack.Contains(f.Relative))
.Where(f => File.ReadAllText(f.Path).Contains(ItalianNamespace, StringComparison.Ordinal))
.Select(f => f.Relative)
.ToList();
Assert.IsEmpty(violations, "Use IFiscalPack and FiscalPackCatalog instead of the Italian pack in: " + string.Join(", ", violations));
}
[TestMethod]
public void TheAbstractions_SayNothingItalian()
{
string[] italianTerms = ["Italy", "Italian", "FatturaPa", "Iva"];
var violations = SourceFiles()
.Where(f => f.Relative.StartsWith("src/Khaemhat.Fiscal.Abstractions/", StringComparison.Ordinal))
.SelectMany(f => italianTerms
.Where(term => CodeLines(f.Path).Any(line => line.Contains(term, StringComparison.Ordinal)))
.Select(term => $"{f.Relative}: {term}"))
.ToList();
Assert.IsEmpty(violations, "Country-specific names belong in the country pack: " + string.Join("; ", violations));
}
[TestMethod]
public void TheCompositionRoot_RegistersThePackBehindTheCatalog()
{
var root = File.ReadAllText(Path.Combine(RepositoryLayout.Root, "src", "Khaemhat.Web", "Hosting", "KhaemhatServices.cs"));
StringAssert.Contains(root, "AddSingleton<IFiscalPack, ItalyFiscalPack>()");
StringAssert.Contains(root, "new FiscalPackCatalog(");
}
private static IEnumerable<(string Path, string Relative)> SourceFiles() =>
Directory.EnumerateFiles(Path.Combine(RepositoryLayout.Root, "src"), "*.*", SearchOption.AllDirectories)
.Where(f => f.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".razor", StringComparison.OrdinalIgnoreCase))
.Select(f => (Path: f, Relative: RepositoryLayout.Relative(f)))
.Where(f => !f.Relative.Contains("/obj/", StringComparison.Ordinal) && !f.Relative.Contains("/bin/", StringComparison.Ordinal));
// Comments may cite the country as an example (Italy: N1...N7); code may not.
private static IEnumerable<string> CodeLines(string path) =>
File.ReadLines(path).Where(line => !line.TrimStart().StartsWith("//", StringComparison.Ordinal));
}