diff --git a/BankAccount/BankAccount.nuspec b/BankAccount/BankAccount.nuspec index b13b1f3..1b78c74 100644 --- a/BankAccount/BankAccount.nuspec +++ b/BankAccount/BankAccount.nuspec @@ -2,7 +2,7 @@ $id$ - $version$-alpha0 + $version$-alpha1 $title$ $author$ belidzs @@ -10,7 +10,7 @@ https://github.com/belidzs/MagyarNemzetiBank.BankAccount false $description$ - First alpha release + Second alpha release $copyright$ mnb bank banking bank-account bankaccount giro central-bank hungarian diff --git a/BankAccount/Properties/AssemblyInfo.cs b/BankAccount/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..11f83c9 --- /dev/null +++ b/BankAccount/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MagyarNemzetiBank.Properties")] +[assembly: AssemblyDescription("This library written in pure C# checks the validity of Hungarian bank account numbers and determines which bank they belong to.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Balázs Keresztury")] +[assembly: AssemblyProduct("MagyarNemzetiBank.BankAccount")] +[assembly: AssemblyCopyright("Copyright (c) 2019 Balázs Keresztury")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("46844df6-193c-425b-b616-7e659dee4fb0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BankAccountExample/App.config b/BankAccountExample/App.config new file mode 100644 index 0000000..7eb8d24 --- /dev/null +++ b/BankAccountExample/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/BankAccountExample/BankAccountExample.csproj b/BankAccountExample/BankAccountExample.csproj new file mode 100644 index 0000000..4c4b647 --- /dev/null +++ b/BankAccountExample/BankAccountExample.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {1A4ACA5A-7461-4A21-AC51-E3F784E3CC38} + Exe + MagyarNemzetiBank + MagyarNemzetiBank.BankAccountExample + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {F868E5A1-F07A-4A11-A399-065DA1E192A8} + BankAccount + + + + \ No newline at end of file diff --git a/BankAccountExample/Program.cs b/BankAccountExample/Program.cs new file mode 100644 index 0000000..e019dc8 --- /dev/null +++ b/BankAccountExample/Program.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MagyarNemzetiBank; + +namespace MagyarNemzetiBank.BankAccountExample +{ + class Program + { + static void Main(string[] args) + { + string validAccountNumber = "10032000-01076349"; + var accountValid = new BankAccount(validAccountNumber); + System.Console.WriteLine($"{accountValid.AccountNumber}: IsValid = {accountValid.IsValid}, Bank = {accountValid.Bank}"); + + var accountInvalidNumber = new BankAccount("00000000-00000000-00000001"); + System.Console.WriteLine($"{accountInvalidNumber.AccountNumber}: IsValid = {accountInvalidNumber.IsValid}"); + try + { + System.Console.WriteLine($"Checking bank details for {accountInvalidNumber.AccountNumber}"); + System.Console.WriteLine(accountInvalidNumber.Bank); + } + catch (FormatException) + { + System.Console.WriteLine($"{typeof(FormatException)} was thrown because account number was not valid"); + } + + var accountInvalidBank = new BankAccount("00000000-00000000"); + System.Console.WriteLine($"{accountInvalidBank.AccountNumber}: IsValid = {accountInvalidBank.IsValid} (it's technically valid)"); + try + { + System.Console.WriteLine($"Checking bank details for {accountInvalidBank.AccountNumber}"); + System.Console.WriteLine(accountInvalidBank.Bank); + } + catch (KeyNotFoundException) + { + System.Console.WriteLine($"{typeof(KeyNotFoundException)} was thrown, because the bank account number doesn't belong to any known bank."); + } + System.Console.ReadKey(); + } + } +} diff --git a/BankAccountExample/Properties/AssemblyInfo.cs b/BankAccountExample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ea90229 --- /dev/null +++ b/BankAccountExample/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleApp1")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1a4aca5a-7461-4a21-ac51-e3f784e3cc38")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/README.md b/README.md new file mode 100644 index 0000000..7d0c5b4 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# MagyarNemzetiBank.BankAccount +This library written in pure C# checks the validity of a Hungarian bank account number and determines which bank is belongs to. + +## Usage +Let's check a valid bank account: + +```csharp +string validAccountNumber = "10032000-01076349"; +var accountValid = new BankAccount(validAccountNumber); +System.Console.WriteLine($"{accountValid.AccountNumber}: IsValid = {accountValid.IsValid}, Bank = {accountValid.Bank}"); +``` + +An invalid bank account will return `IsValid = false` and throws `FormatException` when `Bank` property is read: + +```csharp +var accountInvalidNumber = new BankAccount("00000000-00000000-00000001"); +System.Console.WriteLine($"{accountInvalidNumber.AccountNumber}: IsValid = {accountInvalidNumber.IsValid}"); +try +{ + System.Console.WriteLine($"Checking bank details for {accountInvalidNumber.AccountNumber}"); + System.Console.WriteLine(accountInvalidNumber.Bank); +} +catch (FormatException) +{ + System.Console.WriteLine($"{typeof(FormatException)} was thrown because account number was not valid"); +} +``` + +When the syntax of the bank account number is correct, but it doesn't belong to any known bank `KeyNotFoundException` is thrown: + +```csharp +var accountInvalidBank = new BankAccount("00000000-00000000"); +System.Console.WriteLine($"{accountInvalidBank.AccountNumber}: IsValid = {accountInvalidBank.IsValid} (it's technically valid)"); +try +{ + System.Console.WriteLine($"Checking bank details for {accountInvalidBank.AccountNumber}"); + System.Console.WriteLine(accountInvalidBank.Bank); +} +catch (KeyNotFoundException) +{ + System.Console.WriteLine($"{typeof(KeyNotFoundException)} was thrown, because the bank account number doesn't belong to any known bank."); +} +``` + +Alternatively you can use the static `BankAccount.Validate(string accountNumber)` method to check if the number is syntactically correct. + +## Download from Nuget +[!['nuget badge'](https://img.shields.io/nuget/v/MagyarNemzetiBank.BankAccount.svg)](https://www.nuget.org/packages/MagyarNemzetiBank.BankAccount/)