Parties need their identifiers checked before they reach documents. IBAN, EAN and e-mail checks are international and live in Core. The Italian VAT number, fiscal code (with calculator, decoder and omocodia) and SDI recipient code are Italian, so they sit in the Italian pack behind ITaxIdentifierRules, as the non-negotiable rule of SPEC 1.10 wins over the class list of SPEC 21 (ADR 0025). IBankDirectory reads ABI and CAB from an Italian IBAN; its bank list arrives with the base data. ViesClient calls the VIES REST service and never reports a number as invalid when the service could not answer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using Khaemhat.Core.Validation;
|
|
|
|
namespace Khaemhat.Core.Tests.Validation;
|
|
|
|
[TestClass]
|
|
public sealed class IbanValidatorTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("IT60 X054 2811 1010 0000 0123 456")]
|
|
[DataRow("it60x0542811101000000123456")]
|
|
[DataRow("DE89 3704 0044 0532 0130 00")]
|
|
[DataRow("GB82 WEST 1234 5698 7654 32")]
|
|
[DataRow("FR14 2004 1010 0505 0001 3M02 606")]
|
|
public void KnownIbans_AreValid(string iban) => Assert.IsTrue(IbanValidator.IsValid(iban));
|
|
|
|
[TestMethod]
|
|
[DataRow("IT61 X054 2811 1010 0000 0123 456")] // wrong check digits
|
|
[DataRow("IT60 X054 2811 1010 0000 0123 45")] // Italian IBANs have 27 characters
|
|
[DataRow("DE89-3704-0044-0532-0130-00")]
|
|
[DataRow("")]
|
|
[DataRow(null)]
|
|
public void WrongIbans_AreRefused(string? iban) => Assert.IsFalse(IbanValidator.IsValid(iban));
|
|
|
|
[TestMethod]
|
|
public void Format_GroupsByFour() =>
|
|
Assert.AreEqual("IT60 X054 2811 1010 0000 0123 456", IbanValidator.Format("it60x0542811101000000123456"));
|
|
}
|
|
|
|
[TestClass]
|
|
public sealed class EanValidatorTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("4006381333931")]
|
|
[DataRow("96385074")]
|
|
[DataRow("036000291452")]
|
|
[DataRow("10012345678902")]
|
|
public void KnownBarcodes_AreValid(string code) => Assert.IsTrue(EanValidator.IsValid(code));
|
|
|
|
[TestMethod]
|
|
[DataRow("4006381333932")]
|
|
[DataRow("400638133393")]
|
|
[DataRow("40063813339A1")]
|
|
public void WrongBarcodes_AreRefused(string code) => Assert.IsFalse(EanValidator.IsValid(code));
|
|
}
|
|
|
|
[TestClass]
|
|
public sealed class EmailValidatorTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("mario.rossi@example.it")]
|
|
[DataRow("fatture+2026@pec.example-azienda.it")]
|
|
[DataRow("a@b.co")]
|
|
public void UsualAddresses_AreValid(string address) => Assert.IsTrue(EmailValidator.IsValid(address));
|
|
|
|
[TestMethod]
|
|
[DataRow("mario.rossi@")]
|
|
[DataRow("@example.it")]
|
|
[DataRow("mario..rossi@example.it")]
|
|
[DataRow("mario@rossi@example.it")]
|
|
[DataRow("mario@localhost")]
|
|
[DataRow("mario rossi@example.it")]
|
|
[DataRow("mario@-example.it")]
|
|
public void BrokenAddresses_AreRefused(string address) => Assert.IsFalse(EmailValidator.IsValid(address));
|
|
}
|