-
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.Add method
- Loading branch information
1 parent
4445b16
commit e8e4bd6
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
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,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)); | ||
} | ||
} |