Parties, items and the CRM archives need codes given by the system without
duplicates, and the address and bank fields should fill themselves; this adds
both before the party and item screens that use them.
- CodeMask ({seq:0000}, {anno}, {categoria}) and code_sequences (migration
015): one sequence per rule, year and category, taken under a lock in the
transaction that saves the record, skipping codes written by hand
- CodeRuleService: rules in company settings with the masks of SPEC 11.12,
validation, preview of the next code, manual code allowed or not
- AutoFillService: municipality from postal code and back, personal tax code,
VIES, bank and BIC from the IBAN, delivery date on working days, options
that can be switched off (the ECB job honours its option)
- IBankDirectory.ReadIban gives ABI and CAB even without the ABI list; the
Italian pack now registers the directory
- Company preferences page (mockup 074) at /tabelle/preferenze, in the menu
- aria-checked now renders true/false on switch rows and profile radios
- ADR 0027, wiki, CHANGELOG, STATUS, DATA-MODEL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
6.3 KiB
C#
155 lines
6.3 KiB
C#
using Khaemhat.Fiscal.Abstractions;
|
|
|
|
namespace Khaemhat.Fiscal.Italy.Tests;
|
|
|
|
[TestClass]
|
|
public sealed class ItalianVatNumberValidatorTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("01234567897")]
|
|
[DataRow("IT 01234567897")]
|
|
[DataRow("it01234567897")]
|
|
public void ValidNumbers_PassWithOrWithoutPrefix(string number) => Assert.IsTrue(ItalianVatNumberValidator.IsValid(number));
|
|
|
|
[TestMethod]
|
|
[DataRow("01234567890")] // wrong check digit
|
|
[DataRow("1234567897")] // ten digits
|
|
[DataRow("00000000000")] // no taxpayer number
|
|
[DataRow("0123456789A")]
|
|
public void InvalidNumbers_AreRefused(string number) => Assert.IsFalse(ItalianVatNumberValidator.IsValid(number));
|
|
}
|
|
|
|
[TestClass]
|
|
public sealed class FiscalCodeTests
|
|
{
|
|
private static readonly DateOnly Today = new(2026, 11, 11);
|
|
|
|
[TestMethod]
|
|
public void Compute_GivesTheKnownCode()
|
|
{
|
|
var code = FiscalCodeCalculator.Compute(new PersonalTaxCodeData("Rossi", "Mario", new DateOnly(1980, 1, 1), PersonSex.Male, "H501"));
|
|
|
|
Assert.AreEqual("RSSMRA80A01H501U", code);
|
|
Assert.IsTrue(FiscalCodeValidator.IsValid(code));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Compute_FollowsTheRulesForNamesAndWomen()
|
|
{
|
|
var code = FiscalCodeCalculator.Compute(new PersonalTaxCodeData("De Luca", "Giovanna Maria", new DateOnly(1975, 12, 31), PersonSex.Female, "f205"));
|
|
|
|
// Surname: consonants D, L, C. Name with four consonants or more: 1st, 3rd and 4th (G, N, N).
|
|
StringAssert.StartsWith(code, "DLCGNN75T71F205");
|
|
Assert.IsTrue(FiscalCodeValidator.IsValidPersonal(code));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Compute_PadsShortNamesWithVowelsAndX()
|
|
{
|
|
var code = FiscalCodeCalculator.Compute(new PersonalTaxCodeData("Fo", "Ugo", new DateOnly(2001, 7, 9), PersonSex.Male, "L219"));
|
|
|
|
StringAssert.StartsWith(code, "FOXGUO01L09L219");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Compute_IgnoresAccentsAndApostrophes()
|
|
{
|
|
var plain = FiscalCodeCalculator.Compute(new PersonalTaxCodeData("DAMICO", "NICOLO", new DateOnly(1990, 5, 20), PersonSex.Male, "A944"));
|
|
var typed = FiscalCodeCalculator.Compute(new PersonalTaxCodeData("D'Amico", "Nicolò", new DateOnly(1990, 5, 20), PersonSex.Male, "A944"));
|
|
|
|
Assert.AreEqual(plain, typed);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Validator_AcceptsOmocodiaAndRefusesAWrongCheckCharacter()
|
|
{
|
|
// H501 becomes H50M (1 -> M) and the check character is computed again.
|
|
var first15 = "RSSMRA80A01H50M";
|
|
var omocodic = first15 + FiscalCodeValidator.CheckCharacter(first15);
|
|
|
|
Assert.IsTrue(FiscalCodeValidator.IsValidPersonal(omocodic));
|
|
Assert.IsFalse(FiscalCodeValidator.IsValidPersonal("RSSMRA80A01H501A"));
|
|
Assert.IsFalse(FiscalCodeValidator.IsValidPersonal("RSSMRA80Z01H501U"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Validator_AcceptsCompanyCodes() => Assert.IsTrue(FiscalCodeValidator.IsValid("01234567897"));
|
|
|
|
[TestMethod]
|
|
public void Decode_ReadsBirthDateSexAndPlace()
|
|
{
|
|
var man = FiscalCodeCalculator.Decode("RSSMRA80A01H501U", Today);
|
|
var woman = FiscalCodeCalculator.Decode(FiscalCodeCalculator.Compute(new("Bianchi", "Anna", new DateOnly(2010, 3, 15), PersonSex.Female, "F205")), Today);
|
|
|
|
Assert.AreEqual(new PersonalTaxCodeInfo(new DateOnly(1980, 1, 1), PersonSex.Male, "H501"), man);
|
|
Assert.AreEqual(new DateOnly(2010, 3, 15), woman!.BirthDate);
|
|
Assert.AreEqual(PersonSex.Female, woman.Sex);
|
|
Assert.IsNull(FiscalCodeCalculator.Decode("RSSMRA80A01H501A", Today));
|
|
}
|
|
}
|
|
|
|
[TestClass]
|
|
public sealed class SdiRecipientCodeTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("ABC1234", RecipientKind.Business)]
|
|
[DataRow("0000000", RecipientKind.Business)]
|
|
[DataRow("UFE3RT", RecipientKind.PublicAdministration)]
|
|
[DataRow("0000000", RecipientKind.Consumer)]
|
|
[DataRow("", RecipientKind.Consumer)]
|
|
[DataRow("XXXXXXX", RecipientKind.Foreign)]
|
|
public void ValidCodes_HaveNoProblems(string code, RecipientKind kind) =>
|
|
Assert.IsEmpty(SdiRecipientCodeValidator.Check(code, kind));
|
|
|
|
[TestMethod]
|
|
[DataRow("ABC123", RecipientKind.Business, "fiscal.recipient.business-length")]
|
|
[DataRow("XXXXXXX", RecipientKind.Business, "fiscal.recipient.foreign-code-domestic")]
|
|
[DataRow("ABC1234", RecipientKind.PublicAdministration, "fiscal.recipient.pa-length")]
|
|
[DataRow("", RecipientKind.PublicAdministration, "fiscal.recipient.required")]
|
|
[DataRow("0000000", RecipientKind.Foreign, "fiscal.recipient.foreign")]
|
|
[DataRow("AB-1234", RecipientKind.Business, "fiscal.recipient.characters")]
|
|
public void WrongCodes_SayWhy(string code, RecipientKind kind, string problem) =>
|
|
Assert.AreEqual(problem, SdiRecipientCodeValidator.Check(code, kind).Single().Code);
|
|
|
|
[TestMethod]
|
|
public void Defaults_DependOnTheCustomer()
|
|
{
|
|
var rules = new ItalianTaxIdentifierRules();
|
|
|
|
Assert.AreEqual("XXXXXXX", rules.DefaultRecipientCode(RecipientKind.Foreign));
|
|
Assert.AreEqual("0000000", rules.DefaultRecipientCode(RecipientKind.Consumer));
|
|
Assert.IsNull(rules.DefaultRecipientCode(RecipientKind.PublicAdministration));
|
|
}
|
|
}
|
|
|
|
[TestClass]
|
|
public sealed class ItalianBankDirectoryTests
|
|
{
|
|
[TestMethod]
|
|
public void FindByIban_ReadsAbiAndCab()
|
|
{
|
|
var directory = new ItalianBankDirectory([new BankInfo("05428", "Banca di prova", "BPROITMMXXX", null)]);
|
|
|
|
var bank = directory.FindByIban("IT60 X054 2811 1010 0000 0123 456");
|
|
|
|
Assert.AreEqual("Banca di prova", bank!.Name);
|
|
Assert.AreEqual("11101", bank.BranchCode);
|
|
Assert.IsNull(directory.FindByIban("DE89 3704 0044 0532 0130 00"));
|
|
Assert.AreEqual(("05428", "11101"), ItalianBankDirectory.CodesOf("IT60X0542811101000000123456"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ReadIban_GivesTheCodes_EvenForAnUnknownBank()
|
|
{
|
|
var directory = new ItalianBankDirectory([]);
|
|
|
|
var bank = directory.ReadIban("IT60X0542811101000000123456");
|
|
|
|
Assert.AreEqual(new BankInfo("05428", null, null, "11101"), bank);
|
|
Assert.IsNull(directory.FindByIban("IT60X0542811101000000123456"));
|
|
Assert.IsNull(directory.ReadIban("DE89370400440532013000"));
|
|
Assert.IsNull(directory.ReadIban("IT00X0542811101000000123456"));
|
|
Assert.IsNotNull(new ItalyFiscalPack().GetFeature<IBankDirectory>());
|
|
}
|
|
}
|