@@ -55,7 +55,7 @@ public UnitAbbreviationsCacheTests(ITestOutputHelper output)
55
55
[ InlineData ( 0.115 , "0.12 m" ) ]
56
56
public void DefaultToStringFormatting ( double value , string expected )
57
57
{
58
- string actual = Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , AmericanCulture ) ;
58
+ string actual = Length . FromMeters ( value ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture ) ;
59
59
Assert . Equal ( expected , actual ) ;
60
60
}
61
61
@@ -77,7 +77,7 @@ private enum CustomUnit
77
77
[ InlineData ( "it-IT" ) ]
78
78
public void CommaRadixPointCultureFormatting ( string culture )
79
79
{
80
- Assert . Equal ( "0,12 m" , Length . FromMeters ( 0.12 ) . ToString ( LengthUnit . Meter , GetCulture ( culture ) ) ) ;
80
+ Assert . Equal ( "0,12 m" , Length . FromMeters ( 0.12 ) . ToUnit ( LengthUnit . Meter ) . ToString ( GetCulture ( culture ) ) ) ;
81
81
}
82
82
83
83
// These cultures all use a decimal point for the radix point
@@ -89,7 +89,7 @@ public void CommaRadixPointCultureFormatting(string culture)
89
89
[ InlineData ( "es-MX" ) ]
90
90
public void DecimalRadixPointCultureFormatting ( string culture )
91
91
{
92
- Assert . Equal ( "0.12 m" , Length . FromMeters ( 0.12 ) . ToString ( LengthUnit . Meter , GetCulture ( culture ) ) ) ;
92
+ Assert . Equal ( "0.12 m" , Length . FromMeters ( 0.12 ) . ToUnit ( LengthUnit . Meter ) . ToString ( GetCulture ( culture ) ) ) ;
93
93
}
94
94
95
95
// These cultures all use a comma in digit grouping
@@ -102,7 +102,7 @@ public void DecimalRadixPointCultureFormatting(string culture)
102
102
public void CommaDigitGroupingCultureFormatting ( string cultureName )
103
103
{
104
104
CultureInfo culture = GetCulture ( cultureName ) ;
105
- Assert . Equal ( "1,111 m" , Length . FromMeters ( 1111 ) . ToString ( LengthUnit . Meter , culture ) ) ;
105
+ Assert . Equal ( "1,111 m" , Length . FromMeters ( 1111 ) . ToUnit ( LengthUnit . Meter ) . ToString ( culture ) ) ;
106
106
107
107
// Feet/Inch and Stone/Pound combinations are only used (customarily) in the US, UK and maybe Ireland - all English speaking countries.
108
108
// FeetInches returns a whole number of feet, with the remainder expressed (rounded) in inches. Same for SonePounds.
@@ -119,7 +119,7 @@ public void CommaDigitGroupingCultureFormatting(string cultureName)
119
119
public void SpaceDigitGroupingCultureFormatting ( string culture )
120
120
{
121
121
// Note: the space used in digit groupings is actually a "thin space" Unicode character U+2009
122
- Assert . Equal ( "1 111 m" , Length . FromMeters ( 1111 ) . ToString ( LengthUnit . Meter , GetCulture ( culture ) ) ) ;
122
+ Assert . Equal ( "1 111 m" , Length . FromMeters ( 1111 ) . ToUnit ( LengthUnit . Meter ) . ToString ( GetCulture ( culture ) ) ) ;
123
123
}
124
124
125
125
// These cultures all use a decimal point in digit grouping
@@ -131,7 +131,7 @@ public void SpaceDigitGroupingCultureFormatting(string culture)
131
131
[ InlineData ( "it-IT" ) ]
132
132
public void DecimalPointDigitGroupingCultureFormatting ( string culture )
133
133
{
134
- Assert . Equal ( "1.111 m" , Length . FromMeters ( 1111 ) . ToString ( LengthUnit . Meter , GetCulture ( culture ) ) ) ;
134
+ Assert . Equal ( "1.111 m" , Length . FromMeters ( 1111 ) . ToUnit ( LengthUnit . Meter ) . ToString ( GetCulture ( culture ) ) ) ;
135
135
}
136
136
137
137
[ Theory ]
@@ -143,7 +143,7 @@ public void DecimalPointDigitGroupingCultureFormatting(string culture)
143
143
[ InlineData ( 6 , "1.123457 m" ) ]
144
144
public void CustomNumberOfSignificantDigitsAfterRadixFormatting ( int significantDigitsAfterRadix , string expected )
145
145
{
146
- string actual = Length . FromMeters ( 1.123456789 ) . ToString ( LengthUnit . Meter , AmericanCulture , significantDigitsAfterRadix ) ;
146
+ string actual = Length . FromMeters ( 1.123456789 ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture , significantDigitsAfterRadix ) ;
147
147
Assert . Equal ( expected , actual ) ;
148
148
}
149
149
@@ -158,7 +158,7 @@ public void CustomNumberOfSignificantDigitsAfterRadixFormatting(int significantD
158
158
public void RoundingErrorsWithSignificantDigitsAfterRadixFormatting ( double value ,
159
159
int maxSignificantDigitsAfterRadix , string expected )
160
160
{
161
- string actual = Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , AmericanCulture , maxSignificantDigitsAfterRadix ) ;
161
+ string actual = Length . FromMeters ( value ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture , maxSignificantDigitsAfterRadix ) ;
162
162
Assert . Equal ( expected , actual ) ;
163
163
}
164
164
@@ -170,7 +170,7 @@ public void RoundingErrorsWithSignificantDigitsAfterRadixFormatting(double value
170
170
[ InlineData ( 1.99e-4 , "1.99e-04 m" ) ]
171
171
public void ScientificNotationLowerInterval ( double value , string expected )
172
172
{
173
- string actual = Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , AmericanCulture ) ;
173
+ string actual = Length . FromMeters ( value ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture ) ;
174
174
Assert . Equal ( expected , actual ) ;
175
175
}
176
176
@@ -181,7 +181,7 @@ public void ScientificNotationLowerInterval(double value, string expected)
181
181
[ InlineData ( 999.99 , "999.99 m" ) ]
182
182
public void FixedPointNotationIntervalFormatting ( double value , string expected )
183
183
{
184
- string actual = Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , AmericanCulture ) ;
184
+ string actual = Length . FromMeters ( value ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture ) ;
185
185
Assert . Equal ( expected , actual ) ;
186
186
}
187
187
@@ -193,7 +193,7 @@ public void FixedPointNotationIntervalFormatting(double value, string expected)
193
193
[ InlineData ( 999999.99 , "999,999.99 m" ) ]
194
194
public void FixedPointNotationWithDigitGroupingIntervalFormatting ( double value , string expected )
195
195
{
196
- string actual = Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , AmericanCulture ) ;
196
+ string actual = Length . FromMeters ( value ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture ) ;
197
197
Assert . Equal ( expected , actual ) ;
198
198
}
199
199
@@ -204,7 +204,7 @@ public void FixedPointNotationWithDigitGroupingIntervalFormatting(double value,
204
204
[ InlineData ( double . MaxValue , "1.8e+308 m" ) ]
205
205
public void ScientificNotationUpperIntervalFormatting ( double value , string expected )
206
206
{
207
- string actual = Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , AmericanCulture ) ;
207
+ string actual = Length . FromMeters ( value ) . ToUnit ( LengthUnit . Meter ) . ToString ( AmericanCulture ) ;
208
208
Assert . Equal ( expected , actual ) ;
209
209
}
210
210
@@ -231,35 +231,35 @@ public void AllUnitsImplementToStringForInvariantCulture()
231
231
[ Fact ]
232
232
public void ToString_WithNorwegianCulture ( )
233
233
{
234
- Assert . Equal ( "1 °" , Angle . FromDegrees ( 1 ) . ToString ( AngleUnit . Degree , NorwegianCulture ) ) ;
235
- Assert . Equal ( "1 m²" , Area . FromSquareMeters ( 1 ) . ToString ( AreaUnit . SquareMeter , NorwegianCulture ) ) ;
236
- Assert . Equal ( "1 V" , ElectricPotential . FromVolts ( 1 ) . ToString ( ElectricPotentialUnit . Volt , NorwegianCulture ) ) ;
237
- Assert . Equal ( "1 m³/s" , VolumeFlow . FromCubicMetersPerSecond ( 1 ) . ToString ( VolumeFlowUnit . CubicMeterPerSecond , NorwegianCulture ) ) ;
238
- Assert . Equal ( "1 N" , Force . FromNewtons ( 1 ) . ToString ( ForceUnit . Newton , NorwegianCulture ) ) ;
239
- Assert . Equal ( "1 m" , Length . FromMeters ( 1 ) . ToString ( LengthUnit . Meter , NorwegianCulture ) ) ;
240
- Assert . Equal ( "1 kg" , Mass . FromKilograms ( 1 ) . ToString ( MassUnit . Kilogram , NorwegianCulture ) ) ;
241
- Assert . Equal ( "1 Pa" , Pressure . FromPascals ( 1 ) . ToString ( PressureUnit . Pascal , NorwegianCulture ) ) ;
242
- Assert . Equal ( "1 rad/s" , RotationalSpeed . FromRadiansPerSecond ( 1 ) . ToString ( RotationalSpeedUnit . RadianPerSecond , NorwegianCulture ) ) ;
243
- Assert . Equal ( "1 K" , Temperature . FromKelvins ( 1 ) . ToString ( TemperatureUnit . Kelvin , NorwegianCulture ) ) ;
244
- Assert . Equal ( "1 N·m" , Torque . FromNewtonMeters ( 1 ) . ToString ( TorqueUnit . NewtonMeter , NorwegianCulture ) ) ;
245
- Assert . Equal ( "1 m³" , Volume . FromCubicMeters ( 1 ) . ToString ( VolumeUnit . CubicMeter , NorwegianCulture ) ) ;
234
+ Assert . Equal ( "1 °" , Angle . FromDegrees ( 1 ) . ToUnit ( AngleUnit . Degree ) . ToString ( NorwegianCulture ) ) ;
235
+ Assert . Equal ( "1 m²" , Area . FromSquareMeters ( 1 ) . ToUnit ( AreaUnit . SquareMeter ) . ToString ( NorwegianCulture ) ) ;
236
+ Assert . Equal ( "1 V" , ElectricPotential . FromVolts ( 1 ) . ToUnit ( ElectricPotentialUnit . Volt ) . ToString ( NorwegianCulture ) ) ;
237
+ Assert . Equal ( "1 m³/s" , VolumeFlow . FromCubicMetersPerSecond ( 1 ) . ToUnit ( VolumeFlowUnit . CubicMeterPerSecond ) . ToString ( NorwegianCulture ) ) ;
238
+ Assert . Equal ( "1 N" , Force . FromNewtons ( 1 ) . ToUnit ( ForceUnit . Newton ) . ToString ( NorwegianCulture ) ) ;
239
+ Assert . Equal ( "1 m" , Length . FromMeters ( 1 ) . ToUnit ( LengthUnit . Meter ) . ToString ( NorwegianCulture ) ) ;
240
+ Assert . Equal ( "1 kg" , Mass . FromKilograms ( 1 ) . ToUnit ( MassUnit . Kilogram ) . ToString ( NorwegianCulture ) ) ;
241
+ Assert . Equal ( "1 Pa" , Pressure . FromPascals ( 1 ) . ToUnit ( PressureUnit . Pascal ) . ToString ( NorwegianCulture ) ) ;
242
+ Assert . Equal ( "1 rad/s" , RotationalSpeed . FromRadiansPerSecond ( 1 ) . ToUnit ( RotationalSpeedUnit . RadianPerSecond ) . ToString ( NorwegianCulture ) ) ;
243
+ Assert . Equal ( "1 K" , Temperature . FromKelvins ( 1 ) . ToUnit ( TemperatureUnit . Kelvin ) . ToString ( NorwegianCulture ) ) ;
244
+ Assert . Equal ( "1 N·m" , Torque . FromNewtonMeters ( 1 ) . ToUnit ( TorqueUnit . NewtonMeter ) . ToString ( NorwegianCulture ) ) ;
245
+ Assert . Equal ( "1 m³" , Volume . FromCubicMeters ( 1 ) . ToUnit ( VolumeUnit . CubicMeter ) . ToString ( NorwegianCulture ) ) ;
246
246
}
247
247
248
248
[ Fact ]
249
249
public void ToString_WithRussianCulture ( )
250
250
{
251
- Assert . Equal ( "1 °" , Angle . FromDegrees ( 1 ) . ToString ( AngleUnit . Degree , RussianCulture ) ) ;
252
- Assert . Equal ( "1 м²" , Area . FromSquareMeters ( 1 ) . ToString ( AreaUnit . SquareMeter , RussianCulture ) ) ;
253
- Assert . Equal ( "1 В" , ElectricPotential . FromVolts ( 1 ) . ToString ( ElectricPotentialUnit . Volt , RussianCulture ) ) ;
254
- Assert . Equal ( "1 м³/с" , VolumeFlow . FromCubicMetersPerSecond ( 1 ) . ToString ( VolumeFlowUnit . CubicMeterPerSecond , RussianCulture ) ) ;
255
- Assert . Equal ( "1 Н" , Force . FromNewtons ( 1 ) . ToString ( ForceUnit . Newton , RussianCulture ) ) ;
256
- Assert . Equal ( "1 м" , Length . FromMeters ( 1 ) . ToString ( LengthUnit . Meter , RussianCulture ) ) ;
257
- Assert . Equal ( "1 кг" , Mass . FromKilograms ( 1 ) . ToString ( MassUnit . Kilogram , RussianCulture ) ) ;
258
- Assert . Equal ( "1 Па" , Pressure . FromPascals ( 1 ) . ToString ( PressureUnit . Pascal , RussianCulture ) ) ;
259
- Assert . Equal ( "1 рад/с" , RotationalSpeed . FromRadiansPerSecond ( 1 ) . ToString ( RotationalSpeedUnit . RadianPerSecond , RussianCulture ) ) ;
260
- Assert . Equal ( "1 K" , Temperature . FromKelvins ( 1 ) . ToString ( TemperatureUnit . Kelvin , RussianCulture ) ) ;
261
- Assert . Equal ( "1 Н·м" , Torque . FromNewtonMeters ( 1 ) . ToString ( TorqueUnit . NewtonMeter , RussianCulture ) ) ;
262
- Assert . Equal ( "1 м³" , Volume . FromCubicMeters ( 1 ) . ToString ( VolumeUnit . CubicMeter , RussianCulture ) ) ;
251
+ Assert . Equal ( "1 °" , Angle . FromDegrees ( 1 ) . ToUnit ( AngleUnit . Degree ) . ToString ( RussianCulture ) ) ;
252
+ Assert . Equal ( "1 м²" , Area . FromSquareMeters ( 1 ) . ToUnit ( AreaUnit . SquareMeter ) . ToString ( RussianCulture ) ) ;
253
+ Assert . Equal ( "1 В" , ElectricPotential . FromVolts ( 1 ) . ToUnit ( ElectricPotentialUnit . Volt ) . ToString ( RussianCulture ) ) ;
254
+ Assert . Equal ( "1 м³/с" , VolumeFlow . FromCubicMetersPerSecond ( 1 ) . ToUnit ( VolumeFlowUnit . CubicMeterPerSecond ) . ToString ( RussianCulture ) ) ;
255
+ Assert . Equal ( "1 Н" , Force . FromNewtons ( 1 ) . ToUnit ( ForceUnit . Newton ) . ToString ( RussianCulture ) ) ;
256
+ Assert . Equal ( "1 м" , Length . FromMeters ( 1 ) . ToUnit ( LengthUnit . Meter ) . ToString ( RussianCulture ) ) ;
257
+ Assert . Equal ( "1 кг" , Mass . FromKilograms ( 1 ) . ToUnit ( MassUnit . Kilogram ) . ToString ( RussianCulture ) ) ;
258
+ Assert . Equal ( "1 Па" , Pressure . FromPascals ( 1 ) . ToUnit ( PressureUnit . Pascal ) . ToString ( RussianCulture ) ) ;
259
+ Assert . Equal ( "1 рад/с" , RotationalSpeed . FromRadiansPerSecond ( 1 ) . ToUnit ( RotationalSpeedUnit . RadianPerSecond ) . ToString ( RussianCulture ) ) ;
260
+ Assert . Equal ( "1 K" , Temperature . FromKelvins ( 1 ) . ToUnit ( TemperatureUnit . Kelvin ) . ToString ( RussianCulture ) ) ;
261
+ Assert . Equal ( "1 Н·м" , Torque . FromNewtonMeters ( 1 ) . ToUnit ( TorqueUnit . NewtonMeter ) . ToString ( RussianCulture ) ) ;
262
+ Assert . Equal ( "1 м³" , Volume . FromCubicMeters ( 1 ) . ToUnit ( VolumeUnit . CubicMeter ) . ToString ( RussianCulture ) ) ;
263
263
}
264
264
265
265
[ Fact ]
0 commit comments