Skip to content

Commit 5fcb0dd

Browse files
committed
Update
1 parent 09b47da commit 5fcb0dd

6 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/plugins/NodaMoneyTest/FastMoneyDto.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class FastMoneyDto
1111

1212
public string Currency { get; init; } = CurrencyCode.CNY;
1313

14+
public string Symbol { get; init; } = "¥";
15+
1416
#endregion
1517

1618
}
@@ -22,7 +24,12 @@ public static class FastMoneyExtensions
2224

2325
public static FastMoneyDto ToDto(this FastMoney fastMoney)
2426
{
25-
return new FastMoneyDto { Amount = fastMoney.Amount, Currency = fastMoney.Currency.Code };
27+
return new FastMoneyDto
28+
{
29+
Amount = fastMoney.Amount,
30+
Currency = fastMoney.Currency.Code,
31+
Symbol = fastMoney.Currency.Symbol
32+
};
2633
}
2734

2835
#endregion

src/plugins/NodaMoneyTest/MoneyTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public static void DefaultCurrency_Test()
2828
// });
2929
//MoneyContext.DefaultThreadContext = myDefaultContext;
3030

31-
var money = new Money(10.12345m);
32-
Console.WriteLine(money); // ¥10.1234
31+
var money = new Money(1001.12346m); // Amount = 1001.1235
32+
Console.WriteLine(money); // ¥1,001.12
33+
Console.WriteLine(money.ToString("C4", CultureInfo.CurrentCulture)); // ¥1,001.1235
3334
}
3435

3536
public static void FastMoney_Test()

src/plugins/NodaMoneyTest/NodaMoneyTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="NodaMoney" Version="2.6.0" />
11+
<PackageReference Include="NodaMoney" Version="2.7.0" />
1212
</ItemGroup>
1313

1414
</Project>

src/plugins/NodaMoneyTest/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ internal static class Program
88
private static void Main()
99
{
1010
MoneyTest.DefaultCurrency_Test();
11+
1112
//MoneyTest.Money_Test();
1213
//MoneyTest.Parse_Test();
1314
//MoneyTest.FastMoney_Test();

src/plugins/NodaMoneyTest/SerializationTest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NodaMoney;
22
using System.ComponentModel.DataAnnotations;
3+
using System.Text.Encodings.Web;
34
using System.Text.Json;
45

56
namespace NodaMoneyTest;
@@ -9,6 +10,11 @@ public static class SerializationTest
910

1011
#region Constants & Statics
1112

13+
private static readonly JsonSerializerOptions JsonOptions = new()
14+
{
15+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
16+
};
17+
1218
public static void Input_Validation_ModelState_Test()
1319
{
1420
var input = new MyInput("Jane Doe", 25, new FastMoneyDto { Amount = 101m, });
@@ -38,9 +44,8 @@ public static void Output_Serialization_Test()
3844
{
3945
var money = new FastMoney(99.99m);
4046
var dto = money.ToDto();
41-
4247
var output = new MyOutput("Alice Smith", 28, dto);
43-
var json = JsonSerializer.Serialize(output);
48+
var json = JsonSerializer.Serialize(output, JsonOptions);
4449
Console.WriteLine(json);
4550
}
4651

template/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,4 @@ FodyWeavers.xsd
435435
*.msp
436436

437437
# Source Generator files
438-
**/_Generated/**/*.g.cs
438+
**/_Generated/**

0 commit comments

Comments
 (0)