Skip to content

Commit

Permalink
Add CopyTo tests for all sets
Browse files Browse the repository at this point in the history
  • Loading branch information
mikernet committed Mar 8, 2024
1 parent 5dab4da commit f9f3e5f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Tests/Singulink.Globalization.Currency.Tests/Sets/CopyTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Singulink.Globalization.Tests.Sets;
public static class CopyTo
{
[PrefixTestClass]
public class TMoneySet : Tests<MoneySet>;

[PrefixTestClass]
public class TSortedMoneySet : Tests<SortedMoneySet>;

[PrefixTestClass]
public class TImmutableMoneySet : Tests<ImmutableMoneySet>;

[PrefixTestClass]
public class TImmutableSortedMoneySet : Tests<ImmutableSortedMoneySet>;

public class Tests<T> where T : IReadOnlyMoneySet
{
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 readonly IReadOnlyMoneySet _set = T.Create(CurrencyRegistry.Default, [Usd100, Cad50, Eur25]);

[TestMethod]
public void DestinationSufficientSize_Successful()
{
var array = new Money[3];

((ICollection<Money>)_set).CopyTo(array, 0);
array.ShouldBe([Usd100, Cad50, Eur25], ignoreOrder: true);

array = new Money[10];

((ICollection<Money>)_set).CopyTo(array, 5);

array.Take(5).ShouldAllBe(m => m.IsDefault);
array.Skip(5).Take(3).ShouldBe([Usd100, Cad50, Eur25], ignoreOrder: true);
array.Skip(8).ShouldAllBe(m => m.IsDefault);
}

[TestMethod]
public void DestinationInsufficientSize_Successful()
{
var array = new Money[2];
Should.Throw<ArgumentException>(() => ((ICollection<Money>)_set).CopyTo(array, 1));
Should.Throw<ArgumentOutOfRangeException>(() => ((ICollection<Money>)_set).CopyTo(array, 15));

array = new Money[10];
Should.Throw<ArgumentException>(() => ((ICollection<Money>)_set).CopyTo(array, 8));
}
}
}

0 comments on commit f9f3e5f

Please sign in to comment.