@@ -69,15 +69,6 @@ private enum CustomUnit
69
69
// ReSharper restore UnusedMember.Local
70
70
}
71
71
72
- #if ! WINDOWS_UWP
73
- private UnitSystem GetCachedUnitSystem ( )
74
- {
75
- Culture culture = GetCulture ( "en-US" ) ;
76
- UnitSystem unitSystem = UnitSystem . GetCached ( culture ) ;
77
- return unitSystem ;
78
- }
79
- #endif
80
-
81
72
private static IEnumerable < object > GetUnitTypesWithMissingAbbreviations < TUnitType > ( string cultureName ,
82
73
IEnumerable < TUnitType > unitValues )
83
74
where TUnitType : /*Enum constraint hack*/ struct , IComparable , IFormattable
@@ -180,15 +171,21 @@ public void DecimalPointDigitGroupingCultureFormatting(string culture)
180
171
181
172
#if ! WINDOWS_UWP
182
173
[ Theory ]
183
- [ InlineData ( "m^2" , AreaUnit . SquareMeter ) ]
184
- [ InlineData ( "cm^2" , AreaUnit . Undefined ) ]
185
- public void Parse_ReturnsUnitMappedByCustomAbbreviationOrUndefined ( string unitAbbreviationToParse , AreaUnit expected )
174
+ [ InlineData ( "m^^ 2" , AreaUnit . SquareMeter ) ]
175
+ [ InlineData ( "cm^^ 2" , AreaUnit . SquareCentimeter ) ]
176
+ public void Parse_ReturnsUnitMappedByCustomAbbreviation ( string customAbbreviation , AreaUnit expected )
186
177
{
187
- UnitSystem unitSystem = GetCachedUnitSystem ( ) ;
188
- unitSystem . MapUnitToAbbreviation ( AreaUnit . SquareMeter , "m^2" ) ;
189
- var actual = unitSystem . Parse < AreaUnit > ( unitAbbreviationToParse ) ;
178
+ UnitSystem unitSystem = UnitSystem . Default ;
179
+ unitSystem . MapUnitToAbbreviation ( expected , customAbbreviation ) ;
180
+ var actual = unitSystem . Parse < AreaUnit > ( customAbbreviation ) ;
190
181
Assert . Equal ( expected , actual ) ;
191
182
}
183
+
184
+ [ Fact ]
185
+ public void Parse_UnknownAbbreviationThrowsUnitNotFoundException ( )
186
+ {
187
+ Assert . Throws < UnitNotFoundException > ( ( ) => UnitSystem . Default . Parse < AreaUnit > ( "nonexistingunit" ) ) ;
188
+ }
192
189
#endif
193
190
194
191
[ Theory ]
@@ -296,31 +293,31 @@ public void ShouldUseCorrectMicroSign()
296
293
Assert . Equal ( VolumeUnit . CubicMicrometer , Volume . ParseUnit ( "\u00b5 m³" ) ) ;
297
294
298
295
// "\u03bc" = Lower case greek letter 'Mu'
299
- Assert . Throws < UnitsNetException > ( ( ) => Acceleration . ParseUnit ( "\u03bc m/s²" ) ) ;
300
- Assert . Throws < UnitsNetException > ( ( ) => AmplitudeRatio . ParseUnit ( "dB\u03bc V" ) ) ;
301
- Assert . Throws < UnitsNetException > ( ( ) => Angle . ParseUnit ( "\u03bc °" ) ) ;
302
- Assert . Throws < UnitsNetException > ( ( ) => Angle . ParseUnit ( "\u03bc rad" ) ) ;
303
- Assert . Throws < UnitsNetException > ( ( ) => Area . ParseUnit ( "\u03bc m²" ) ) ;
304
- Assert . Throws < UnitsNetException > ( ( ) => Duration . ParseUnit ( "\u03bc s" ) ) ;
305
- Assert . Throws < UnitsNetException > ( ( ) => ElectricCurrent . ParseUnit ( "\u03bc A" ) ) ;
306
- Assert . Throws < UnitsNetException > ( ( ) => ElectricPotential . ParseUnit ( "\u03bc V" ) ) ;
307
- Assert . Throws < UnitsNetException > ( ( ) => Flow . ParseUnit ( "\u03bc LPM" ) ) ;
308
- Assert . Throws < UnitsNetException > ( ( ) => ForceChangeRate . ParseUnit ( "\u03bc N/s" ) ) ;
309
- Assert . Throws < UnitsNetException > ( ( ) => ForcePerLength . ParseUnit ( "\u03bc N/m" ) ) ;
310
- Assert . Throws < UnitsNetException > ( ( ) => KinematicViscosity . ParseUnit ( "\u03bc St" ) ) ;
311
- Assert . Throws < UnitsNetException > ( ( ) => Length . ParseUnit ( "\u03bc in" ) ) ;
312
- Assert . Throws < UnitsNetException > ( ( ) => Length . ParseUnit ( "\u03bc m" ) ) ;
313
- Assert . Throws < UnitsNetException > ( ( ) => MassFlow . ParseUnit ( "\u03bc g/S" ) ) ;
314
- Assert . Throws < UnitsNetException > ( ( ) => Mass . ParseUnit ( "\u03bc g" ) ) ;
315
- Assert . Throws < UnitsNetException > ( ( ) => Power . ParseUnit ( "\u03bc W" ) ) ;
316
- Assert . Throws < UnitsNetException > ( ( ) => Pressure . ParseUnit ( "\u03bc Pa" ) ) ;
317
- Assert . Throws < UnitsNetException > ( ( ) => RotationalSpeed . ParseUnit ( "\u03bc °/s" ) ) ;
318
- Assert . Throws < UnitsNetException > ( ( ) => RotationalSpeed . ParseUnit ( "\u03bc rad/s" ) ) ;
319
- Assert . Throws < UnitsNetException > ( ( ) => Speed . ParseUnit ( "\u03bc m/min" ) ) ;
320
- Assert . Throws < UnitsNetException > ( ( ) => Speed . ParseUnit ( "\u03bc m/s" ) ) ;
321
- Assert . Throws < UnitsNetException > ( ( ) => TemperatureChangeRate . ParseUnit ( "\u03bc °C/s" ) ) ;
322
- Assert . Throws < UnitsNetException > ( ( ) => Volume . ParseUnit ( "\u03bc l" ) ) ;
323
- Assert . Throws < UnitsNetException > ( ( ) => Volume . ParseUnit ( "\u03bc m³" ) ) ;
296
+ Assert . Throws < UnitNotFoundException > ( ( ) => Acceleration . ParseUnit ( "\u03bc m/s²" ) ) ;
297
+ Assert . Throws < UnitNotFoundException > ( ( ) => AmplitudeRatio . ParseUnit ( "dB\u03bc V" ) ) ;
298
+ Assert . Throws < UnitNotFoundException > ( ( ) => Angle . ParseUnit ( "\u03bc °" ) ) ;
299
+ Assert . Throws < UnitNotFoundException > ( ( ) => Angle . ParseUnit ( "\u03bc rad" ) ) ;
300
+ Assert . Throws < UnitNotFoundException > ( ( ) => Area . ParseUnit ( "\u03bc m²" ) ) ;
301
+ Assert . Throws < UnitNotFoundException > ( ( ) => Duration . ParseUnit ( "\u03bc s" ) ) ;
302
+ Assert . Throws < UnitNotFoundException > ( ( ) => ElectricCurrent . ParseUnit ( "\u03bc A" ) ) ;
303
+ Assert . Throws < UnitNotFoundException > ( ( ) => ElectricPotential . ParseUnit ( "\u03bc V" ) ) ;
304
+ Assert . Throws < UnitNotFoundException > ( ( ) => Flow . ParseUnit ( "\u03bc LPM" ) ) ;
305
+ Assert . Throws < UnitNotFoundException > ( ( ) => ForceChangeRate . ParseUnit ( "\u03bc N/s" ) ) ;
306
+ Assert . Throws < UnitNotFoundException > ( ( ) => ForcePerLength . ParseUnit ( "\u03bc N/m" ) ) ;
307
+ Assert . Throws < UnitNotFoundException > ( ( ) => KinematicViscosity . ParseUnit ( "\u03bc St" ) ) ;
308
+ Assert . Throws < UnitNotFoundException > ( ( ) => Length . ParseUnit ( "\u03bc in" ) ) ;
309
+ Assert . Throws < UnitNotFoundException > ( ( ) => Length . ParseUnit ( "\u03bc m" ) ) ;
310
+ Assert . Throws < UnitNotFoundException > ( ( ) => MassFlow . ParseUnit ( "\u03bc g/S" ) ) ;
311
+ Assert . Throws < UnitNotFoundException > ( ( ) => Mass . ParseUnit ( "\u03bc g" ) ) ;
312
+ Assert . Throws < UnitNotFoundException > ( ( ) => Power . ParseUnit ( "\u03bc W" ) ) ;
313
+ Assert . Throws < UnitNotFoundException > ( ( ) => Pressure . ParseUnit ( "\u03bc Pa" ) ) ;
314
+ Assert . Throws < UnitNotFoundException > ( ( ) => RotationalSpeed . ParseUnit ( "\u03bc °/s" ) ) ;
315
+ Assert . Throws < UnitNotFoundException > ( ( ) => RotationalSpeed . ParseUnit ( "\u03bc rad/s" ) ) ;
316
+ Assert . Throws < UnitNotFoundException > ( ( ) => Speed . ParseUnit ( "\u03bc m/min" ) ) ;
317
+ Assert . Throws < UnitNotFoundException > ( ( ) => Speed . ParseUnit ( "\u03bc m/s" ) ) ;
318
+ Assert . Throws < UnitNotFoundException > ( ( ) => TemperatureChangeRate . ParseUnit ( "\u03bc °C/s" ) ) ;
319
+ Assert . Throws < UnitNotFoundException > ( ( ) => Volume . ParseUnit ( "\u03bc l" ) ) ;
320
+ Assert . Throws < UnitNotFoundException > ( ( ) => Volume . ParseUnit ( "\u03bc m³" ) ) ;
324
321
}
325
322
326
323
[ Theory ]
@@ -490,7 +487,7 @@ public void NotANumberFormatting()
490
487
[ Fact ]
491
488
public void Parse_AmbiguousUnitsThrowsException ( )
492
489
{
493
- UnitSystem unitSystem = GetCachedUnitSystem ( ) ;
490
+ UnitSystem unitSystem = UnitSystem . Default ;
494
491
495
492
// Act 1
496
493
Assert . Throws < AmbiguousUnitParseException > ( ( ) => unitSystem . Parse < VolumeUnit > ( "tsp" ) ) ;
0 commit comments