-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4445b16
commit 821ed8d
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
Tests/Singulink.Globalization.Currency.Tests/SortedMoneySetTests/SubtractTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Shouldly; | ||
|
||
namespace Singulink.Globalization.Tests.SortedMoneySetTests; | ||
|
||
[TestClass] | ||
public class SubtractTests | ||
{ | ||
private static readonly Money Usd100 = new(100m, "USD"); | ||
private static readonly Money Cad50 = new(50m, "CAD"); | ||
private static readonly Money Eur25 = new(25m, "EUR"); | ||
private static readonly Money Aud75 = new(75m, "AUD"); | ||
private static readonly ImmutableSortedMoneySet ImmutableSet = [Usd100, Cad50, Eur25]; | ||
|
||
private readonly SortedMoneySet _set = ImmutableSet.ToSet(); | ||
|
||
// public void Subtract(Money value) tests | ||
|
||
[TestMethod] | ||
public void Money_CurrencyExists_SubtractsPositiveAmountAndReturnsPositiveAmount() | ||
{ | ||
_set.Subtract(Usd100); | ||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([new(0m, "USD"), Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void MoneyCurrencyExists_SubtractsZeroAmountAndReturnsPositiveAmount() | ||
{ | ||
_set.Subtract(new(-0m, "EUR")); | ||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([Usd100, Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void MoneyCurrencyNotInSet_AddsValueToSet() | ||
{ | ||
_set.Subtract(-Aud75); | ||
_set.ShouldBe([Usd100, Cad50, Eur25, Aud75]); | ||
} | ||
|
||
[TestMethod] | ||
public void MoneyCurrencyDisallowed_ThrowsArgumentException() | ||
{ | ||
var value = new Money(100, new Currency("Blah blah blah", "BBB", "$$", 2)); | ||
|
||
Should.Throw<ArgumentException>(() => _set.Subtract(value)) | ||
.Message.ShouldBe($"The currency '{value.Currency}' is not present in the set's currency registry. (Parameter 'value')"); | ||
|
||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([Usd100, Cad50, Eur25]); | ||
} | ||
|
||
// public void Subtract(decimal amount, string currencyCode) tests | ||
|
||
[TestMethod] | ||
public void CurrencyCodeExists_SubtractsPositiveAmountAndReturnsPositiveAmount() | ||
{ | ||
_set.Subtract(100m, "USD"); | ||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([new(0m, "USD"), Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void CurrencyCodeExists_SubtractsZeroAmountAndReturnsPositiveAmount() | ||
{ | ||
_set.Subtract(-0m, "EUR"); | ||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([Usd100, Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void CurrencyCodeNotInSet_AddsValueToSet() | ||
{ | ||
_set.Subtract(-75m, "AUD"); | ||
_set.ShouldBe([Usd100, Cad50, Eur25, Aud75]); | ||
} | ||
|
||
[TestMethod] | ||
public void CurrencyCodeDisallowed_ThrowsArgumentException() | ||
{ | ||
Should.Throw<ArgumentException>(() => _set.Subtract(100m, "Blah blah blah")) | ||
.Message.ShouldBe("Currency code 'Blah blah blah' not found in the 'System' registry. (Parameter 'currencyCode')"); | ||
|
||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([Usd100, Cad50, Eur25]); | ||
} | ||
|
||
// public void Subtract(decimal amount, Currency currency) tests | ||
|
||
[TestMethod] | ||
public void CurrencyExists_SubtractsPositiveAmountAndReturnsPositiveAmount() | ||
{ | ||
_set.Subtract(-100m, Currency.Get("USD")); | ||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([new(0m, "USD"), Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void CurrencyExists_SubtractsZeroAmountAndReturnsPositiveAmount() | ||
{ | ||
_set.Subtract(-0m, Currency.Get("EUR")); | ||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([Usd100, Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void CurrencyNotInSet_AddsValueToSet() | ||
{ | ||
_set.Subtract(75m, Currency.Get("AUD")); | ||
_set.ShouldBe([Usd100, Cad50, Eur25, Aud75]); | ||
} | ||
|
||
[TestMethod] | ||
public void CurrencyDisallowed_ThrowsArgumentException() | ||
{ | ||
var disallowedCurrency = new Currency("XXX", "Non-existent currency", "X", 2); | ||
|
||
Should.Throw<ArgumentException>(() => _set.Subtract(100m, disallowedCurrency)) | ||
.Message.ShouldBe($"The currency '{disallowedCurrency}' is not present in the set's currency registry. (Parameter 'currency')"); | ||
|
||
_set.Count.ShouldBe(3); | ||
_set.ShouldBe([Usd100, Cad50, Eur25]); | ||
} | ||
} |