Skip to content

Commit a9b7b7e

Browse files
committed
Test coverage for configured, mapper-wide decimal and double ToString formatting
1 parent 3058c4d commit a9b7b7e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

AgileMapper.UnitTests/Configuration/WhenConfiguringStringFormatting.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class WhenConfiguringStringFormatting
88
{
99
// See https://github.com/agileobjects/AgileMapper/issues/23
1010
[Fact]
11-
public void ShouldFormatDateTimesGlobally()
11+
public void ShouldFormatDateTimesMapperWide()
1212
{
1313
using (var mapper = Mapper.CreateNew())
1414
{
@@ -21,5 +21,35 @@ public void ShouldFormatDateTimesGlobally()
2121
result.Value.ShouldBe(source.Value.ToString("o"));
2222
}
2323
}
24+
25+
[Fact]
26+
public void ShouldFormatDecimalsMapperWide()
27+
{
28+
using (var mapper = Mapper.CreateNew())
29+
{
30+
mapper.WhenMapping
31+
.StringsFrom<decimal>(c => c.FormatUsing("C"));
32+
33+
var source = new PublicProperty<decimal> { Value = 1.99m };
34+
var result = mapper.Map(source).ToANew<PublicField<string>>();
35+
36+
result.Value.ShouldBe(source.Value.ToString("C"));
37+
}
38+
}
39+
40+
[Fact]
41+
public void ShouldFormatDoublesMapperWideUsingDecimalPlaces()
42+
{
43+
using (var mapper = Mapper.CreateNew())
44+
{
45+
mapper.WhenMapping
46+
.StringsFrom<double>(c => c.FormatUsing("0.00"));
47+
48+
var source = new PublicProperty<double> { Value = 1 };
49+
var result = mapper.Map(source).ToANew<PublicField<string>>();
50+
51+
result.Value.ShouldBe("1.00");
52+
}
53+
}
2454
}
2555
}

0 commit comments

Comments
 (0)