Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Feature/currency code #46

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Nox.Types.EntityFramework/CurrencyCode3Converter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Nox.Types.EntityFramework;

/// <summary>
/// Class for three-letters currency code (ISO 4217).
/// </summary>
public class CurrencyCode3Converter : ValueConverter<CurrencyCode3, string>
{
/// <summary>
/// Initializes a new instance of the <see cref="CurrencyCode3Converter" /> class.
/// </summary>
public CurrencyCode3Converter() : base(currencyCode3 => currencyCode3.Value, currencyCode3 => CurrencyCode3.From(currencyCode3)) { }
rochar marked this conversation as resolved.
Show resolved Hide resolved
}

28 changes: 28 additions & 0 deletions src/Nox.Types/Types/CurrencyCode3/CurrencyCode3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Linq;

namespace Nox.Types;

/// <summary>
/// Class for three-letters currency code (ISO 4217).
/// </summary>
public sealed class CurrencyCode3 : ValueObject<string, CurrencyCode3>
{
private readonly string[] CurrencyCodes = Enum.GetNames(typeof(CurrencyCode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this as a private readonly static variable? Also, can we rename it using the following convention https://regusit.atlassian.net/wiki/spaces/NOX/pages/3153461266/Coding+Conventions+Styles+and+Guidelines#Private-static-fields ?


/// <summary>
/// Validates the <see cref="CurrencyCode3"/> object.
/// </summary>
/// <returns>A validation result indicating whether the <see cref="CurrencyCode3"/> object is valid or not.</returns>
internal override ValidationResult Validate()
{
var result = base.Validate();

if (!CurrencyCodes.Contains(Value))
{
result.Errors.Add(new ValidationFailure(nameof(Value), $"Could not create a Nox CurrencyCode3 type with unsupported value '{Value}'."));
}

return result;
}
}
181 changes: 181 additions & 0 deletions tests/Nox.Types.Tests/NoxCurrencyCode3Tests.cs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove Nox from the class Name

Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
namespace Nox.Types.Tests;
public class NoxCurrencyCode3Tests
{
[InlineData("AED")]
rochar marked this conversation as resolved.
Show resolved Hide resolved
[InlineData("AFN")]
[InlineData("ALL")]
[InlineData("AMD")]
[InlineData("ANG")]
[InlineData("AOA")]
[InlineData("ARS")]
[InlineData("AUD")]
[InlineData("AWG")]
[InlineData("AZN")]
[InlineData("BAM")]
[InlineData("BBD")]
[InlineData("BDT")]
[InlineData("BGN")]
[InlineData("BHD")]
[InlineData("BIF")]
[InlineData("BMD")]
[InlineData("BND")]
[InlineData("BOB")]
[InlineData("BRL")]
[InlineData("BSD")]
[InlineData("BTC")]
[InlineData("BTN")]
[InlineData("BWP")]
[InlineData("BYR")]
[InlineData("BYN")]
[InlineData("BZD")]
[InlineData("CAD")]
[InlineData("CDF")]
[InlineData("CHF")]
[InlineData("CLP")]
[InlineData("CNY")]
[InlineData("COP")]
[InlineData("CRC")]
[InlineData("CUC")]
[InlineData("CUP")]
[InlineData("CVE")]
[InlineData("CZK")]
[InlineData("DJF")]
[InlineData("DKK")]
[InlineData("DOP")]
[InlineData("DZD")]
[InlineData("EGP")]
[InlineData("ERN")]
[InlineData("ETB")]
[InlineData("EUR")]
[InlineData("FJD")]
[InlineData("FKP")]
[InlineData("GBP")]
[InlineData("GEL")]
[InlineData("GHS")]
[InlineData("GIP")]
[InlineData("GMD")]
[InlineData("GNF")]
[InlineData("GTQ")]
[InlineData("GYD")]
[InlineData("HKD")]
[InlineData("HNL")]
[InlineData("HRK")]
[InlineData("HTG")]
[InlineData("HUF")]
[InlineData("IDR")]
[InlineData("ILS")]
[InlineData("INR")]
[InlineData("IQD")]
[InlineData("IRR")]
[InlineData("ISK")]
[InlineData("JMD")]
[InlineData("JOD")]
[InlineData("JPY")]
[InlineData("KES")]
[InlineData("KGS")]
[InlineData("KHR")]
[InlineData("KMF")]
[InlineData("KPW")]
[InlineData("KRW")]
[InlineData("KWD")]
[InlineData("KYD")]
[InlineData("KZT")]
[InlineData("LAK")]
[InlineData("LBP")]
[InlineData("LKR")]
[InlineData("LRD")]
[InlineData("LSL")]
[InlineData("LYD")]
[InlineData("MAD")]
[InlineData("MDL")]
[InlineData("MGA")]
[InlineData("MKD")]
[InlineData("MMK")]
[InlineData("MNT")]
[InlineData("MOP")]
[InlineData("MRO")]
[InlineData("MTL")]
[InlineData("MUR")]
[InlineData("MVR")]
[InlineData("MWK")]
[InlineData("MXN")]
[InlineData("MYR")]
[InlineData("MZN")]
[InlineData("NAD")]
[InlineData("NGN")]
[InlineData("NIO")]
[InlineData("NOK")]
[InlineData("NPR")]
[InlineData("NZD")]
[InlineData("OMR")]
[InlineData("PAB")]
[InlineData("PEN")]
[InlineData("PGK")]
[InlineData("PHP")]
[InlineData("PKR")]
[InlineData("PLN")]
[InlineData("PYG")]
[InlineData("QAR")]
[InlineData("RON")]
[InlineData("RSD")]
[InlineData("RUB")]
[InlineData("RWF")]
[InlineData("SAR")]
[InlineData("SBD")]
[InlineData("SCR")]
[InlineData("SDD")]
[InlineData("SDG")]
[InlineData("SEK")]
[InlineData("SGD")]
[InlineData("SHP")]
[InlineData("SLL")]
[InlineData("SOS")]
[InlineData("SRD")]
[InlineData("STD")]
[Theory]
public void Nox_CurrencyCode3_Constructor_ReturnsSameValue_AllCurrencies(string currencyCode3String)
rochar marked this conversation as resolved.
Show resolved Hide resolved
{
var currencyCode3 = CurrencyCode3.From(currencyCode3String);

Assert.Equal(currencyCode3String, currencyCode3.Value);
}

[Fact]
public void Nox_CurrencyCode3_Constructor_WithUnsupportedCurrencyCode3_ThrowsValidationException()
{
var exception = Assert.Throws<TypeValidationException>(() => _ =
CurrencyCode3.From("ABC")
);

Assert.Equal("Could not create a Nox CurrencyCode3 type with unsupported value 'ABC'.", exception.Errors.First().ErrorMessage);
}

[Fact]
public void Nox_CurrencyCode3_Equality_Tests()
{
var currencyCode3_1 = CurrencyCode3.From("USD");

var currencyCode3_2 = CurrencyCode3.From("USD");

Assert.Equal(currencyCode3_1, currencyCode3_2);
}

[Fact]
public void Nox_CurrencyCode3_NotEqual_Tests()
{
var currencyCode3_1 = CurrencyCode3.From("RWF");

var currencyCode3_2 = CurrencyCode3.From("SHP");

Assert.NotEqual(currencyCode3_1, currencyCode3_2);
}

[Fact]
public void Nox_CurrencyCode3_ToString_ReturnsString()
{
var currencyCode3 = CurrencyCode3.From("USD");

Assert.Equal("USD", currencyCode3.ToString());
}
}