diff --git a/Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/AddTests.cs b/Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/AddTests.cs new file mode 100644 index 0000000..bda62bd --- /dev/null +++ b/Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/AddTests.cs @@ -0,0 +1,100 @@ +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 _immutableSet = [Usd100, Cad50]; + + // public void Add(Money value) tests + + [TestMethod] + public void AddMoney_CurrencyExists_UpdatesValue() + { + var updatedSet = _immutableSet.Add(Usd100); + + updatedSet.Count.ShouldBe(2); + updatedSet.ShouldBe(ImmutableSortedMoneySet.Create(Money.Create(200m, "USD"), Cad50)); + } + + [TestMethod] + public void AddMoney_NewCurrency_AddsValue() + { + var updatedSet = _immutableSet.Add(Eur25); + + updatedSet.Count.ShouldBe(3); + updatedSet.ShouldBe(ImmutableSortedMoneySet.Create(Cad50, Eur25, Usd100)); + } + + [TestMethod] + public void AddMoney_DefaultValue_NoChange() + { + var updatedSet = _immutableSet.Add(default); + + updatedSet.Count.ShouldBe(2); + updatedSet.ShouldBe(_immutableSet); + } + + [TestMethod] + public void AddMoney_CurrencyDisallowed_ThrowsException() + { + var value = new Money(100, DisallowedCurrency); + Should.Throw(() => _immutableSet.Add(value)); + } + + // public void Add(decimal amount, string currencyCode) tests + + [TestMethod] + public void AddByCurrencyCode_CurrencyExists_UpdatesValue() + { + var updatedSet = _immutableSet.Add(100, "USD"); + updatedSet.Count.ShouldBe(2); + updatedSet.ShouldBe([Cad50, new(200m, "USD")]); + } + + [TestMethod] + public void AddByCurrencyCode_NewCurrency_AddsValue() + { + var updatedSet = _immutableSet.Add(25m, "EUR"); + updatedSet.Count.ShouldBe(3); + updatedSet.ShouldBe([Cad50, Eur25, Usd100]); + } + + [TestMethod] + public void AddByCurrencyCode_CurrencyDisallowed_ThrowsArgumentException() + { + Should.Throw(() => _immutableSet.Add(100m, DisallowedCurrency.CurrencyCode)); + } + + // public void Add(decimal amount, Currency currency) tests + + [TestMethod] + public void AddByCurrency_CurrencyExists_UpdatesValue() + { + var updatedSet = _immutableSet.Add(100m, Currency.Get("USD")); + updatedSet.Count.ShouldBe(2); + updatedSet.ShouldBe([Cad50, new(200m, "USD")]); + } + + [TestMethod] + public void AddByCurrency_NewCurrency_AddsValue() + { + var updatedSet = _immutableSet.Add(25m, Currency.Get("EUR")); + updatedSet.Count.ShouldBe(3); + updatedSet.ShouldBe([Cad50, Eur25, Usd100]); + } + + [TestMethod] + public void AddByCurrency_CurrencyDisallowed_ThrowsArgumentException() + { + _immutableSet.Count.ShouldBe(2); + Should.Throw(() => _immutableSet.Add(100m, DisallowedCurrency)); + } +} \ No newline at end of file