From 4f8d91847c0285cc2bcb3e20c54fa153f1a13778 Mon Sep 17 00:00:00 2001 From: Martijn Bodeman <11424653+skwasjer@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:55:21 +0100 Subject: [PATCH] fix(registry): patch Finland bank code to 6 digits (#257) --- .../Swift/Patches/9_FinlandBankCodePatch.cs | 21 +++++++++++++++++++ .../Swift/Patches/RecordPatcher.cs | 1 + .../Registry/Swift/SwiftRegistryProvider.cs | 8 +++---- .../Issues/224_FinlandBankCode.cs | 21 +++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/IbanNet.CodeGen/Swift/Patches/9_FinlandBankCodePatch.cs create mode 100644 test/IbanNet.Tests/Issues/224_FinlandBankCode.cs diff --git a/src/IbanNet.CodeGen/Swift/Patches/9_FinlandBankCodePatch.cs b/src/IbanNet.CodeGen/Swift/Patches/9_FinlandBankCodePatch.cs new file mode 100644 index 00000000..c347c9a6 --- /dev/null +++ b/src/IbanNet.CodeGen/Swift/Patches/9_FinlandBankCodePatch.cs @@ -0,0 +1,21 @@ +namespace IbanNet.CodeGen.Swift.Patches; + +internal sealed class _9_FinlandBankCodePatch : RecordPatcher +{ + protected override SwiftCsvRecord Apply(SwiftCsvRecord record) + { + switch (record) + { + case { CountryCode: "FI" }: + record.Bban.Pattern = "6!n8!n"; + record.Bban.Example = "12345600000785"; + record.Bank.Pattern = "6!n"; + record.Bank.Example = "123456"; + + return record; + + default: + return record; + } + } +} diff --git a/src/IbanNet.CodeGen/Swift/Patches/RecordPatcher.cs b/src/IbanNet.CodeGen/Swift/Patches/RecordPatcher.cs index 91a4cd19..03b0224c 100644 --- a/src/IbanNet.CodeGen/Swift/Patches/RecordPatcher.cs +++ b/src/IbanNet.CodeGen/Swift/Patches/RecordPatcher.cs @@ -19,6 +19,7 @@ private static IEnumerable GetPatches() .Where(t => !t.IsAbstract && typeof(RecordPatcher).IsAssignableFrom(t)) .Select(Activator.CreateInstance) .Cast() + .OrderBy(rp => rp.GetType().Name) .ToList(); } } diff --git a/src/IbanNet/Registry/Swift/SwiftRegistryProvider.cs b/src/IbanNet/Registry/Swift/SwiftRegistryProvider.cs index d23099ba..a5c9ec2e 100644 --- a/src/IbanNet/Registry/Swift/SwiftRegistryProvider.cs +++ b/src/IbanNet/Registry/Swift/SwiftRegistryProvider.cs @@ -692,13 +692,13 @@ private static IEnumerable Load() Example = "FI2112345600000785", EffectiveDate = new DateTimeOffset(2011, 12, 1, 0, 0, 0, TimeSpan.Zero) }, - Bban = new BbanStructure(new SwiftPattern("3!n11!n"), 4) + Bban = new BbanStructure(new SwiftPattern("6!n8!n"), 4) { - Example = "" + Example = "12345600000785" }, - Bank = new BankStructure(new SwiftPattern("3!n"), 4) + Bank = new BankStructure(new SwiftPattern("6!n"), 4) { - Example = "123" + Example = "123456" }, Sepa = new SepaInfo { diff --git a/test/IbanNet.Tests/Issues/224_FinlandBankCode.cs b/test/IbanNet.Tests/Issues/224_FinlandBankCode.cs new file mode 100644 index 00000000..9bfd5168 --- /dev/null +++ b/test/IbanNet.Tests/Issues/224_FinlandBankCode.cs @@ -0,0 +1,21 @@ +using IbanNet.Registry; + +namespace IbanNet.Issues; + +public sealed class _224_FinlandBankCode +{ + [Theory] + [InlineData("FI4017453000182859", "174530")] + [InlineData("FI2840554920113105", "405549")] + public void When_extracting_bank_code_it_should_return_expected(string ibanStr, string expectedBankCode) + { + var ibanParser = new IbanParser(IbanRegistry.Default); + + // Act + bool isValid = ibanParser.TryParse(ibanStr, out Iban? iban); + + // Assert + isValid.Should().BeTrue(); + iban!.BankIdentifier.Should().Be(expectedBankCode); + } +}