Skip to content

Commit

Permalink
Add tests for ImmutableSortedMoneySet.Add method
Browse files Browse the repository at this point in the history
  • Loading branch information
Giura-Paul committed Mar 4, 2024
1 parent 4445b16 commit e8e4bd6
Showing 1 changed file with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ArgumentException>(() => _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<ArgumentException>(() => _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<ArgumentException>(() => _immutableSet.Add(100m, DisallowedCurrency));
}
}

0 comments on commit e8e4bd6

Please sign in to comment.