Skip to content

Commit

Permalink
Added feature per PR #13.
Browse files Browse the repository at this point in the history
Some cleaning and SourceLink support.
  • Loading branch information
sinkien committed Oct 24, 2020
1 parent 64b2696 commit f81817f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
9 changes: 9 additions & 0 deletions SinKien.IBAN4Net.NetStandard.Tests/CountryCodeTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SinKien.IBAN4Net.NetStandard.Tests.Net45
Expand Down Expand Up @@ -114,5 +116,12 @@ public void GetCountryTwoDifferentObjectsShouldHaveDifferentHashcode()

Assert.AreNotEqual(entry1.GetHashCode(), entry2.GetHashCode());
}

[TestMethod]
public void GetCountryCodesShouldReturnAllOfThem()
{
IEnumerable<CountryCodeEntry> entries = CountryCode.GetCountryCodes();
Assert.AreEqual(251, entries.Count());
}
}
}
8 changes: 7 additions & 1 deletion SinKien.IBAN4Net.NetStandard/CountryCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ static CountryCode()
/// </summary>
private static SortedDictionary<string, CountryCodeEntry> _alpha3Map = new SortedDictionary<string, CountryCodeEntry>();



/// <summary>
/// Returns all defined country codes as IEnumerable
/// </summary>
/// <returns>IEnumerable of country codes</returns>
public static IEnumerable<CountryCodeEntry> GetCountryCodes() => _alpha3Map.Values.AsEnumerable();

/// <summary>
/// Gets CountryCode object from map
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions SinKien.IBAN4Net.NetStandard/IbanUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace SinKien.IBAN4Net
/// IBAN Utilities
/// </summary>
public class IbanUtils
{
{
private static char[] _letters = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

/// <summary>
/// Validation of IBAN string
/// </summary>
Expand Down Expand Up @@ -582,15 +584,15 @@ private static bool hasValidBbanEntryCharacterType(BBanEntry entry, string entry
return (validationResult == IbanFormatViolation.NO_VIOLATION);
}

private static char[] letters = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

private static int calculateMod(string iban)
{
string reformattedIban = GetBBan(iban) + GetCountryCodeAndCheckDigit(iban);
double total = 0;

for (int i = 0; i < reformattedIban.Length; i++)
{
double numericValue = char.IsLetter(reformattedIban[i]) ? (10 + Array.IndexOf(letters, reformattedIban[i])) : char.GetNumericValue(reformattedIban[i]);
double numericValue = char.IsLetter(reformattedIban[i]) ? (10 + Array.IndexOf(_letters, reformattedIban[i])) : char.GetNumericValue(reformattedIban[i]);
if (numericValue < 0 || numericValue > 35)
{
throw new IbanFormatException($"Invalid character on position {i} = {numericValue}", IbanFormatViolation.IBAN_VALID_CHARACTERS, reformattedIban[i]);
Expand Down
16 changes: 14 additions & 2 deletions SinKien.IBAN4Net.NetStandard/SinKien.IBAN4Net.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@
<TargetFrameworks>net45;netstandard1.2;netstandard1.4;netstandard2.0</TargetFrameworks>
<RootNamespace>SinKien.IBAN4Net</RootNamespace>
<AssemblyName>SinKien.IBAN4Net</AssemblyName>
<Version>2.0.2</Version>
<Version>2.0.3</Version>
<Authors>Vaclav Beca</Authors>
<Description>IBAN4Net is a .NET Standard compliant (1.2, 1.4, 2.0) library for generation and validation of the International Bank Account Numbers (IBAN) and Business Identifier Codes (BIC).</Description>
<PackageProjectUrl>https://github.com/sinkien/IBAN4Net</PackageProjectUrl>
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<Copyright>Copyright 2020 Vaclav Beca [sinkien]</Copyright>
<PackageTags>iban, bic, iban4net</PackageTags>
<RepositoryType>github</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/sinkien/IBAN4Net</RepositoryUrl>
<PackageReleaseNotes></PackageReleaseNotes>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<FileVersion>2.0.3.0</FileVersion>
<PackageLicenseFile></PackageLicenseFile>
<PackageId>IBAN4Net</PackageId>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>

0 comments on commit f81817f

Please sign in to comment.