Skip to content

Commit 0216e52

Browse files
committed
tests: Remove UWP specific test code
We no longer run tests for WindowsRuntimeComponent, so removing obsolete #if WINDOWS_UWP pragma regions.
1 parent 3c81c21 commit 0216e52

File tree

3 files changed

+42
-125
lines changed

3 files changed

+42
-125
lines changed

UnitsNet.Tests/Extensions/NumberToTimeSpan/NumberToTimeSpanExtensionsTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
#if !WINDOWS_UWP
2322
using System;
2423
using Xunit;
2524
using UnitsNet.Extensions.NumberToTimeSpan;
@@ -63,4 +62,3 @@ public void ExtensionMethodsReturnTimeSpanOfSameValue()
6362
}
6463
}
6564
}
66-
#endif

UnitsNet.Tests/NumberExtensionsTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
#if !WINDOWS_UWP
2322
using Xunit;
2423
using UnitsNet.Extensions.NumberToAngle;
2524
using UnitsNet.Extensions.NumberToForce;
@@ -40,4 +39,3 @@ public void SomeArbitraryExtensionMethods_CreatesCorrectValue()
4039
}
4140
}
4241
}
43-
#endif

UnitsNet.Tests/UnitSystemTests.cs

Lines changed: 42 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
using Xunit;
2626
using UnitsNet.Units;
2727
using Xunit.Abstractions;
28-
#if WINDOWS_UWP
29-
using Culture=System.String;
30-
#else
3128
using System.Globalization;
32-
using Culture=System.IFormatProvider;
33-
#endif
3429

3530
namespace UnitsNet.Tests
3631
{
@@ -41,6 +36,9 @@ namespace UnitsNet.Tests
4136
public class UnitSystemTests
4237
{
4338
private readonly ITestOutputHelper _output;
39+
private static CultureInfo CultureAmerican => new CultureInfo("en-US");
40+
private static CultureInfo CultureRussian => new CultureInfo("ru-RU");
41+
private static CultureInfo CultureNorwegian => new CultureInfo("nb-NO");
4442

4543
public UnitSystemTests(ITestOutputHelper output)
4644
{
@@ -56,12 +54,7 @@ public UnitSystemTests(ITestOutputHelper output)
5654
[InlineData(0.115, "0.12 m")]
5755
public void DefaultToStringFormatting(double value, string expected)
5856
{
59-
#if WINDOWS_UWP
60-
Culture cultureEnUs = "en-US";
61-
#else
62-
Culture cultureEnUs = new CultureInfo("en-US");
63-
#endif
64-
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, cultureEnUs);
57+
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, CultureAmerican);
6558
Assert.Equal(expected, actual);
6659
}
6760

@@ -85,11 +78,7 @@ private static IEnumerable<object> GetUnitTypesWithMissingAbbreviations<TUnitTyp
8578
{
8679
try
8780
{
88-
#if WINDOWS_UWP
89-
unitSystem.GetDefaultAbbreviation(unit.GetType(), Convert.ToInt32(unit));
90-
#else
9181
unitSystem.GetDefaultAbbreviation(unit);
92-
#endif
9382
}
9483
catch
9584
{
@@ -133,7 +122,7 @@ public void DecimalRadixPointCultureFormatting(string culture)
133122
[InlineData("es-MX")]
134123
public void CommaDigitGroupingCultureFormatting(string cultureName)
135124
{
136-
Culture culture = GetCulture(cultureName);
125+
CultureInfo culture = GetCulture(cultureName);
137126
Assert.Equal("1,111 m", Length.FromMeters(1111).ToString(LengthUnit.Meter, culture));
138127

139128
// Feet/Inch and Stone/Pound combinations are only used (customarily) in the US, UK and maybe Ireland - all English speaking countries.
@@ -154,14 +143,6 @@ public void SpaceDigitGroupingCultureFormatting(string culture)
154143
Assert.Equal("1 111 m", Length.FromMeters(1111).ToString(LengthUnit.Meter, GetCulture(culture)));
155144
}
156145

157-
// Switzerland uses an apostrophe for digit grouping
158-
// [Ignore("Fails on Win 8.1 and Win10 due to a bug in .NET framework.")]
159-
// [InlineData("fr-CH")]
160-
// public void ApostropheDigitGroupingCultureFormatting(string culture)
161-
// {
162-
// Assert.Equal("1'111 m", Length.FromMeters(1111).ToString(LengthUnit.Meter, new CultureInfo(culture)));
163-
// }
164-
165146
// These cultures all use a decimal point in digit grouping
166147
[Theory]
167148
[InlineData("de-DE")]
@@ -174,7 +155,6 @@ public void DecimalPointDigitGroupingCultureFormatting(string culture)
174155
Assert.Equal("1.111 m", Length.FromMeters(1111).ToString(LengthUnit.Meter, GetCulture(culture)));
175156
}
176157

177-
#if !WINDOWS_UWP
178158
[Theory]
179159
[InlineData("m^^2", AreaUnit.SquareMeter)]
180160
[InlineData("cm^^2", AreaUnit.SquareCentimeter)]
@@ -191,7 +171,6 @@ public void Parse_UnknownAbbreviationThrowsUnitNotFoundException()
191171
{
192172
Assert.Throws<UnitNotFoundException>(() => UnitSystem.Default.Parse<AreaUnit>("nonexistingunit"));
193173
}
194-
#endif
195174

196175
[Theory]
197176
[InlineData(1, "1.1 m")]
@@ -202,12 +181,7 @@ public void Parse_UnknownAbbreviationThrowsUnitNotFoundException()
202181
[InlineData(6, "1.123457 m")]
203182
public void CustomNumberOfSignificantDigitsAfterRadixFormatting(int significantDigitsAfterRadix, string expected)
204183
{
205-
#if WINDOWS_UWP
206-
Culture cultureEnUs = "en-US";
207-
#else
208-
Culture cultureEnUs = new CultureInfo("en-US");
209-
#endif
210-
string actual = Length.FromMeters(1.123456789).ToString(LengthUnit.Meter, cultureEnUs, significantDigitsAfterRadix);
184+
string actual = Length.FromMeters(1.123456789).ToString(LengthUnit.Meter, CultureAmerican, significantDigitsAfterRadix);
211185
Assert.Equal(expected, actual);
212186
}
213187

@@ -222,12 +196,7 @@ public void CustomNumberOfSignificantDigitsAfterRadixFormatting(int significantD
222196
public void RoundingErrorsWithSignificantDigitsAfterRadixFormatting(double value,
223197
int maxSignificantDigitsAfterRadix, string expected)
224198
{
225-
#if WINDOWS_UWP
226-
Culture cultureEnUs = "en-US";
227-
#else
228-
Culture cultureEnUs = new CultureInfo("en-US");
229-
#endif
230-
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, cultureEnUs, maxSignificantDigitsAfterRadix);
199+
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, CultureAmerican, maxSignificantDigitsAfterRadix);
231200
Assert.Equal(expected, actual);
232201
}
233202

@@ -239,12 +208,7 @@ public void RoundingErrorsWithSignificantDigitsAfterRadixFormatting(double value
239208
[InlineData(1.99e-4, "1.99e-04 m")]
240209
public void ScientificNotationLowerInterval(double value, string expected)
241210
{
242-
#if WINDOWS_UWP
243-
Culture cultureEnUs = "en-US";
244-
#else
245-
Culture cultureEnUs = new CultureInfo("en-US");
246-
#endif
247-
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, cultureEnUs);
211+
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, CultureAmerican);
248212
Assert.Equal(expected, actual);
249213
}
250214

@@ -255,12 +219,7 @@ public void ScientificNotationLowerInterval(double value, string expected)
255219
[InlineData(999.99, "999.99 m")]
256220
public void FixedPointNotationIntervalFormatting(double value, string expected)
257221
{
258-
#if WINDOWS_UWP
259-
Culture cultureEnUs = "en-US";
260-
#else
261-
Culture cultureEnUs = new CultureInfo("en-US");
262-
#endif
263-
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, cultureEnUs);
222+
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, CultureAmerican);
264223
Assert.Equal(expected, actual);
265224
}
266225

@@ -272,12 +231,7 @@ public void FixedPointNotationIntervalFormatting(double value, string expected)
272231
[InlineData(999999.99, "999,999.99 m")]
273232
public void FixedPointNotationWithDigitGroupingIntervalFormatting(double value, string expected)
274233
{
275-
#if WINDOWS_UWP
276-
Culture cultureEnUs = "en-US";
277-
#else
278-
Culture cultureEnUs = new CultureInfo("en-US");
279-
#endif
280-
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, cultureEnUs);
234+
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, CultureAmerican);
281235
Assert.Equal(expected, actual);
282236
}
283237

@@ -288,12 +242,7 @@ public void FixedPointNotationWithDigitGroupingIntervalFormatting(double value,
288242
[InlineData(double.MaxValue, "1.8e+308 m")]
289243
public void ScientificNotationUpperIntervalFormatting(double value, string expected)
290244
{
291-
#if WINDOWS_UWP
292-
Culture cultureEnUs = "en-US";
293-
#else
294-
Culture cultureEnUs = new CultureInfo("en-US");
295-
#endif
296-
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, cultureEnUs);
245+
string actual = Length.FromMeters(value).ToString(LengthUnit.Meter, CultureAmerican);
297246
Assert.Equal(expected, actual);
298247
}
299248

@@ -417,73 +366,56 @@ public void AllUnitsImplementToStringForInvariantCulture()
417366
[Fact]
418367
public void ToString_WithNorwegianCulture()
419368
{
420-
#if WINDOWS_UWP
421-
Culture norwegian = "nb-NO";
422-
#else
423-
Culture norwegian = new CultureInfo("nb-NO");
424-
#endif
425-
Assert.Equal("1 °", Angle.FromDegrees(1).ToString(AngleUnit.Degree, norwegian));
426-
Assert.Equal("1 m²", Area.FromSquareMeters(1).ToString(AreaUnit.SquareMeter, norwegian));
427-
Assert.Equal("1 V", ElectricPotential.FromVolts(1).ToString(ElectricPotentialUnit.Volt, norwegian));
428-
Assert.Equal("1 m³/s", Flow.FromCubicMetersPerSecond(1).ToString(FlowUnit.CubicMeterPerSecond, norwegian));
429-
Assert.Equal("1 N", Force.FromNewtons(1).ToString(ForceUnit.Newton, norwegian));
430-
Assert.Equal("1 m", Length.FromMeters(1).ToString(LengthUnit.Meter, norwegian));
431-
Assert.Equal("1 kg", Mass.FromKilograms(1).ToString(MassUnit.Kilogram, norwegian));
432-
Assert.Equal("1 Pa", Pressure.FromPascals(1).ToString(PressureUnit.Pascal, norwegian));
433-
Assert.Equal("1 rad/s", RotationalSpeed.FromRadiansPerSecond(1).ToString(RotationalSpeedUnit.RadianPerSecond, norwegian));
434-
Assert.Equal("1 K", Temperature.FromKelvins(1).ToString(TemperatureUnit.Kelvin, norwegian));
435-
Assert.Equal("1 N·m", Torque.FromNewtonMeters(1).ToString(TorqueUnit.NewtonMeter, norwegian));
436-
Assert.Equal("1 m³", Volume.FromCubicMeters(1).ToString(VolumeUnit.CubicMeter, norwegian));
369+
Assert.Equal("1 °", Angle.FromDegrees(1).ToString(AngleUnit.Degree, CultureNorwegian));
370+
Assert.Equal("1 m²", Area.FromSquareMeters(1).ToString(AreaUnit.SquareMeter, CultureNorwegian));
371+
Assert.Equal("1 V", ElectricPotential.FromVolts(1).ToString(ElectricPotentialUnit.Volt, CultureNorwegian));
372+
Assert.Equal("1 m³/s", Flow.FromCubicMetersPerSecond(1).ToString(FlowUnit.CubicMeterPerSecond, CultureNorwegian));
373+
Assert.Equal("1 N", Force.FromNewtons(1).ToString(ForceUnit.Newton, CultureNorwegian));
374+
Assert.Equal("1 m", Length.FromMeters(1).ToString(LengthUnit.Meter, CultureNorwegian));
375+
Assert.Equal("1 kg", Mass.FromKilograms(1).ToString(MassUnit.Kilogram, CultureNorwegian));
376+
Assert.Equal("1 Pa", Pressure.FromPascals(1).ToString(PressureUnit.Pascal, CultureNorwegian));
377+
Assert.Equal("1 rad/s", RotationalSpeed.FromRadiansPerSecond(1).ToString(RotationalSpeedUnit.RadianPerSecond, CultureNorwegian));
378+
Assert.Equal("1 K", Temperature.FromKelvins(1).ToString(TemperatureUnit.Kelvin, CultureNorwegian));
379+
Assert.Equal("1 N·m", Torque.FromNewtonMeters(1).ToString(TorqueUnit.NewtonMeter, CultureNorwegian));
380+
Assert.Equal("1 m³", Volume.FromCubicMeters(1).ToString(VolumeUnit.CubicMeter, CultureNorwegian));
437381
}
438382

439383
[Fact]
440384
public void ToString_WithRussianCulture()
441385
{
442-
#if WINDOWS_UWP
443-
Culture russian = "ru-RU";
444-
#else
445-
Culture russian = new CultureInfo( "ru-RU");
446-
#endif
447-
Assert.Equal("1 °", Angle.FromDegrees(1).ToString(AngleUnit.Degree, russian));
448-
Assert.Equal("1 м²", Area.FromSquareMeters(1).ToString(AreaUnit.SquareMeter, russian));
449-
Assert.Equal("1 В", ElectricPotential.FromVolts(1).ToString(ElectricPotentialUnit.Volt, russian));
450-
Assert.Equal("1 м³/с", Flow.FromCubicMetersPerSecond(1).ToString(FlowUnit.CubicMeterPerSecond, russian));
451-
Assert.Equal("1 Н", Force.FromNewtons(1).ToString(ForceUnit.Newton, russian));
452-
Assert.Equal("1 м", Length.FromMeters(1).ToString(LengthUnit.Meter, russian));
453-
Assert.Equal("1 кг", Mass.FromKilograms(1).ToString(MassUnit.Kilogram, russian));
454-
Assert.Equal("1 Па", Pressure.FromPascals(1).ToString(PressureUnit.Pascal, russian));
455-
Assert.Equal("1 рад/с", RotationalSpeed.FromRadiansPerSecond(1).ToString(RotationalSpeedUnit.RadianPerSecond, russian));
456-
Assert.Equal("1 K", Temperature.FromKelvins(1).ToString(TemperatureUnit.Kelvin, russian));
457-
Assert.Equal("1 Н·м", Torque.FromNewtonMeters(1).ToString(TorqueUnit.NewtonMeter, russian));
458-
Assert.Equal("1 м³", Volume.FromCubicMeters(1).ToString(VolumeUnit.CubicMeter, russian));
386+
Assert.Equal("1 °", Angle.FromDegrees(1).ToString(AngleUnit.Degree, CultureRussian));
387+
Assert.Equal("1 м²", Area.FromSquareMeters(1).ToString(AreaUnit.SquareMeter, CultureRussian));
388+
Assert.Equal("1 В", ElectricPotential.FromVolts(1).ToString(ElectricPotentialUnit.Volt, CultureRussian));
389+
Assert.Equal("1 м³/с", Flow.FromCubicMetersPerSecond(1).ToString(FlowUnit.CubicMeterPerSecond, CultureRussian));
390+
Assert.Equal("1 Н", Force.FromNewtons(1).ToString(ForceUnit.Newton, CultureRussian));
391+
Assert.Equal("1 м", Length.FromMeters(1).ToString(LengthUnit.Meter, CultureRussian));
392+
Assert.Equal("1 кг", Mass.FromKilograms(1).ToString(MassUnit.Kilogram, CultureRussian));
393+
Assert.Equal("1 Па", Pressure.FromPascals(1).ToString(PressureUnit.Pascal, CultureRussian));
394+
Assert.Equal("1 рад/с", RotationalSpeed.FromRadiansPerSecond(1).ToString(RotationalSpeedUnit.RadianPerSecond, CultureRussian));
395+
Assert.Equal("1 K", Temperature.FromKelvins(1).ToString(TemperatureUnit.Kelvin, CultureRussian));
396+
Assert.Equal("1 Н·м", Torque.FromNewtonMeters(1).ToString(TorqueUnit.NewtonMeter, CultureRussian));
397+
Assert.Equal("1 м³", Volume.FromCubicMeters(1).ToString(VolumeUnit.CubicMeter, CultureRussian));
459398
}
460399

461400
[Fact]
462401
public void GetDefaultAbbreviationFallsBackToDefaultStringIfNotSpecified()
463402
{
464-
UnitSystem usUnits = UnitSystem.GetCached(GetCulture("en-US"));
465-
466-
#if WINDOWS_UWP
467-
string abbreviation = usUnits.GetDefaultAbbreviation(typeof(CustomUnit), (int)CustomUnit.Unit1);
468-
Assert.Equal("(no abbreviation for CustomUnit with numeric value 1)", abbreviation);
469-
#else
403+
UnitSystem usUnits = UnitSystem.GetCached(CultureAmerican);
470404
string abbreviation = usUnits.GetDefaultAbbreviation(CustomUnit.Unit1);
471405
Assert.Equal("(no abbreviation for CustomUnit.Unit1)", abbreviation);
472-
#endif
473406
}
474407

475-
#if !WINDOWS_UWP
476408
[Fact]
477409
public void GetDefaultAbbreviationFallsBackToUsEnglishCulture()
478410
{
479411
// CurrentCulture affects number formatting, such as comma or dot as decimal separator.
480412
// CurrentUICulture affects localization, in this case the abbreviation.
481413
// Zulu (South Africa)
482-
CultureInfo zuluCulture = new CultureInfo("zu-ZA");
414+
var zuluCulture = new CultureInfo("zu-ZA");
483415
UnitSystem zuluUnits = UnitSystem.GetCached(zuluCulture);
484416
CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = zuluCulture;
485417

486-
UnitSystem usUnits = UnitSystem.GetCached(new CultureInfo("en-US"));
418+
UnitSystem usUnits = UnitSystem.GetCached(CultureAmerican);
487419
usUnits.MapUnitToAbbreviation(CustomUnit.Unit1, "US english abbreviation for Unit1");
488420

489421
// Act
@@ -492,19 +424,15 @@ public void GetDefaultAbbreviationFallsBackToUsEnglishCulture()
492424
// Assert
493425
Assert.Equal("US english abbreviation for Unit1", abbreviation);
494426
}
495-
#endif
496427

497-
#if !WINDOWS_UWP
498428
[Fact]
499429
public void MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviationForAlreadyMappedUnits()
500430
{
501-
CultureInfo cultureInfo = new CultureInfo("en-US");
502-
UnitSystem unitSystem = UnitSystem.GetCached(cultureInfo);
431+
UnitSystem unitSystem = UnitSystem.GetCached(CultureAmerican);
503432
unitSystem.MapUnitToAbbreviation(AreaUnit.SquareMeter, "m^2");
504433

505434
Assert.Equal("m²", unitSystem.GetDefaultAbbreviation(AreaUnit.SquareMeter));
506435
}
507-
#endif
508436

509437
[Fact]
510438
public void NegativeInfinityFormatting()
@@ -518,7 +446,6 @@ public void NotANumberFormatting()
518446
Assert.Equal("NaN m", Length.FromMeters(double.NaN).ToString());
519447
}
520448

521-
#if !WINDOWS_UWP
522449
[Fact]
523450
public void Parse_AmbiguousUnitsThrowsException()
524451
{
@@ -530,7 +457,6 @@ public void Parse_AmbiguousUnitsThrowsException()
530457
// Act 2
531458
Assert.Throws<AmbiguousUnitParseException>(() => Volume.Parse("1 tsp"));
532459
}
533-
#endif
534460

535461
[Fact]
536462
public void Parse_UnambiguousUnitsDoesNotThrow()
@@ -547,16 +473,11 @@ public void PositiveInfinityFormatting()
547473
}
548474

549475
/// <summary>
550-
/// Convenience method to use the proper culture parameter type.
551-
/// The UWP lib uses culture name string instead of CultureInfo.
476+
/// Convenience method to the proper culture parameter type.
552477
/// </summary>
553-
private static Culture GetCulture(string cultureName)
478+
private static CultureInfo GetCulture(string cultureName)
554479
{
555-
#if WINDOWS_UWP
556-
return cultureName;
557-
#else
558480
return new CultureInfo(cultureName);
559-
#endif
560481
}
561482
}
562-
}
483+
}

0 commit comments

Comments
 (0)