1
1
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected] ).
2
2
// https://github.com/angularsen/UnitsNet
3
- //
3
+ //
4
4
// Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
// of this software and associated documentation files (the "Software"), to deal
6
6
// in the Software without restriction, including without limitation the rights
7
7
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
8
// copies of the Software, and to permit persons to whom the Software is
9
9
// furnished to do so, subject to the following conditions:
10
- //
10
+ //
11
11
// The above copyright notice and this permission notice shall be included in
12
12
// all copies or substantial portions of the Software.
13
- //
13
+ //
14
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
19
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
// THE SOFTWARE.
21
21
22
+ using System . Globalization ;
22
23
using Xunit ;
23
24
24
25
namespace UnitsNet . Tests . CustomCode
@@ -46,5 +47,28 @@ public void StonePoundsRoundTrip()
46
47
AssertEx . EqualTolerance ( 2 , stonePounds . Stone , StoneTolerance ) ;
47
48
AssertEx . EqualTolerance ( 3 , stonePounds . Pounds , PoundsTolerance ) ;
48
49
}
50
+
51
+ [ Fact ]
52
+ public void StonePoundsToString_FormatsNumberInDefaultCulture ( )
53
+ {
54
+ Mass m = Mass . FromStonePounds ( 3500 , 1 ) ;
55
+ StonePounds stonePounds = m . StonePounds ;
56
+ string numberInCurrentCulture = 3500 . ToString ( "n0" , GlobalConfiguration . DefaultCulture ) ; // Varies between machines, can't hard code it
57
+
58
+ Assert . Equal ( $ "{ numberInCurrentCulture } st 1 lb", stonePounds . ToString ( ) ) ;
59
+ }
60
+
61
+ // These cultures use a thin space in digit grouping
62
+ [ Theory ]
63
+ [ InlineData ( "nn-NO" ) ]
64
+ [ InlineData ( "fr-FR" ) ]
65
+ public void StonePoundsToString_GivenCultureWithThinSpaceDigitGroup_ReturnsNumberWithThinSpaceDigitGroup ( string cultureName )
66
+ {
67
+ var formatProvider = new CultureInfo ( cultureName ) ;
68
+ Mass m = Mass . FromStonePounds ( 3500 , 1 ) ;
69
+ StonePounds stonePounds = m . StonePounds ;
70
+
71
+ Assert . Equal ( "3 500 st 1 lb" , stonePounds . ToString ( formatProvider ) ) ;
72
+ }
49
73
}
50
- }
74
+ }
0 commit comments