This repository was archived by the owner on Jun 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
commercetools.Sdk.Domain.Tests
commercetools.Sdk.Serialization.Tests
commercetools.Sdk.Domain/Common Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ public class MoneyTest
8
8
[ Fact ]
9
9
public void MoneyToDecimal ( )
10
10
{
11
- var m = new Money ( ) { CurrencyCode = "EUR" , CentAmount = 123456 } ;
11
+ var m = new Money ( ) { CurrencyCode = "EUR" , CentAmount = 123456 } ;
12
12
decimal expect = 1234.56M ;
13
13
Assert . Equal ( expect , m . AmountToDecimal ( ) ) ;
14
14
}
Original file line number Diff line number Diff line change @@ -102,5 +102,23 @@ public void DeserializeInvalidMoney()
102
102
var exception = Assert . Throws < JsonSerializationException > ( ( ) => serializerService . Deserialize < BaseMoney > ( serialized ) ) ;
103
103
Assert . Equal ( "Unknown money type: {\" type\" :\" unknown\" ,\" centAmount\" :123456}" , exception . Message ) ;
104
104
}
105
+
106
+ [ Fact ]
107
+ public void MoneyDeserializationWithZeroFractionDigits ( )
108
+ {
109
+ ISerializerService serializerService = this . serializationFixture . SerializerService ;
110
+ string serialized = @"{
111
+ ""type"": ""centPrecision"",
112
+ ""currencyCode"": ""KRW"",
113
+ ""centAmount"": 60500,
114
+ ""fractionDigits"": 0
115
+ }" ;
116
+ var deserialized = serializerService . Deserialize < BaseMoney > ( serialized ) ;
117
+ Assert . IsType < Money > ( deserialized ) ;
118
+ Assert . Equal ( "KRW" , deserialized . CurrencyCode ) ;
119
+ Assert . Equal ( MoneyType . CentPrecision , deserialized . Type ) ;
120
+ Assert . Equal ( 0 , deserialized . FractionDigits ) ;
121
+ Assert . Equal ( 60500M , deserialized . AmountToDecimal ( ) ) ;
122
+ }
105
123
}
106
124
}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public class Money : BaseMoney
12
12
13
13
public override decimal AmountToDecimal ( )
14
14
{
15
- return ( decimal ) CentAmount / 100M ;
15
+ return CentAmount / ( decimal ) Math . Pow ( 10 , FractionDigits ?? 2 ) ;
16
16
}
17
17
18
18
[ Obsolete ( "will be replaced by more resilient implementation" ) ]
You can’t perform that action at this time.
0 commit comments