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
88 [ Fact ]
99 public void MoneyToDecimal ( )
1010 {
11- var m = new Money ( ) { CurrencyCode = "EUR" , CentAmount = 123456 } ;
11+ var m = new Money ( ) { CurrencyCode = "EUR" , CentAmount = 123456 } ;
1212 decimal expect = 1234.56M ;
1313 Assert . Equal ( expect , m . AmountToDecimal ( ) ) ;
1414 }
Original file line number Diff line number Diff line change @@ -102,5 +102,23 @@ public void DeserializeInvalidMoney()
102102 var exception = Assert . Throws < JsonSerializationException > ( ( ) => serializerService . Deserialize < BaseMoney > ( serialized ) ) ;
103103 Assert . Equal ( "Unknown money type: {\" type\" :\" unknown\" ,\" centAmount\" :123456}" , exception . Message ) ;
104104 }
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+ }
105123 }
106124}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public class Money : BaseMoney
1212
1313 public override decimal AmountToDecimal ( )
1414 {
15- return ( decimal ) CentAmount / 100M ;
15+ return CentAmount / ( decimal ) Math . Pow ( 10 , FractionDigits ?? 2 ) ;
1616 }
1717
1818 [ Obsolete ( "will be replaced by more resilient implementation" ) ]
You can’t perform that action at this time.
0 commit comments