Skip to content

Commit

Permalink
Add ToString tests for sets
Browse files Browse the repository at this point in the history
  • Loading branch information
mikernet committed Mar 7, 2024
1 parent 0fe1df3 commit 9da7dd6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Globalization;

namespace Singulink.Globalization.Tests.ImmutableSortedMoneySetTests;

[PrefixTestClass]
public class ToString
{
private const char Sp = '\u00A0'; // The space char that ToString uses (non-breaking space)

private static readonly CultureInfo EnUS = CultureInfo.GetCultureInfo("en-US");
private static readonly CultureInfo FrFR = CultureInfo.GetCultureInfo("fe-FR");
private static readonly ImmutableSortedMoneySet Set = [Money.Create(1.23m, "USD"), Money.Create(0m, "CAD"), Money.Create(500m, "JPY")];

[TestMethod]
public void DefaultFormat()
{
CultureInfo.CurrentCulture = EnUS;

Set.ToString().ShouldBe($"CAD{Sp}0.00, JPY{Sp}500, USD{Sp}1.23");
Set.ToString(null, FrFR).ShouldBe($"0.00{Sp}CAD, 500{Sp}JPY, 1.23{Sp}USD");
}

[TestMethod]
public void ZeroAmountsIgnoredFormat()
{
CultureInfo.CurrentCulture = EnUS;

Set.ToString("!").ShouldBe($"JPY{Sp}500, USD{Sp}1.23");
Set.ToString("!", FrFR).ShouldBe($"500{Sp}JPY, 1.23{Sp}USD");
}

[TestMethod]
public void CustomMoneyFormat()
{
CultureInfo.CurrentCulture = EnUS;

Set.ToString("SN$0").ShouldBe("$0, ¥500, $1");
}

[TestMethod]
public void CustomMoneyWithZeroAmountsIgnoredFormat()
{
CultureInfo.CurrentCulture = EnUS;

Set.ToString("!SN$0").ShouldBe("¥500, $1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Globalization;

namespace Singulink.Globalization.Tests.SortedMoneySetTests;

[PrefixTestClass]
public class ToString
{
private const char Sp = '\u00A0'; // The space char that ToString uses (non-breaking space)

private static readonly CultureInfo EnUS = CultureInfo.GetCultureInfo("en-US");
private static readonly CultureInfo FrFR = CultureInfo.GetCultureInfo("fe-FR");
private static readonly ImmutableSortedMoneySet Set = [Money.Create(1.23m, "USD"), Money.Create(0m, "CAD"), Money.Create(500m, "JPY")];

private readonly SortedMoneySet _set = Set.ToSet();

[TestMethod]
public void DefaultFormat()
{
CultureInfo.CurrentCulture = EnUS;

_set.ToString().ShouldBe($"CAD{Sp}0.00, JPY{Sp}500, USD{Sp}1.23");
_set.ToString(null, FrFR).ShouldBe($"0.00{Sp}CAD, 500{Sp}JPY, 1.23{Sp}USD");
}

[TestMethod]
public void ZeroAmountsIgnoredFormat()
{
CultureInfo.CurrentCulture = EnUS;

_set.ToString("!").ShouldBe($"JPY{Sp}500, USD{Sp}1.23");
_set.ToString("!", FrFR).ShouldBe($"500{Sp}JPY, 1.23{Sp}USD");
}

[TestMethod]
public void CustomMoneyFormat()
{
CultureInfo.CurrentCulture = EnUS;

_set.ToString("SN$0").ShouldBe("$0, ¥500, $1");
}

[TestMethod]
public void CustomMoneyWithZeroAmountsIgnoredFormat()
{
CultureInfo.CurrentCulture = EnUS;

_set.ToString("!SN$0").ShouldBe("¥500, $1");
}
}

0 comments on commit 9da7dd6

Please sign in to comment.