Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
belidzs committed Feb 14, 2020
2 parents a5a7c7e + 17ec590 commit 0f47dd7
Show file tree
Hide file tree
Showing 20 changed files with 299 additions and 324 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[*.cs]

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none

# SA1309: Field names should not begin with underscore
dotnet_diagnostic.SA1309.severity = none

# SA1623: Property summary documentation should match accessors
dotnet_diagnostic.SA1623.severity = none

# SA1642: Constructor summary documentation should begin with standard text
dotnet_diagnostic.SA1642.severity = none
71 changes: 40 additions & 31 deletions BankAccount/BankAccount.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
using System;
// <copyright file="BankAccount.cs" company="Balázs Keresztury">
// Copyright (c) Balázs Keresztury. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;

namespace MagyarNemzetiBank
{
/// <summary>
/// Represents a single Hungarian Bank Account.
/// </summary>
public class BankAccount
{
/// <summary>
/// Bank Account Number in the format of 00000000-00000000 or 00000000-00000000-00000000 with or without the hyphens
/// </summary>
public string AccountNumber { get; set; }
/// <summary>
/// Tells whether the bank account's account number is valid
/// </summary>
public bool IsValid => BankAccountValidator.Validate(AccountNumber);
/// <summary>
/// Name of the bank the BankAccount belongs to
/// </summary>
public string Bank
{
get
{
if (IsValid)
{
return _giroBankDictionary[Convert.ToInt32(AccountNumber.Substring(0, 3))];
}
else
{
throw new FormatException("Invalid Bank Account");
}
}
}

// https://www.mnb.hu/letoltes/hitelintezetek-azonosito-adatai.pdf
private readonly Dictionary<int, string> _giroBankDictionary = new Dictionary<int, string>()
{
Expand Down Expand Up @@ -65,7 +46,7 @@ public string Bank
{ 109, "UniCredit Bank Hungary Zrt." },
{ 171, "UniCredit Jelzálogbank Zrt." },
{ 147, "IC Bank Zrt." },
{ 111, "Inter-Európa Bank Zrt."},
{ 111, "Inter-Európa Bank Zrt." },
{ 137, "ING Bank (Magyarország) Zrt." },
{ 104, "Kereskedelmi és Hitelbank Zrt." },
{ 144, "Központi Elszámolóház és Értéktár Zrt. (KELER)" },
Expand Down Expand Up @@ -97,16 +78,44 @@ public string Bank
{ 700, "Tiszaföldvár és Vidéke Takarékszövetkezet, Tiszaföldvár" },
{ 803, "Tiszántúli Első Hitelszövetkezet" },
{ 659, "Turai Takarékszövetkezet, Tura" },
{ 121, "Westdeutche Landesbank (Hungária) Zrt." }
{ 121, "Westdeutche Landesbank (Hungária) Zrt." },
};

/// <summary>
/// Bank Account
/// Initializes a new instance of the <see cref="BankAccount"/> class.
/// </summary>
/// <param name="accountNumber">Bank Account Number in the format of 00000000-00000000 or 00000000-00000000-00000000 with or without the hyphens</param>
/// <param name="accountNumber">Bank Account Number in the format of 00000000-00000000 or 00000000-00000000-00000000 with or without the hyphens.</param>
public BankAccount(string accountNumber)
{
AccountNumber = accountNumber;
}

/// <summary>
/// Bank Account Number in the format of 00000000-00000000 or 00000000-00000000-00000000 with or without the hyphens.
/// </summary>
public string AccountNumber { get; set; }

/// <summary>
/// Tells whether the bank account's account number is valid.
/// </summary>
public bool IsValid => BankAccountValidator.Validate(AccountNumber);

/// <summary>
/// Name of the bank the BankAccount belongs to.
/// </summary>
public string Bank
{
get
{
if (IsValid)
{
return _giroBankDictionary[Convert.ToInt32(AccountNumber.Substring(0, 3))];
}
else
{
throw new FormatException("Invalid Bank Account");
}
}
}
}
}
29 changes: 20 additions & 9 deletions BankAccount/BankAccount.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFrameworks>netstandard1.0;netstandard2.0</TargetFrameworks>
<RootNamespace>MagyarNemzetiBank</RootNamespace>
<AssemblyName>MagyarNemzetiBank.BankAccount</AssemblyName>
<Description>This library written in pure C# checks the validity of Hungarian bank account numbers and determines which bank they belong to</Description>
<Company>Balázs Keresztury</Company>
<Copyright>Copyright (c) 2019 Balázs Keresztury</Copyright>
<Product>MagyarNemzetiBank.BankAccount</Product>
<AssemblyVersion>1.0.0</AssemblyVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/belidzs/MagyarNemzetiBank.BankAccount</PackageProjectUrl>
<RepositoryUrl>https://github.com/belidzs/MagyarNemzetiBank.BankAccount</RepositoryUrl>
<PackageTags>mnb bank banking bank-account bankaccount giro central-bank hungarian</PackageTags>
<Authors>Balázs Keresztury</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.1</Version>
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="&quot;C:\Program Files (x86)\NuGet\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Prop Configuration=$(ConfigurationName)" />
</Target>
<ItemGroup>
<None Remove="stylecop.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
17 changes: 0 additions & 17 deletions BankAccount/BankAccount.nuspec

This file was deleted.

34 changes: 23 additions & 11 deletions BankAccount/BankAccountValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/*
// <copyright file="BankAccountValidator.cs" company="Balázs Keresztury">
// Copyright (c) Balázs Keresztury. All rights reserved.
// </copyright>

/*
* 18/2009. (VIII. 6.) MNB rendelet a pénzforgalom lebonyolításáról
* http://net.jogtar.hu/jr/gen/hjegy_doc.cgi?docid=A0900018.MNB&celpara=#xcelparam
*
Expand All @@ -16,29 +20,35 @@
namespace MagyarNemzetiBank
{
/// <summary>
/// Static class to validate Hungarian bank account numbers
/// Static class to validate Hungarian bank account numbers.
/// </summary>
public static class BankAccountValidator
{
private const string RegexGiro = "^[0-9]{8}-?[0-9]{8}(-?[0-9]{8})?$";

// ellenőrzőalgoritmusban meghatározott szorzók
private static readonly int[] Multipliers = { 9, 7, 3, 1 };
private const string RegexGiro = "^[0-9]{8}-?[0-9]{8}(-?[0-9]{8})?$";

/// <summary>
/// Checks if the given bank account number conforms to the Hungarian bank account number format and performs a parity check
/// Checks if the given bank account number conforms to the Hungarian bank account number format and performs a parity check.
/// </summary>
/// <param name="accountNumber">Bank account number with or without hyphens</param>
/// <returns>True if the account number is valid</returns>
/// <param name="accountNumber">Bank account number with or without hyphens.</param>
/// <returns>True if the account number is valid.</returns>
public static bool Validate(string accountNumber)
{
if (accountNumber == null || accountNumber.Equals("")) return true;
//megfelelés regex formátumnak
if (accountNumber == null || accountNumber.Equals(string.Empty))
{
return true;
}

// megfelelés regex formátumnak
Regex regexGiro = new Regex(RegexGiro);
if (regexGiro.IsMatch(accountNumber))
{
// ha megfelel a regexnek
// kötőjelek eltávolítása
accountNumber = accountNumber.Replace("-", "");
accountNumber = accountNumber.Replace("-", string.Empty);

// első nyolc blokk és a maradék ellenőrzése, külön
return ValidateBlock(accountNumber.Substring(0, 8)) && ValidateBlock(accountNumber.Substring(8));
}
Expand All @@ -55,13 +65,15 @@ private static bool ValidateBlock(string accountNumberBlock)
for (int j = 0; j < accountNumberBlock.Length - 1; j++)
{
// szorzatösszeg kalkulálása
result += Int32.Parse(accountNumberBlock[j].ToString()) * Multipliers[j % 4];
result += int.Parse(accountNumberBlock[j].ToString()) * Multipliers[j % 4];
}
if ((10 - result % 10) % 10 != Int32.Parse(accountNumberBlock[accountNumberBlock.Length - 1].ToString()))

if ((10 - (result % 10)) % 10 != int.Parse(accountNumberBlock[accountNumberBlock.Length - 1].ToString()))
{
// a szorzatösszeg modulo 10 értékét 10-ből kivonva az utolsó számjegyet kell kapni. Ha ez 10, akkor 0-t
return false;
}

return true;
}
}
Expand Down
33 changes: 0 additions & 33 deletions BankAccount/Properties/AssemblyInfo.cs

This file was deleted.

17 changes: 17 additions & 0 deletions BankAccount/stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// ACTION REQUIRED: This file was automatically added to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md

"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "Balázs Keresztury",
},
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace"
}
}
}
6 changes: 0 additions & 6 deletions BankAccountExample/App.config

This file was deleted.

58 changes: 0 additions & 58 deletions BankAccountExample/BankAccountExample.csproj

This file was deleted.

Loading

0 comments on commit 0f47dd7

Please sign in to comment.