Skip to content

Commit

Permalink
reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RemyDuijkeren committed Jan 14, 2025
1 parent 042130b commit d3a00a0
Show file tree
Hide file tree
Showing 97 changed files with 4,201 additions and 4,070 deletions.
4 changes: 1 addition & 3 deletions src/NodaMoney/Money.UnaryOperators.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Numerics;

namespace NodaMoney;
namespace NodaMoney;

/// <summary>Represents Money, an amount defined in a specific Currency.</summary>
public partial struct Money
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System;
using FluentAssertions;
using Xunit;
using NodaMoney.Tests.Helpers;
using Xunit;

namespace NodaMoney.Tests.CurrencyInfoBuilderSpec;

Expand Down Expand Up @@ -168,88 +168,3 @@ public void WhenSymbolIsEmpty_ThenSymbolMustBeDefaultCurrencySign()
bitcoin.Should().BeEquivalentTo(result);
}
}

[Collection(nameof(NoParallelization))]
public class GivenIWantToUnregisterCurrency
{
[Fact]
public void WhenUnregisterIsoCurrency_ThenThisMustSucceed()
{
var money = Currency.FromCode("PEN"); // should work

CurrencyInfoBuilder.Unregister("PEN");
Action action = () => Currency.FromCode("PEN");

action.Should().Throw<InvalidCurrencyException>().WithMessage("*unknown*currency*");
}

[Fact]
public void WhenUnregisterCustomCurrency_ThenThisMustSucceed()
{
var builder = new CurrencyInfoBuilder("XYZ")
{
EnglishName = "Xyz",
Symbol = "฿",
NumericCode = "123", // iso number
DecimalDigits = 4,
IsIso4217 = false
};

builder.Register();
//Currency xyz = Currency.FromCode("XYZ", "virtual"); // should work
Currency xyz = Currency.FromCode("XYZ"); // should work

CurrencyInfoBuilder.Unregister("XYZ");
//Action action = () => Currency.FromCode("XYZ", "virtual");
Action action = () => Currency.FromCode("XYZ");

action.Should().Throw<InvalidCurrencyException>().WithMessage("*unknown*currency*");
}

[Fact]
public void WhenCurrencyDoesNotExist_ThenThrowException()
{
Action action = () => CurrencyInfoBuilder.Unregister("ABC");

action.Should().Throw<InvalidCurrencyException>().WithMessage("*is unknown currency code!");
}

[Fact]
public void WhenCodeIsNull_ThenThrowException()
{
Action action = () => CurrencyInfoBuilder.Unregister(null);

action.Should().Throw<ArgumentNullException>();
}

[Fact]
public void WhenCodeIsEmpty_ThenThrowException()
{
Action action = () => CurrencyInfoBuilder.Unregister("");

action.Should().Throw<ArgumentNullException>();
}
}

[Collection(nameof(NoParallelization))]
public class GivenIWantToReplaceIsoCurrencyWithOwnVersion
{
[Fact]
public void WhenReplacingEuroWithCustom_ThenThisShouldSucceed()
{
// Panamanian balboa
CurrencyInfo oldEuro = CurrencyInfoBuilder.Unregister("PAB");

var builder = new CurrencyInfoBuilder("PAB");
builder.LoadDataFromCurrencyInfo(oldEuro);
builder.EnglishName = "New Panamanian balboa";
builder.DecimalDigits = 1;

builder.Register();

CurrencyInfo newEuro = CurrencyInfo.FromCode("PAB");
newEuro.Symbol.Should().Be("B/.");
newEuro.EnglishName.Should().Be("New Panamanian balboa");
newEuro.DecimalDigits.Should().Be(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentAssertions;
using Xunit;
using NodaMoney.Tests.Helpers;

namespace NodaMoney.Tests.CurrencyInfoBuilderSpec;

[Collection(nameof(NoParallelization))]
public class GivenIWantToReplaceIsoCurrencyWithOwnVersion
{
[Fact]
public void WhenReplacingEuroWithCustom_ThenThisShouldSucceed()
{
// Panamanian balboa
CurrencyInfo oldEuro = CurrencyInfoBuilder.Unregister("PAB");

var builder = new CurrencyInfoBuilder("PAB");
builder.LoadDataFromCurrencyInfo(oldEuro);
builder.EnglishName = "New Panamanian balboa";
builder.DecimalDigits = 1;

builder.Register();

CurrencyInfo newEuro = CurrencyInfo.FromCode("PAB");
newEuro.Symbol.Should().Be("B/.");
newEuro.EnglishName.Should().Be("New Panamanian balboa");
newEuro.DecimalDigits.Should().Be(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using FluentAssertions;
using NodaMoney.Tests.Helpers;
using Xunit;

namespace NodaMoney.Tests.CurrencyInfoBuilderSpec;

[Collection(nameof(NoParallelization))]
public class GivenIWantToUnregisterCurrency
{
[Fact]
public void WhenUnregisterIsoCurrency_ThenThisMustSucceed()
{
var money = Currency.FromCode("PEN"); // should work

CurrencyInfoBuilder.Unregister("PEN");
Action action = () => Currency.FromCode("PEN");

action.Should().Throw<InvalidCurrencyException>().WithMessage("*unknown*currency*");
}

[Fact]
public void WhenUnregisterCustomCurrency_ThenThisMustSucceed()
{
var builder = new CurrencyInfoBuilder("XYZ")
{
EnglishName = "Xyz",
Symbol = "฿",
NumericCode = "123", // iso number
DecimalDigits = 4,
IsIso4217 = false
};

builder.Register();
//Currency xyz = Currency.FromCode("XYZ", "virtual"); // should work
Currency xyz = Currency.FromCode("XYZ"); // should work

CurrencyInfoBuilder.Unregister("XYZ");
//Action action = () => Currency.FromCode("XYZ", "virtual");
Action action = () => Currency.FromCode("XYZ");

action.Should().Throw<InvalidCurrencyException>().WithMessage("*unknown*currency*");
}

[Fact]
public void WhenCurrencyDoesNotExist_ThenThrowException()
{
Action action = () => CurrencyInfoBuilder.Unregister("ABC");

action.Should().Throw<InvalidCurrencyException>().WithMessage("*is unknown currency code!");
}

[Fact]
public void WhenCodeIsNull_ThenThrowException()
{
Action action = () => CurrencyInfoBuilder.Unregister(null);

action.Should().Throw<ArgumentNullException>();
}

[Fact]
public void WhenCodeIsEmpty_ThenThrowException()
{
Action action = () => CurrencyInfoBuilder.Unregister("");

action.Should().Throw<ArgumentNullException>();
}
}
Loading

0 comments on commit d3a00a0

Please sign in to comment.