-
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.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
Tests/Singulink.Globalization.Currency.Tests/ImmutableSortedMoneySetTests/ToString.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,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"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Tests/Singulink.Globalization.Currency.Tests/SortedMoneySetTests/ToString.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,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"); | ||
} | ||
} |