-
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.
Add tests for ImmutableSortedMoneySet
- Loading branch information
1 parent
4445b16
commit ef804e9
Showing
4 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/AddTests.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,99 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Shouldly; | ||
|
||
namespace Singulink.Globalization.Tests.ImmutableSortedMoneySetTests; | ||
|
||
[TestClass] | ||
public class AddTests | ||
{ | ||
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 Currency DisallowedCurrency = new("Blah blah blah", "BBB", "$$", 2); | ||
private static readonly ImmutableSortedMoneySet Set = [Usd100, Cad50]; | ||
|
||
// public void Add(Money value) tests | ||
|
||
[TestMethod] | ||
public void AddMoney_CurrencyExists_UpdatesValue() | ||
{ | ||
var resultSet = Set.Add(Usd100); | ||
|
||
resultSet.Count.ShouldBe(2); | ||
resultSet.ShouldBe(ImmutableSortedMoneySet.Create(Money.Create(200m, "USD"), Cad50)); | ||
} | ||
|
||
[TestMethod] | ||
public void AddMoney_NewCurrency_AddsValue() | ||
{ | ||
var resultSet = Set.Add(Eur25); | ||
|
||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe(ImmutableSortedMoneySet.Create(Cad50, Eur25, Usd100)); | ||
} | ||
|
||
[TestMethod] | ||
public void AddMoney_DefaultValue_NoChange() | ||
{ | ||
var resultSet = Set.Add(default); | ||
|
||
resultSet.ShouldBeSameAs(Set); | ||
} | ||
|
||
[TestMethod] | ||
public void AddMoney_CurrencyDisallowed_ThrowsException() | ||
{ | ||
var value = new Money(100, DisallowedCurrency); | ||
Should.Throw<ArgumentException>(() => Set.Add(value)); | ||
} | ||
|
||
// public void Add(decimal amount, string currencyCode) tests | ||
|
||
[TestMethod] | ||
public void AddByCurrencyCode_CurrencyExists_UpdatesValue() | ||
{ | ||
var resultSet = Set.Add(100, "USD"); | ||
resultSet.Count.ShouldBe(2); | ||
resultSet.ShouldBe([Cad50, new(200m, "USD")]); | ||
} | ||
|
||
[TestMethod] | ||
public void AddByCurrencyCode_NewCurrency_AddsValue() | ||
{ | ||
var resultSet = Set.Add(25m, "EUR"); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([Cad50, Eur25, Usd100]); | ||
} | ||
|
||
[TestMethod] | ||
public void AddByCurrencyCode_CurrencyDisallowed_ThrowsArgumentException() | ||
{ | ||
Should.Throw<ArgumentException>(() => Set.Add(100m, DisallowedCurrency.CurrencyCode)); | ||
} | ||
|
||
// public void Add(decimal amount, Currency currency) tests | ||
|
||
[TestMethod] | ||
public void AddByCurrency_CurrencyExists_UpdatesValue() | ||
{ | ||
var resultSet = Set.Add(100m, Currency.Get("USD")); | ||
resultSet.Count.ShouldBe(2); | ||
resultSet.ShouldBe([Cad50, new(200m, "USD")]); | ||
} | ||
|
||
[TestMethod] | ||
public void AddByCurrency_NewCurrency_AddsValue() | ||
{ | ||
var resultSet = Set.Add(25m, Currency.Get("EUR")); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([Cad50, Eur25, Usd100]); | ||
} | ||
|
||
[TestMethod] | ||
public void AddByCurrency_CurrencyDisallowed_ThrowsArgumentException() | ||
{ | ||
Set.Count.ShouldBe(2); | ||
Should.Throw<ArgumentException>(() => Set.Add(100m, DisallowedCurrency)); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/RemoveTests.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,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Shouldly; | ||
|
||
namespace Singulink.Globalization.Tests.ImmutableSortedMoneySetTests | ||
{ | ||
[TestClass] | ||
public class RemoveTests | ||
{ | ||
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 ImmutableSortedMoneySet Set = [Usd100, Cad50, Eur25]; | ||
|
||
// public bool Remove(string currencyCode) tests | ||
|
||
[TestMethod] | ||
public void RemoveCurrencyCode_CurrencyFound_RemovesValue() | ||
{ | ||
var resultSet = Set.Remove("USD"); | ||
resultSet.Count.ShouldBe(2); | ||
resultSet.ShouldBe([Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void RemoveCurrencyCode_CurrencyNotFound_NoChange() | ||
{ | ||
var resultSet = Set.Remove("JPY"); | ||
resultSet.ShouldBeSameAs(Set); | ||
} | ||
|
||
[TestMethod] | ||
public void RemoveCurrencyCode_DisallowedCurrency_ThrowsArgumentException() | ||
{ | ||
Should.Throw<ArgumentException>(() => Set.Remove("XXX")); | ||
} | ||
|
||
// public bool Remove(Currency currency) tests | ||
|
||
[TestMethod] | ||
public void RemoveCurrency_CurrencyFound_RemovesValue() | ||
{ | ||
var resultSet = Set.Remove(Usd100.Currency); | ||
resultSet.Count.ShouldBe(2); | ||
resultSet.ShouldBe([Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void RemoveCurrency_CurrencyNotFound_NoChange() | ||
{ | ||
var gbpCurrency = Currency.Get("GBP"); | ||
var resultSet = Set.Remove(gbpCurrency); | ||
resultSet.ShouldBeSameAs(Set); | ||
} | ||
|
||
[TestMethod] | ||
public void RemoveCurrency_DisallowedCurrency_ThrowsArgumentException() | ||
{ | ||
var disallowedCurrency = new Currency("XXX", "Disallowed currency", "X", 2); | ||
Should.Throw<ArgumentException>(() => Set.Remove(disallowedCurrency)); | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/SetAmountTests.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,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Shouldly; | ||
|
||
namespace Singulink.Globalization.Tests.ImmutableSortedMoneySetTests; | ||
|
||
[TestClass] | ||
public class SetAmountTests | ||
{ | ||
private static readonly Currency Usd = Currency.Get("USD"); | ||
private static readonly Currency Aud = Currency.Get("AUD"); | ||
private static readonly Currency DisallowedCurrency = new Currency("Blah blah blah", "BBB", "$$", 2); | ||
|
||
private static readonly Money Usd0 = new(0m, "USD"); | ||
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 Set = [Usd100, Cad50, Eur25]; | ||
|
||
// public void SetAmount(decimal amount, string currencyCode) tests | ||
|
||
[TestMethod] | ||
public void SetByCurrencyCode_CurrencyExists_UpdatesValue() | ||
{ | ||
var resultSet = Set.SetAmount(200m, "USD"); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([Money.Create(200m, "USD"), Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetByCurrencyCode_NewCurrency_AddsValue() | ||
{ | ||
var resultSet = Set.SetAmount(75m, "AUD"); | ||
resultSet.Count.ShouldBe(4); | ||
resultSet.ShouldBe([Cad50, Eur25, Usd100, Aud75]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetByCurrencyCode_ZeroAmount_ZeroesValue() | ||
{ | ||
var resultSet = Set.SetAmount(0, "USD"); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([Usd0, Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetByCurrencyCode_CurrencyDisallowed_ThrowsArgumentException() | ||
{ | ||
Should.Throw<ArgumentException>(() => Set.SetAmount(123m, DisallowedCurrency.CurrencyCode)); | ||
} | ||
|
||
// public void SetAmount(decimal amount, Currency currency) tests | ||
|
||
[TestMethod] | ||
|
||
public void SetByCurrency_CurrencyExists_UpdatesValue() | ||
{ | ||
var resultSet = Set.SetAmount(200m, Usd); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([new(200m, "USD"), Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetByCurrency_CurrencyDoesNotExist_AddsValue() | ||
{ | ||
var resultSet = Set.SetAmount(75m, Aud); | ||
resultSet.Count.ShouldBe(4); | ||
resultSet.ShouldBe([Cad50, Eur25, Usd100, Aud75]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetByCurrency_ZeroAmount_ZeroesValue() | ||
{ | ||
var resultSet = Set.SetAmount(0, Usd); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([Usd0, Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetByCurrency_CurrencyDisallowed_ThrowsArgumentException() | ||
{ | ||
Should.Throw<ArgumentException>(() => Set.SetAmount(123m, DisallowedCurrency)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/SetValueTests.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,43 @@ | ||
using Shouldly; | ||
|
||
namespace Singulink.Globalization.Tests.ImmutableSortedMoneySetTests; | ||
|
||
[TestClass] | ||
public class SetValueTests | ||
{ | ||
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 Set = [Usd100, Cad50, Eur25]; | ||
|
||
[TestMethod] | ||
public void SetValue_CurrencyDoesNotExist_AddsValue() | ||
{ | ||
var resultSet = Set.SetValue(Aud75); | ||
resultSet.Count.ShouldBe(4); | ||
resultSet.ShouldBe([Cad50, Eur25, Usd100, Aud75]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetValue_CurrencyExists_UpdatesValue() | ||
{ | ||
var resultSet = Set.SetValue(new(200m, "USD")); | ||
resultSet.Count.ShouldBe(3); | ||
resultSet.ShouldBe([new(200m, "USD"), Cad50, Eur25]); | ||
} | ||
|
||
[TestMethod] | ||
public void SetValue_DefaultValue_NoChange() | ||
{ | ||
var resultSet = Set.SetValue(default); | ||
resultSet.ShouldBeSameAs(Set); | ||
} | ||
|
||
[TestMethod] | ||
public void SetValue_CurrencyIsNotAccepted_ThrowsArgumentException() | ||
{ | ||
var value = new Money(100, new Currency("Blah blah blah", "BBB", "$$", 2)); | ||
Should.Throw<ArgumentException>(() => Set.SetValue(value)); | ||
} | ||
} |