Skip to content

Commit

Permalink
Dsidirop/tasks/iban 00019 add support for exotic countries (#20)
Browse files Browse the repository at this point in the history
* feat (IBAN-00019-add-support-for-exotic-countries): enrich IBAN tests to test against the exotic countries

    b = National bank code
    s = Branch code
    c = Account number

    Central African Republic	27	23n	      		CFkk nnnn nnnn nnnn nnnn nnnn nnn             [CF 42 20001000010120069700160]
    Chad	                    27	23n	      		TDkk nnnn nnnn nnnn nnnn nnnn nnn             [TD 89 60002000010271091600153]
    Comoros	                    27	23n	      		KMkk nnnn nnnn nnnn nnnn nnnn nnn             [KM 46 00005000010010904400137]
    Congo, Republic of the	    27	23n	      		CGkk nnnn nnnn nnnn nnnn nnnn nnn             [CG 39 30011000101013451300019]
    Côte d'Ivoire	            28	1a, 23n	  		CIkk annn nnnn nnnn nnnn nnnn nnnn            [CI 77 A 12312341234123412341234]
    Djibouti	                27	23n	      		DJkk nnnn nnnn nnnn nnnn nnnn nnn             [DJ 21 10002010010409943020008]
    Equatorial Guinea	        27	23n	      		GQkk nnnn nnnn nnnn nnnn nnnn nnn             [GQ 70 50002001003715228190196]
    Gabon	                    27	23n	      		GAkk nnnn nnnn nnnn nnnn nnnn nnn             [GA 21 40021010032001890020126]
    Guinea-Bissau	            25	2c, 19n	  		GWkk ccnn nnnn nnnn nnnn nnnn n               [GW 04 GW1430010181800637601]
    Honduras	                28	4a, 20n	  		HNkk aaaa nnnn nnnn nnnn nnnn nnnn            [HN 54 PISA00000000000000123124]
    Morocco	                    28	24n	      		MAkk nnnn nnnn nnnn nnnn nnnn nnnn            [MA 64 011519000001205000534921]
    Nicaragua	                32	4a, 24n	  		NIkk aaaa nnnn nnnn nnnn nnnn nnnn nnnn       [NI 92 BAMC000000000000000003123123]
    Niger	                    28	2a, 22n	  		NEkk aann nnnn nnnn nnnn nnnn nnnn            [NE 58 NE0380100100130305000268]
    Togo	                    28	2a, 22n	  		TGkk aann nnnn nnnn nnnn nnnn nnnn            [TG 53 TG0090604310346500400070]
    Libya	                    25	21n	            LYkk bbbs sscc cccc cccc cccc c               [LY 83 002048000020100120361]

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Central African Republic" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Chad" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Comoros" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Congo" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Cote Divoire" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Djibouti" / "Equatorial Guinea" / "Gabon" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Honduras" / "Guinea Bissau" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Morocco" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Nicaragua" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Niger" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Libya" IBANs

* feat (IBAN-00019-add-support-for-exotic-countries): add support for "Honduras" IBANs

Co-authored-by: Kyriakos Sidiropoulos <[email protected]>
Co-authored-by: Venca Beca <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2022
1 parent 62f21bc commit 7d36881
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 5 deletions.
216 changes: 212 additions & 4 deletions SinKien.IBAN4Net.NetStandard.Tests/IbanExamplesTest.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,230 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SinKien.IBAN4Net.NetStandard.Tests.Net45
{
[TestClass]
public class IbanExamplesTest
{

[TestMethod]
public void AllSampleValidIBANsShouldWork()
{
var IBANs = System.IO.File.ReadAllLines(System.IO.Path.Combine("SampleData", "SampleValidIBANs.txt"));
foreach (var iban in IBANs)
{
IbanUtils.IsValid(iban, out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION, $"{iban}: {result.ToString()}");
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION, $"{iban}: {result}");
}
}

[TestMethod]
public void CentralAfricanRepublic_ValidIbanShouldPass()
{
IbanUtils.IsValid("CF4220001000010120069700160", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void CentralAfricanRepublic_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("CF0220001000010120069700160", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Chad_ValidIbanShouldPass()
{
IbanUtils.IsValid("TD8960002000010271091600153", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Chad_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("TD0260002000010271091600153", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Comoros_ValidIbanShouldPass()
{
IbanUtils.IsValid("KM4600005000010010904400137", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Comoros_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("KM4000005000010010904400137", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Congo_ValidIbanShouldPass()
{
IbanUtils.IsValid("CG3930011000101013451300019", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Congo_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("CG0930011000101013451300019", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void CoteDivoire_ValidIbanShouldPass()
{
IbanUtils.IsValid("CI77A12312341234123412341234", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void CoteDivoire_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("CI97A12312341234123412341234", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Djibouti_ValidIbanShouldPass()
{
IbanUtils.IsValid("DJ2110002010010409943020008", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Djibouti_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("DJ0110002010010409943020008", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void EquatorialGuinea_ValidIbanShouldPass()
{
IbanUtils.IsValid("GQ7050002001003715228190196", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void EquatorialGuinea_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("GQ7350002001003715228190196", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Gabon_ValidIbanShouldPass()
{
IbanUtils.IsValid("GA2140021010032001890020126", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Gabon_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("GA1140021010032001890020126", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void GuineaBissau_ValidIbanShouldPass()
{
IbanUtils.IsValid("GW04GW1430010181800637601", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void GuineaBissau_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("GW01GW1430010181800637601", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Honduras_ValidIbanShouldPass()
{
IbanUtils.IsValid("HN54PISA00000000000000123124", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Honduras_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("HN34PISA00000000000000123124", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Morocco_ValidIbanShouldPass()
{
IbanUtils.IsValid("MA64181815211118602202000107", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Morocco_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("MA04181815211118602202000107", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Nicaragua_ValidIbanShouldPass()
{
IbanUtils.IsValid("NI92BAMC000000000000000003123123", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Nicaragua_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("NI12BAMC000000000000000003123123", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Niger_ValidIbanShouldPass()
{
IbanUtils.IsValid("NE58NE0380100100130305000268", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Niger_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("NE28NE0380100100130305000268", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Togo_ValidIbanShouldPass()
{
IbanUtils.IsValid("TG53TG0090604310346500400070", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Togo_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("TG33TG0090604310346500400070", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Libya_ValidIbanShouldPass()
{
IbanUtils.IsValid("LY83002048000020100120361", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.NO_VIOLATION);
}

[TestMethod]
public void Libya_InvalidCheckDigitShouldFailValidation()
{
IbanUtils.IsValid("LY33002048000020100120361", out IbanFormatViolation result);
Assert.IsTrue(result == IbanFormatViolation.IBAN_INVALID_CHECK_DIGIT_VALUE);
}

[TestMethod]
public void Belarus_ValidIbanShouldPass()
Expand Down
15 changes: 15 additions & 0 deletions SinKien.IBAN4Net.NetStandard.Tests/SampleData/SampleValidIBANs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,18 @@ CV05123412341234123412341
ML75A12312341234123412341234
MZ97123412341234123412341
SN15A12312341234123412341234
CF4220001000010120069700160
TD8960002000010271091600153
KM4600005000010010904400137
CG3930011000101013451300019
CI77A12312341234123412341234
DJ2110002010010409943020008
GQ7050002001003715228190196
GA2140021010032001890020126
GW04GW1430010181800637601
HN54PISA00000000000000123124
MA64011519000001205000534921
NI92BAMC000000000000000003123123
NE58NE0380100100130305000268
TG53TG0090604310346500400070
LY83002048000020100120361
2 changes: 1 addition & 1 deletion SinKien.IBAN4Net.NetStandard/Bban.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* IBAN4Net
* Copyright 2020 Vaclav Beca [sinkien]
*
Expand Down

0 comments on commit 7d36881

Please sign in to comment.