From f9f3e5ff3e8aeb5dfab82584e98e1c59dd52e480 Mon Sep 17 00:00:00 2001 From: Mike Marynowski Date: Fri, 8 Mar 2024 00:53:15 -0500 Subject: [PATCH] Add CopyTo tests for all sets --- .../Sets/CopyTo.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Tests/Singulink.Globalization.Currency.Tests/Sets/CopyTo.cs diff --git a/Tests/Singulink.Globalization.Currency.Tests/Sets/CopyTo.cs b/Tests/Singulink.Globalization.Currency.Tests/Sets/CopyTo.cs new file mode 100644 index 0000000..980095a --- /dev/null +++ b/Tests/Singulink.Globalization.Currency.Tests/Sets/CopyTo.cs @@ -0,0 +1,52 @@ +namespace Singulink.Globalization.Tests.Sets; +public static class CopyTo +{ + [PrefixTestClass] + public class TMoneySet : Tests; + + [PrefixTestClass] + public class TSortedMoneySet : Tests; + + [PrefixTestClass] + public class TImmutableMoneySet : Tests; + + [PrefixTestClass] + public class TImmutableSortedMoneySet : Tests; + + public class Tests 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)_set).CopyTo(array, 0); + array.ShouldBe([Usd100, Cad50, Eur25], ignoreOrder: true); + + array = new Money[10]; + + ((ICollection)_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(() => ((ICollection)_set).CopyTo(array, 1)); + Should.Throw(() => ((ICollection)_set).CopyTo(array, 15)); + + array = new Money[10]; + Should.Throw(() => ((ICollection)_set).CopyTo(array, 8)); + } + } +}