From 60982b5e8c9029664fcad16e82897cccca517253 Mon Sep 17 00:00:00 2001 From: lipchev Date: Sat, 4 Jan 2025 18:08:24 +0200 Subject: [PATCH] Improving the ToUnit test coverage - ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit now also tests the non-base to non-base conversions - ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit is no longer skipped for quantities with a single unit (the test is still generated) - added the ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity test: covering the IQuantity interfaces - added the Convert_GetTypeCode_Returns_Object test (completing the IConvertible interface coverage) - IQuantity tests: removed the redundant UnitSystem tests and updated "wrong unit type" tests, using all quantities --- .../UnitsNetGen/UnitTestBaseClassGenerator.cs | 40 +++++++++++++--- UnitsNet.Tests/CustomCode/IQuantityTests.cs | 48 ++++--------------- ...orbedDoseOfIonizingRadiationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/AccelerationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/AmountOfSubstanceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/AmplitudeRatioTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/AngleTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/AreaDensityTestsBase.g.cs | 38 ++++++++++++--- .../AreaMomentOfInertiaTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/AreaTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/BitRateTestsBase.g.cs | 38 ++++++++++++--- ...BrakeSpecificFuelConsumptionTestsBase.g.cs | 38 ++++++++++++--- ...oefficientOfThermalExpansionTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/CompressibilityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/DensityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/DoseAreaProductTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/DurationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/DynamicViscosityTestsBase.g.cs | 38 ++++++++++++--- .../ElectricAdmittanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricApparentEnergyTestsBase.g.cs | 38 ++++++++++++--- .../ElectricApparentPowerTestsBase.g.cs | 38 ++++++++++++--- .../ElectricCapacitanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricChargeDensityTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/ElectricChargeTestsBase.g.cs | 38 ++++++++++++--- .../ElectricConductanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricConductivityTestsBase.g.cs | 38 ++++++++++++--- .../ElectricCurrentDensityTestsBase.g.cs | 38 ++++++++++++--- .../ElectricCurrentGradientTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ElectricCurrentTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ElectricFieldTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/ElectricImpedanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricInductanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricPotentialChangeRateTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ElectricPotentialTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ElectricReactanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricReactiveEnergyTestsBase.g.cs | 38 ++++++++++++--- .../ElectricReactivePowerTestsBase.g.cs | 38 ++++++++++++--- .../ElectricResistanceTestsBase.g.cs | 38 ++++++++++++--- .../ElectricResistivityTestsBase.g.cs | 38 ++++++++++++--- ...ElectricSurfaceChargeDensityTestsBase.g.cs | 38 ++++++++++++--- .../ElectricSusceptanceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/EnergyDensityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/EnergyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/EntropyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ForceChangeRateTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ForcePerLengthTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ForceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/FrequencyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/FuelEfficiencyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/HeatFluxTestsBase.g.cs | 38 ++++++++++++--- .../HeatTransferCoefficientTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/IlluminanceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ImpulseTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/InformationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/IrradianceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/IrradiationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/JerkTestsBase.g.cs | 38 ++++++++++++--- .../KinematicViscosityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LeakRateTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LengthTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LevelTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LinearDensityTestsBase.g.cs | 38 ++++++++++++--- .../LinearPowerDensityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LuminanceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LuminosityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/LuminousFluxTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/LuminousIntensityTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/MagneticFieldTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MagneticFluxTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/MagnetizationTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/MassConcentrationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MassFlowTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MassFluxTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MassFractionTestsBase.g.cs | 38 ++++++++++++--- .../MassMomentOfInertiaTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MassTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MolalityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MolarEnergyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MolarEntropyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MolarFlowTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MolarMassTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/MolarityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/PermeabilityTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/PermittivityTestsBase.g.cs | 40 +++++++++++++--- .../PorousMediumPermeabilityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/PowerDensityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/PowerRatioTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/PowerTestsBase.g.cs | 38 ++++++++++++--- .../PressureChangeRateTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/PressureTestsBase.g.cs | 38 ++++++++++++--- .../RadiationEquivalentDoseRateTestsBase.g.cs | 38 ++++++++++++--- .../RadiationEquivalentDoseTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/RadiationExposureTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/RadioactivityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/RatioChangeRateTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/RatioTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ReciprocalAreaTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ReciprocalLengthTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/RelativeHumidityTestsBase.g.cs | 40 +++++++++++++--- .../RotationalAccelerationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/RotationalSpeedTestsBase.g.cs | 38 ++++++++++++--- ...RotationalStiffnessPerLengthTestsBase.g.cs | 38 ++++++++++++--- .../RotationalStiffnessTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ScalarTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/SolidAngleTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/SpecificEnergyTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/SpecificEntropyTestsBase.g.cs | 38 ++++++++++++--- .../SpecificFuelConsumptionTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/SpecificVolumeTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/SpecificWeightTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/SpeedTestsBase.g.cs | 38 ++++++++++++--- .../StandardVolumeFlowTestsBase.g.cs | 38 ++++++++++++--- .../TemperatureChangeRateTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/TemperatureDeltaTestsBase.g.cs | 38 ++++++++++++--- .../TemperatureGradientTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/TemperatureTestsBase.g.cs | 38 ++++++++++++--- .../ThermalConductivityTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/ThermalInsulanceTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/TorqueTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/TurbidityTestsBase.g.cs | 40 +++++++++++++--- .../TestsBase/VitaminATestsBase.g.cs | 40 +++++++++++++--- .../VolumeConcentrationTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/VolumeFlowPerAreaTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/VolumeFlowTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/VolumePerLengthTestsBase.g.cs | 38 ++++++++++++--- .../TestsBase/VolumeTestsBase.g.cs | 38 ++++++++++++--- .../VolumetricHeatCapacityTestsBase.g.cs | 38 ++++++++++++--- .../WarpingMomentOfInertiaTestsBase.g.cs | 38 ++++++++++++--- 128 files changed, 4087 insertions(+), 815 deletions(-) diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 6f8e55be76..625e9a8661 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -797,16 +797,16 @@ public void ToUnit_WithSameUnits_AreEqual({_unitEnumName} unit) Assert.Equal(quantity, toUnitWithSameUnit); }} - [Theory{(_quantity.Units.Length == 1 ? "(Skip = \"Multiple units required\")" : string.Empty)}] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit({_unitEnumName} unit) {{ - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = {_quantity.Name}.Units.First(u => u != {_quantity.Name}.BaseUnit); - - var quantity = {_quantity.Name}.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All({_quantity.Name}.Units.Where(u => u != {_quantity.Name}.BaseUnit), fromUnit => + {{ + var quantity = {_quantity.Name}.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }}); }} [Theory] @@ -818,6 +818,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit({_un Assert.Equal(converted.Unit, unit); }} + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity({_unitEnumName} unit) + {{ + var quantity = {_quantity.Name}.From(3, {_quantity.Name}.BaseUnit); + {_quantity.Name} expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + {{ + IQuantity<{_unitEnumName}> quantityToConvert = quantity; + IQuantity<{_unitEnumName}> convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }}, () => + {{ + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }}); + }} + [Fact] public void ConversionRoundTrip() {{ @@ -1213,6 +1232,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }} + [Fact] + public void Convert_GetTypeCode_Returns_Object() + {{ + var quantity = {_quantity.Name}.From{_baseUnit.PluralName}(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + }} + [Fact] public void GetHashCode_Equals() {{ diff --git a/UnitsNet.Tests/CustomCode/IQuantityTests.cs b/UnitsNet.Tests/CustomCode/IQuantityTests.cs index 1193a838fa..012f0cc09f 100644 --- a/UnitsNet.Tests/CustomCode/IQuantityTests.cs +++ b/UnitsNet.Tests/CustomCode/IQuantityTests.cs @@ -2,8 +2,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; -using System.Diagnostics.CodeAnalysis; -using UnitsNet.Units; +using System.Linq; using Xunit; namespace UnitsNet.Tests @@ -14,48 +13,19 @@ public partial class IQuantityTests [Fact] public void As_GivenWrongUnitType_ThrowsArgumentException() { - IQuantity length = Length.FromMeters(1.2345); - Assert.Throws(() => length.As(MassUnit.Kilogram)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void As_GivenNullUnitSystem_ThrowsArgumentNullException() - { - IQuantity imperialLengthQuantity = new Length(2.0, LengthUnit.Inch); - Assert.Throws(() => imperialLengthQuantity.As((UnitSystem)null!)); - } - - [Fact] - public void As_GivenSIUnitSystem_ReturnsSIValue() - { - IQuantity inches = new Length(2.0, LengthUnit.Inch); - Assert.Equal(0.0508, inches.As(UnitSystem.SI)); + Assert.All(Quantity.Infos.Select(x => x.Zero), quantity => + { + Assert.Throws(() => quantity.As(ComparisonType.Absolute)); + }); } [Fact] public void ToUnit_GivenWrongUnitType_ThrowsArgumentException() { - IQuantity length = Length.FromMeters(1.2345); - Assert.Throws(() => length.ToUnit(MassUnit.Kilogram)); - } - - [Fact] - public void ToUnit_GivenNullUnitSystem_ThrowsArgumentNullException() - { - IQuantity imperialLengthQuantity = new Length(2.0, LengthUnit.Inch); - Assert.Throws(() => imperialLengthQuantity.ToUnit((UnitSystem)null!)); - } - - [Fact] - public void ToUnit_GivenSIUnitSystem_ReturnsSIQuantity() - { - IQuantity inches = new Length(2.0, LengthUnit.Inch); - - IQuantity inSI = inches.ToUnit(UnitSystem.SI); - - Assert.Equal(0.0508, inSI.Value); - Assert.Equal(LengthUnit.Meter, inSI.Unit); + Assert.All(Quantity.Infos.Select(x => x.Zero), quantity => + { + Assert.Throws(() => quantity.ToUnit(ComparisonType.Absolute)); + }); } } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs index 18ed31d7f7..54fe5270cc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs @@ -1054,12 +1054,12 @@ public void ToUnit_WithSameUnits_AreEqual(AbsorbedDoseOfIonizingRadiationUnit un [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AbsorbedDoseOfIonizingRadiationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = AbsorbedDoseOfIonizingRadiation.Units.First(u => u != AbsorbedDoseOfIonizingRadiation.BaseUnit); - - var quantity = AbsorbedDoseOfIonizingRadiation.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(AbsorbedDoseOfIonizingRadiation.Units.Where(u => u != AbsorbedDoseOfIonizingRadiation.BaseUnit), fromUnit => + { + var quantity = AbsorbedDoseOfIonizingRadiation.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1071,6 +1071,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Abso Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AbsorbedDoseOfIonizingRadiationUnit unit) + { + var quantity = AbsorbedDoseOfIonizingRadiation.From(3, AbsorbedDoseOfIonizingRadiation.BaseUnit); + AbsorbedDoseOfIonizingRadiation expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1462,6 +1481,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = AbsorbedDoseOfIonizingRadiation.FromGrays(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index 0879a6b214..7ac9d92590 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -1030,12 +1030,12 @@ public void ToUnit_WithSameUnits_AreEqual(AccelerationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AccelerationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Acceleration.Units.First(u => u != Acceleration.BaseUnit); - - var quantity = Acceleration.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Acceleration.Units.Where(u => u != Acceleration.BaseUnit), fromUnit => + { + var quantity = Acceleration.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1047,6 +1047,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Acce Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AccelerationUnit unit) + { + var quantity = Acceleration.From(3, Acceleration.BaseUnit); + Acceleration expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1432,6 +1451,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Acceleration.FromMetersPerSecondSquared(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index 49e464382a..8175331fbe 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -873,12 +873,12 @@ public void ToUnit_WithSameUnits_AreEqual(AmountOfSubstanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AmountOfSubstanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = AmountOfSubstance.Units.First(u => u != AmountOfSubstance.BaseUnit); - - var quantity = AmountOfSubstance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(AmountOfSubstance.Units.Where(u => u != AmountOfSubstance.BaseUnit), fromUnit => + { + var quantity = AmountOfSubstance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -890,6 +890,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Amou Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AmountOfSubstanceUnit unit) + { + var quantity = AmountOfSubstance.From(3, AmountOfSubstance.BaseUnit); + AmountOfSubstance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1284,6 +1303,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = AmountOfSubstance.FromMoles(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index f5f8083341..b754916549 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -422,12 +422,12 @@ public void ToUnit_WithSameUnits_AreEqual(AmplitudeRatioUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AmplitudeRatioUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = AmplitudeRatio.Units.First(u => u != AmplitudeRatio.BaseUnit); - - var quantity = AmplitudeRatio.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(AmplitudeRatio.Units.Where(u => u != AmplitudeRatio.BaseUnit), fromUnit => + { + var quantity = AmplitudeRatio.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -439,6 +439,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Ampl Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AmplitudeRatioUnit unit) + { + var quantity = AmplitudeRatio.From(3, AmplitudeRatio.BaseUnit); + AmplitudeRatio expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -798,6 +817,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = AmplitudeRatio.FromDecibelVolts(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index e7055d0a73..79d9a3c444 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -1177,12 +1177,12 @@ public void ToUnit_WithSameUnits_AreEqual(AngleUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AngleUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Angle.Units.First(u => u != Angle.BaseUnit); - - var quantity = Angle.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Angle.Units.Where(u => u != Angle.BaseUnit), fromUnit => + { + var quantity = Angle.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1194,6 +1194,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Angl Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AngleUnit unit) + { + var quantity = Angle.From(3, Angle.BaseUnit); + Angle expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1582,6 +1601,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Angle.FromRadians(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index 05d1bb83d4..62011ec129 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -472,12 +472,12 @@ public void ToUnit_WithSameUnits_AreEqual(AreaDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AreaDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = AreaDensity.Units.First(u => u != AreaDensity.BaseUnit); - - var quantity = AreaDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(AreaDensity.Units.Where(u => u != AreaDensity.BaseUnit), fromUnit => + { + var quantity = AreaDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -489,6 +489,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Area Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AreaDensityUnit unit) + { + var quantity = AreaDensity.From(3, AreaDensity.BaseUnit); + AreaDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -841,6 +860,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 9df6f7ac70..8cda4232ae 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -670,12 +670,12 @@ public void ToUnit_WithSameUnits_AreEqual(AreaMomentOfInertiaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AreaMomentOfInertiaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = AreaMomentOfInertia.Units.First(u => u != AreaMomentOfInertia.BaseUnit); - - var quantity = AreaMomentOfInertia.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(AreaMomentOfInertia.Units.Where(u => u != AreaMomentOfInertia.BaseUnit), fromUnit => + { + var quantity = AreaMomentOfInertia.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -687,6 +687,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Area Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AreaMomentOfInertiaUnit unit) + { + var quantity = AreaMomentOfInertia.From(3, AreaMomentOfInertia.BaseUnit); + AreaMomentOfInertia expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1048,6 +1067,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = AreaMomentOfInertia.FromMetersToTheFourth(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index b89886adb6..2af6f384b2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -1245,12 +1245,12 @@ public void ToUnit_WithSameUnits_AreEqual(AreaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(AreaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Area.Units.First(u => u != Area.BaseUnit); - - var quantity = Area.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Area.Units.Where(u => u != Area.BaseUnit), fromUnit => + { + var quantity = Area.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1262,6 +1262,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Area Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(AreaUnit unit) + { + var quantity = Area.From(3, Area.BaseUnit); + Area expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1647,6 +1666,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Area.FromSquareMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index 576192179b..430c1f4f32 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -1437,12 +1437,12 @@ public void ToUnit_WithSameUnits_AreEqual(BitRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(BitRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = BitRate.Units.First(u => u != BitRate.BaseUnit); - - var quantity = BitRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(BitRate.Units.Where(u => u != BitRate.BaseUnit), fromUnit => + { + var quantity = BitRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1454,6 +1454,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(BitR Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(BitRateUnit unit) + { + var quantity = BitRate.From(3, BitRate.BaseUnit); + BitRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1875,6 +1894,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = BitRate.FromBitsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index 13df892898..4fa88eab3d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(BrakeSpecificFuelConsumptionUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(BrakeSpecificFuelConsumptionUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = BrakeSpecificFuelConsumption.Units.First(u => u != BrakeSpecificFuelConsumption.BaseUnit); - - var quantity = BrakeSpecificFuelConsumption.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(BrakeSpecificFuelConsumption.Units.Where(u => u != BrakeSpecificFuelConsumption.BaseUnit), fromUnit => + { + var quantity = BrakeSpecificFuelConsumption.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Brak Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(BrakeSpecificFuelConsumptionUnit unit) + { + var quantity = BrakeSpecificFuelConsumption.From(3, BrakeSpecificFuelConsumption.BaseUnit); + BrakeSpecificFuelConsumption expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index 79bc06a406..920d7f55a1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -544,12 +544,12 @@ public void ToUnit_WithSameUnits_AreEqual(CoefficientOfThermalExpansionUnit unit [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(CoefficientOfThermalExpansionUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = CoefficientOfThermalExpansion.Units.First(u => u != CoefficientOfThermalExpansion.BaseUnit); - - var quantity = CoefficientOfThermalExpansion.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(CoefficientOfThermalExpansion.Units.Where(u => u != CoefficientOfThermalExpansion.BaseUnit), fromUnit => + { + var quantity = CoefficientOfThermalExpansion.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -561,6 +561,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Coef Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(CoefficientOfThermalExpansionUnit unit) + { + var quantity = CoefficientOfThermalExpansion.From(3, CoefficientOfThermalExpansion.BaseUnit); + CoefficientOfThermalExpansion expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -922,6 +941,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = CoefficientOfThermalExpansion.FromPerKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs index 0f79896816..8c25391d12 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -722,12 +722,12 @@ public void ToUnit_WithSameUnits_AreEqual(CompressibilityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(CompressibilityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Compressibility.Units.First(u => u != Compressibility.BaseUnit); - - var quantity = Compressibility.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Compressibility.Units.Where(u => u != Compressibility.BaseUnit), fromUnit => + { + var quantity = Compressibility.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -739,6 +739,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Comp Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(CompressibilityUnit unit) + { + var quantity = Compressibility.From(3, Compressibility.BaseUnit); + Compressibility expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1103,6 +1122,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index 2693b0e659..7a1537d64e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -2162,12 +2162,12 @@ public void ToUnit_WithSameUnits_AreEqual(DensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(DensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Density.Units.First(u => u != Density.BaseUnit); - - var quantity = Density.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Density.Units.Where(u => u != Density.BaseUnit), fromUnit => + { + var quantity = Density.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -2179,6 +2179,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Dens Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(DensityUnit unit) + { + var quantity = Density.From(3, Density.BaseUnit); + Density expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2690,6 +2709,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Density.FromKilogramsPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs index 31da791da1..311dc0a652 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs @@ -1318,12 +1318,12 @@ public void ToUnit_WithSameUnits_AreEqual(DoseAreaProductUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(DoseAreaProductUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = DoseAreaProduct.Units.First(u => u != DoseAreaProduct.BaseUnit); - - var quantity = DoseAreaProduct.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(DoseAreaProduct.Units.Where(u => u != DoseAreaProduct.BaseUnit), fromUnit => + { + var quantity = DoseAreaProduct.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1335,6 +1335,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Dose Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(DoseAreaProductUnit unit) + { + var quantity = DoseAreaProduct.From(3, DoseAreaProduct.BaseUnit); + DoseAreaProduct expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1738,6 +1757,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = DoseAreaProduct.FromGraySquareMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index 716638d9a6..4f8baa3f68 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -1695,12 +1695,12 @@ public void ToUnit_WithSameUnits_AreEqual(DurationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(DurationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Duration.Units.First(u => u != Duration.BaseUnit); - - var quantity = Duration.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Duration.Units.Where(u => u != Duration.BaseUnit), fromUnit => + { + var quantity = Duration.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1712,6 +1712,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Dura Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(DurationUnit unit) + { + var quantity = Duration.From(3, Duration.BaseUnit); + Duration expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2091,6 +2110,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Duration.FromSeconds(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index 4d1eaa3e17..2ff7d00a15 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -731,12 +731,12 @@ public void ToUnit_WithSameUnits_AreEqual(DynamicViscosityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(DynamicViscosityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = DynamicViscosity.Units.First(u => u != DynamicViscosity.BaseUnit); - - var quantity = DynamicViscosity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(DynamicViscosity.Units.Where(u => u != DynamicViscosity.BaseUnit), fromUnit => + { + var quantity = DynamicViscosity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -748,6 +748,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Dyna Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(DynamicViscosityUnit unit) + { + var quantity = DynamicViscosity.From(3, DynamicViscosity.BaseUnit); + DynamicViscosity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1121,6 +1140,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index b6665ba49a..b750695927 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -830,12 +830,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricAdmittanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricAdmittanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricAdmittance.Units.First(u => u != ElectricAdmittance.BaseUnit); - - var quantity = ElectricAdmittance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricAdmittance.Units.Where(u => u != ElectricAdmittance.BaseUnit), fromUnit => + { + var quantity = ElectricAdmittance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -847,6 +847,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricAdmittanceUnit unit) + { + var quantity = ElectricAdmittance.From(3, ElectricAdmittance.BaseUnit); + ElectricAdmittance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1238,6 +1257,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricAdmittance.FromSiemens(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs index 7a1acab441..fab911cf10 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricApparentEnergyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricApparentEnergyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricApparentEnergy.Units.First(u => u != ElectricApparentEnergy.BaseUnit); - - var quantity = ElectricApparentEnergy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricApparentEnergy.Units.Where(u => u != ElectricApparentEnergy.BaseUnit), fromUnit => + { + var quantity = ElectricApparentEnergy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricApparentEnergyUnit unit) + { + var quantity = ElectricApparentEnergy.From(3, ElectricApparentEnergy.BaseUnit); + ElectricApparentEnergy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs index 0714ffefe0..dab5c9ebc7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs @@ -532,12 +532,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricApparentPowerUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricApparentPowerUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricApparentPower.Units.First(u => u != ElectricApparentPower.BaseUnit); - - var quantity = ElectricApparentPower.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricApparentPower.Units.Where(u => u != ElectricApparentPower.BaseUnit), fromUnit => + { + var quantity = ElectricApparentPower.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -549,6 +549,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricApparentPowerUnit unit) + { + var quantity = ElectricApparentPower.From(3, ElectricApparentPower.BaseUnit); + ElectricApparentPower expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -910,6 +929,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs index 11124fa66d..8c650179c5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs @@ -563,12 +563,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricCapacitanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricCapacitanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricCapacitance.Units.First(u => u != ElectricCapacitance.BaseUnit); - - var quantity = ElectricCapacitance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricCapacitance.Units.Where(u => u != ElectricCapacitance.BaseUnit), fromUnit => + { + var quantity = ElectricCapacitance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -580,6 +580,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricCapacitanceUnit unit) + { + var quantity = ElectricCapacitance.From(3, ElectricCapacitance.BaseUnit); + ElectricCapacitance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -944,6 +963,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index 0d8fac37a3..a821d4445d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricChargeDensityUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricChargeDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricChargeDensity.Units.First(u => u != ElectricChargeDensity.BaseUnit); - - var quantity = ElectricChargeDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricChargeDensity.Units.Where(u => u != ElectricChargeDensity.BaseUnit), fromUnit => + { + var quantity = ElectricChargeDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricChargeDensityUnit unit) + { + var quantity = ElectricChargeDensity.From(3, ElectricChargeDensity.BaseUnit); + ElectricChargeDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricChargeDensity.FromCoulombsPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index 36bda2b288..1d98fc8612 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -747,12 +747,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricChargeUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricChargeUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricCharge.Units.First(u => u != ElectricCharge.BaseUnit); - - var quantity = ElectricCharge.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricCharge.Units.Where(u => u != ElectricCharge.BaseUnit), fromUnit => + { + var quantity = ElectricCharge.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -764,6 +764,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricChargeUnit unit) + { + var quantity = ElectricCharge.From(3, ElectricCharge.BaseUnit); + ElectricCharge expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1140,6 +1159,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricCharge.FromCoulombs(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index 8752f829bd..74d4dfea63 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -830,12 +830,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricConductanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricConductanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricConductance.Units.First(u => u != ElectricConductance.BaseUnit); - - var quantity = ElectricConductance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricConductance.Units.Where(u => u != ElectricConductance.BaseUnit), fromUnit => + { + var quantity = ElectricConductance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -847,6 +847,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricConductanceUnit unit) + { + var quantity = ElectricConductance.From(3, ElectricConductance.BaseUnit); + ElectricConductance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1238,6 +1257,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricConductance.FromSiemens(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index cd8f3f8dc8..5fc7d0c26c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -544,12 +544,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricConductivityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricConductivityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricConductivity.Units.First(u => u != ElectricConductivity.BaseUnit); - - var quantity = ElectricConductivity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricConductivity.Units.Where(u => u != ElectricConductivity.BaseUnit), fromUnit => + { + var quantity = ElectricConductivity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -561,6 +561,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricConductivityUnit unit) + { + var quantity = ElectricConductivity.From(3, ElectricConductivity.BaseUnit); + ElectricConductivity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -922,6 +941,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricConductivity.FromSiemensPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index 085b357359..227eaeeaa4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricCurrentDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricCurrentDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricCurrentDensity.Units.First(u => u != ElectricCurrentDensity.BaseUnit); - - var quantity = ElectricCurrentDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricCurrentDensity.Units.Where(u => u != ElectricCurrentDensity.BaseUnit), fromUnit => + { + var quantity = ElectricCurrentDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricCurrentDensityUnit unit) + { + var quantity = ElectricCurrentDensity.From(3, ElectricCurrentDensity.BaseUnit); + ElectricCurrentDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricCurrentDensity.FromAmperesPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index f722cfd9b8..614baf8e71 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -575,12 +575,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricCurrentGradientUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricCurrentGradientUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricCurrentGradient.Units.First(u => u != ElectricCurrentGradient.BaseUnit); - - var quantity = ElectricCurrentGradient.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricCurrentGradient.Units.Where(u => u != ElectricCurrentGradient.BaseUnit), fromUnit => + { + var quantity = ElectricCurrentGradient.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -592,6 +592,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricCurrentGradientUnit unit) + { + var quantity = ElectricCurrentGradient.From(3, ElectricCurrentGradient.BaseUnit); + ElectricCurrentGradient expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -956,6 +975,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricCurrentGradient.FromAmperesPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index 1f81368431..cb362d8b98 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -625,12 +625,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricCurrentUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricCurrentUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricCurrent.Units.First(u => u != ElectricCurrent.BaseUnit); - - var quantity = ElectricCurrent.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricCurrent.Units.Where(u => u != ElectricCurrent.BaseUnit), fromUnit => + { + var quantity = ElectricCurrent.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -642,6 +642,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricCurrentUnit unit) + { + var quantity = ElectricCurrent.From(3, ElectricCurrent.BaseUnit); + ElectricCurrent expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1012,6 +1031,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricCurrent.FromAmperes(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index 86ec0c7c66..dd51cd898f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricFieldUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricFieldUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricField.Units.First(u => u != ElectricField.BaseUnit); - - var quantity = ElectricField.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricField.Units.Where(u => u != ElectricField.BaseUnit), fromUnit => + { + var quantity = ElectricField.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricFieldUnit unit) + { + var quantity = ElectricField.From(3, ElectricField.BaseUnit); + ElectricField expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricField.FromVoltsPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs index 06d2f0b8bc..a8f3c8e805 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs @@ -594,12 +594,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricImpedanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricImpedanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricImpedance.Units.First(u => u != ElectricImpedance.BaseUnit); - - var quantity = ElectricImpedance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricImpedance.Units.Where(u => u != ElectricImpedance.BaseUnit), fromUnit => + { + var quantity = ElectricImpedance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -611,6 +611,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricImpedanceUnit unit) + { + var quantity = ElectricImpedance.From(3, ElectricImpedance.BaseUnit); + ElectricImpedance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -978,6 +997,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index caadf35b50..60b7a20853 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -513,12 +513,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricInductanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricInductanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricInductance.Units.First(u => u != ElectricInductance.BaseUnit); - - var quantity = ElectricInductance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricInductance.Units.Where(u => u != ElectricInductance.BaseUnit), fromUnit => + { + var quantity = ElectricInductance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -530,6 +530,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricInductanceUnit unit) + { + var quantity = ElectricInductance.From(3, ElectricInductance.BaseUnit); + ElectricInductance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -888,6 +907,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricInductance.FromHenries(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index 6ce145dfa3..38a8cc7ae5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -930,12 +930,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricPotentialChangeRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricPotentialChangeRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricPotentialChangeRate.Units.First(u => u != ElectricPotentialChangeRate.BaseUnit); - - var quantity = ElectricPotentialChangeRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricPotentialChangeRate.Units.Where(u => u != ElectricPotentialChangeRate.BaseUnit), fromUnit => + { + var quantity = ElectricPotentialChangeRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -947,6 +947,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricPotentialChangeRateUnit unit) + { + var quantity = ElectricPotentialChangeRate.From(3, ElectricPotentialChangeRate.BaseUnit); + ElectricPotentialChangeRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1350,6 +1369,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricPotentialChangeRate.FromVoltsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index 247c00c671..55f70751f1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -622,12 +622,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricPotentialUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricPotentialUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricPotential.Units.First(u => u != ElectricPotential.BaseUnit); - - var quantity = ElectricPotential.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricPotential.Units.Where(u => u != ElectricPotential.BaseUnit), fromUnit => + { + var quantity = ElectricPotential.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -639,6 +639,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricPotentialUnit unit) + { + var quantity = ElectricPotential.From(3, ElectricPotential.BaseUnit); + ElectricPotential expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1000,6 +1019,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricPotential.FromVolts(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs index d1b3e5d740..b2dd71648e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs @@ -594,12 +594,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricReactanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricReactanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricReactance.Units.First(u => u != ElectricReactance.BaseUnit); - - var quantity = ElectricReactance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricReactance.Units.Where(u => u != ElectricReactance.BaseUnit), fromUnit => + { + var quantity = ElectricReactance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -611,6 +611,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricReactanceUnit unit) + { + var quantity = ElectricReactance.From(3, ElectricReactance.BaseUnit); + ElectricReactance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -978,6 +997,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs index 435d5a4787..556f310dca 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricReactiveEnergyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricReactiveEnergyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricReactiveEnergy.Units.First(u => u != ElectricReactiveEnergy.BaseUnit); - - var quantity = ElectricReactiveEnergy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricReactiveEnergy.Units.Where(u => u != ElectricReactiveEnergy.BaseUnit), fromUnit => + { + var quantity = ElectricReactiveEnergy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricReactiveEnergyUnit unit) + { + var quantity = ElectricReactiveEnergy.From(3, ElectricReactiveEnergy.BaseUnit); + ElectricReactiveEnergy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs index 04e6e8d630..72beb0eccf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs @@ -482,12 +482,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricReactivePowerUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricReactivePowerUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricReactivePower.Units.First(u => u != ElectricReactivePower.BaseUnit); - - var quantity = ElectricReactivePower.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricReactivePower.Units.Where(u => u != ElectricReactivePower.BaseUnit), fromUnit => + { + var quantity = ElectricReactivePower.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -499,6 +499,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricReactivePowerUnit unit) + { + var quantity = ElectricReactivePower.From(3, ElectricReactivePower.BaseUnit); + ElectricReactivePower expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -854,6 +873,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index 2d5014b75b..07272d603e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -594,12 +594,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricResistanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricResistanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricResistance.Units.First(u => u != ElectricResistance.BaseUnit); - - var quantity = ElectricResistance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricResistance.Units.Where(u => u != ElectricResistance.BaseUnit), fromUnit => + { + var quantity = ElectricResistance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -611,6 +611,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricResistanceUnit unit) + { + var quantity = ElectricResistance.From(3, ElectricResistance.BaseUnit); + ElectricResistance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -978,6 +997,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricResistance.FromOhms(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index 7265586455..bfd4b2e4ac 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -768,12 +768,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricResistivityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricResistivityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricResistivity.Units.First(u => u != ElectricResistivity.BaseUnit); - - var quantity = ElectricResistivity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricResistivity.Units.Where(u => u != ElectricResistivity.BaseUnit), fromUnit => + { + var quantity = ElectricResistivity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -785,6 +785,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricResistivityUnit unit) + { + var quantity = ElectricResistivity.From(3, ElectricResistivity.BaseUnit); + ElectricResistivity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1170,6 +1189,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricResistivity.FromOhmMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index 7594f699c0..82be1d1555 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricSurfaceChargeDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricSurfaceChargeDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricSurfaceChargeDensity.Units.First(u => u != ElectricSurfaceChargeDensity.BaseUnit); - - var quantity = ElectricSurfaceChargeDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricSurfaceChargeDensity.Units.Where(u => u != ElectricSurfaceChargeDensity.BaseUnit), fromUnit => + { + var quantity = ElectricSurfaceChargeDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricSurfaceChargeDensityUnit unit) + { + var quantity = ElectricSurfaceChargeDensity.From(3, ElectricSurfaceChargeDensity.BaseUnit); + ElectricSurfaceChargeDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricSurfaceChargeDensity.FromCoulombsPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs index ccf47c9069..ac2bb67e5a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs @@ -830,12 +830,12 @@ public void ToUnit_WithSameUnits_AreEqual(ElectricSusceptanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricSusceptanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricSusceptance.Units.First(u => u != ElectricSusceptance.BaseUnit); - - var quantity = ElectricSusceptance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ElectricSusceptance.Units.Where(u => u != ElectricSusceptance.BaseUnit), fromUnit => + { + var quantity = ElectricSusceptance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -847,6 +847,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ElectricSusceptanceUnit unit) + { + var quantity = ElectricSusceptance.From(3, ElectricSusceptance.BaseUnit); + ElectricSusceptance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1238,6 +1257,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs index 7fb67c62a8..13320432d5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs @@ -730,12 +730,12 @@ public void ToUnit_WithSameUnits_AreEqual(EnergyDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(EnergyDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = EnergyDensity.Units.First(u => u != EnergyDensity.BaseUnit); - - var quantity = EnergyDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(EnergyDensity.Units.Where(u => u != EnergyDensity.BaseUnit), fromUnit => + { + var quantity = EnergyDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -747,6 +747,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Ener Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(EnergyDensityUnit unit) + { + var quantity = EnergyDensity.From(3, EnergyDensity.BaseUnit); + EnergyDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1126,6 +1145,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = EnergyDensity.FromJoulesPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index 909a56c123..99008357b7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -1943,12 +1943,12 @@ public void ToUnit_WithSameUnits_AreEqual(EnergyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(EnergyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Energy.Units.First(u => u != Energy.BaseUnit); - - var quantity = Energy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Energy.Units.Where(u => u != Energy.BaseUnit), fromUnit => + { + var quantity = Energy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1960,6 +1960,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Ener Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(EnergyUnit unit) + { + var quantity = Energy.From(3, Energy.BaseUnit); + Energy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2423,6 +2442,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Energy.FromJoules(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index f5fbfe9cca..abf2244f6d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -575,12 +575,12 @@ public void ToUnit_WithSameUnits_AreEqual(EntropyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(EntropyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Entropy.Units.First(u => u != Entropy.BaseUnit); - - var quantity = Entropy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Entropy.Units.Where(u => u != Entropy.BaseUnit), fromUnit => + { + var quantity = Entropy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -592,6 +592,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Entr Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(EntropyUnit unit) + { + var quantity = Entropy.From(3, Entropy.BaseUnit); + Entropy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -956,6 +975,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Entropy.FromJoulesPerKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index ebbb0144a3..cf0f1d22fc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -907,12 +907,12 @@ public void ToUnit_WithSameUnits_AreEqual(ForceChangeRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ForceChangeRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ForceChangeRate.Units.First(u => u != ForceChangeRate.BaseUnit); - - var quantity = ForceChangeRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ForceChangeRate.Units.Where(u => u != ForceChangeRate.BaseUnit), fromUnit => + { + var quantity = ForceChangeRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -924,6 +924,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Forc Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ForceChangeRateUnit unit) + { + var quantity = ForceChangeRate.From(3, ForceChangeRate.BaseUnit); + ForceChangeRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1312,6 +1331,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ForceChangeRate.FromNewtonsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index 4cdb03a3e8..d1d91822fd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -1686,12 +1686,12 @@ public void ToUnit_WithSameUnits_AreEqual(ForcePerLengthUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ForcePerLengthUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ForcePerLength.Units.First(u => u != ForcePerLength.BaseUnit); - - var quantity = ForcePerLength.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ForcePerLength.Units.Where(u => u != ForcePerLength.BaseUnit), fromUnit => + { + var quantity = ForcePerLength.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1703,6 +1703,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Forc Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ForcePerLengthUnit unit) + { + var quantity = ForcePerLength.From(3, ForcePerLength.BaseUnit); + ForcePerLength expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2160,6 +2179,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ForcePerLength.FromNewtonsPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 42b2a3ddde..396a09d566 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -1153,12 +1153,12 @@ public void ToUnit_WithSameUnits_AreEqual(ForceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ForceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Force.Units.First(u => u != Force.BaseUnit); - - var quantity = Force.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Force.Units.Where(u => u != Force.BaseUnit), fromUnit => + { + var quantity = Force.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1170,6 +1170,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Forc Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ForceUnit unit) + { + var quantity = Force.From(3, Force.BaseUnit); + Force expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1558,6 +1577,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Force.FromNewtons(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index 0df2755195..2bd6664aaf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -890,12 +890,12 @@ public void ToUnit_WithSameUnits_AreEqual(FrequencyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(FrequencyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Frequency.Units.First(u => u != Frequency.BaseUnit); - - var quantity = Frequency.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Frequency.Units.Where(u => u != Frequency.BaseUnit), fromUnit => + { + var quantity = Frequency.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -907,6 +907,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Freq Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(FrequencyUnit unit) + { + var quantity = Frequency.From(3, Frequency.BaseUnit); + Frequency expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1289,6 +1308,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Frequency.FromHertz(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 57340bb920..e9c06eaa14 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -422,12 +422,12 @@ public void ToUnit_WithSameUnits_AreEqual(FuelEfficiencyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(FuelEfficiencyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = FuelEfficiency.Units.First(u => u != FuelEfficiency.BaseUnit); - - var quantity = FuelEfficiency.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(FuelEfficiency.Units.Where(u => u != FuelEfficiency.BaseUnit), fromUnit => + { + var quantity = FuelEfficiency.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -439,6 +439,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Fuel Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(FuelEfficiencyUnit unit) + { + var quantity = FuelEfficiency.From(3, FuelEfficiency.BaseUnit); + FuelEfficiency expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -794,6 +813,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index 5b8d16e0c8..f8ac807234 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -937,12 +937,12 @@ public void ToUnit_WithSameUnits_AreEqual(HeatFluxUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(HeatFluxUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = HeatFlux.Units.First(u => u != HeatFlux.BaseUnit); - - var quantity = HeatFlux.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(HeatFlux.Units.Where(u => u != HeatFlux.BaseUnit), fromUnit => + { + var quantity = HeatFlux.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -954,6 +954,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Heat Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(HeatFluxUnit unit) + { + var quantity = HeatFlux.From(3, HeatFlux.BaseUnit); + HeatFlux expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1351,6 +1370,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = HeatFlux.FromWattsPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index 5575bdb86c..d882172177 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -702,12 +702,12 @@ public void ToUnit_WithSameUnits_AreEqual(HeatTransferCoefficientUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(HeatTransferCoefficientUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = HeatTransferCoefficient.Units.First(u => u != HeatTransferCoefficient.BaseUnit); - - var quantity = HeatTransferCoefficient.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(HeatTransferCoefficient.Units.Where(u => u != HeatTransferCoefficient.BaseUnit), fromUnit => + { + var quantity = HeatTransferCoefficient.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -719,6 +719,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Heat Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(HeatTransferCoefficientUnit unit) + { + var quantity = HeatTransferCoefficient.From(3, HeatTransferCoefficient.BaseUnit); + HeatTransferCoefficient expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1077,6 +1096,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index 5f754f77c7..2574b7da6a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -470,12 +470,12 @@ public void ToUnit_WithSameUnits_AreEqual(IlluminanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(IlluminanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Illuminance.Units.First(u => u != Illuminance.BaseUnit); - - var quantity = Illuminance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Illuminance.Units.Where(u => u != Illuminance.BaseUnit), fromUnit => + { + var quantity = Illuminance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -487,6 +487,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Illu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(IlluminanceUnit unit) + { + var quantity = Illuminance.From(3, Illuminance.BaseUnit); + Illuminance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -842,6 +861,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Illuminance.FromLux(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs index 99f5cc80b4..ff51e39a53 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs @@ -749,12 +749,12 @@ public void ToUnit_WithSameUnits_AreEqual(ImpulseUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ImpulseUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Impulse.Units.First(u => u != Impulse.BaseUnit); - - var quantity = Impulse.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Impulse.Units.Where(u => u != Impulse.BaseUnit), fromUnit => + { + var quantity = Impulse.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -766,6 +766,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Impu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ImpulseUnit unit) + { + var quantity = Impulse.From(3, Impulse.BaseUnit); + Impulse expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1148,6 +1167,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Impulse.FromNewtonSeconds(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index 9f7b01ec00..e8bdfe75ad 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -948,12 +948,12 @@ public void ToUnit_WithSameUnits_AreEqual(InformationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(InformationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Information.Units.First(u => u != Information.BaseUnit); - - var quantity = Information.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Information.Units.Where(u => u != Information.BaseUnit), fromUnit => + { + var quantity = Information.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -965,6 +965,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Info Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(InformationUnit unit) + { + var quantity = Information.From(3, Information.BaseUnit); + Information expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1386,6 +1405,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Information.FromBits(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index e90ca6d017..24026609c5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -768,12 +768,12 @@ public void ToUnit_WithSameUnits_AreEqual(IrradianceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(IrradianceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Irradiance.Units.First(u => u != Irradiance.BaseUnit); - - var quantity = Irradiance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Irradiance.Units.Where(u => u != Irradiance.BaseUnit), fromUnit => + { + var quantity = Irradiance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -785,6 +785,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Irra Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(IrradianceUnit unit) + { + var quantity = Irradiance.From(3, Irradiance.BaseUnit); + Irradiance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1170,6 +1189,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Irradiance.FromWattsPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index d3af297d7f..a1946bd78b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -637,12 +637,12 @@ public void ToUnit_WithSameUnits_AreEqual(IrradiationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(IrradiationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Irradiation.Units.First(u => u != Irradiation.BaseUnit); - - var quantity = Irradiation.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Irradiation.Units.Where(u => u != Irradiation.BaseUnit), fromUnit => + { + var quantity = Irradiation.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -654,6 +654,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Irra Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(IrradiationUnit unit) + { + var quantity = Irradiation.From(3, Irradiation.BaseUnit); + Irradiation expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1024,6 +1043,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Irradiation.FromJoulesPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs index ea7d46d355..d902463dc6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs @@ -886,12 +886,12 @@ public void ToUnit_WithSameUnits_AreEqual(JerkUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(JerkUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Jerk.Units.First(u => u != Jerk.BaseUnit); - - var quantity = Jerk.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Jerk.Units.Where(u => u != Jerk.BaseUnit), fromUnit => + { + var quantity = Jerk.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -903,6 +903,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Jerk Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(JerkUnit unit) + { + var quantity = Jerk.From(3, Jerk.BaseUnit); + Jerk expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1279,6 +1298,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Jerk.FromMetersPerSecondCubed(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index faef046540..eea29ac09d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -773,12 +773,12 @@ public void ToUnit_WithSameUnits_AreEqual(KinematicViscosityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(KinematicViscosityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = KinematicViscosity.Units.First(u => u != KinematicViscosity.BaseUnit); - - var quantity = KinematicViscosity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(KinematicViscosity.Units.Where(u => u != KinematicViscosity.BaseUnit), fromUnit => + { + var quantity = KinematicViscosity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -790,6 +790,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Kine Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(KinematicViscosityUnit unit) + { + var quantity = KinematicViscosity.From(3, KinematicViscosity.BaseUnit); + KinematicViscosity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1160,6 +1179,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = KinematicViscosity.FromSquareMetersPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs index 750d465020..640291dff1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(LeakRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LeakRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = LeakRate.Units.First(u => u != LeakRate.BaseUnit); - - var quantity = LeakRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(LeakRate.Units.Where(u => u != LeakRate.BaseUnit), fromUnit => + { + var quantity = LeakRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Leak Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LeakRateUnit unit) + { + var quantity = LeakRate.From(3, LeakRate.BaseUnit); + LeakRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = LeakRate.FromPascalCubicMetersPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 0f44ebdec5..df6277822c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -2482,12 +2482,12 @@ public void ToUnit_WithSameUnits_AreEqual(LengthUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LengthUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Length.Units.First(u => u != Length.BaseUnit); - - var quantity = Length.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Length.Units.Where(u => u != Length.BaseUnit), fromUnit => + { + var quantity = Length.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -2499,6 +2499,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Leng Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LengthUnit unit) + { + var quantity = Length.From(3, Length.BaseUnit); + Length expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2968,6 +2987,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Length.FromMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index ba3772249d..94d2ecfeee 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -360,12 +360,12 @@ public void ToUnit_WithSameUnits_AreEqual(LevelUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LevelUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Level.Units.First(u => u != Level.BaseUnit); - - var quantity = Level.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Level.Units.Where(u => u != Level.BaseUnit), fromUnit => + { + var quantity = Level.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -377,6 +377,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Leve Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LevelUnit unit) + { + var quantity = Level.From(3, Level.BaseUnit); + Level expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -730,6 +749,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Level.FromDecibels(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index 5566e59997..7828e2377a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -916,12 +916,12 @@ public void ToUnit_WithSameUnits_AreEqual(LinearDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LinearDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = LinearDensity.Units.First(u => u != LinearDensity.BaseUnit); - - var quantity = LinearDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(LinearDensity.Units.Where(u => u != LinearDensity.BaseUnit), fromUnit => + { + var quantity = LinearDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -933,6 +933,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Line Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LinearDensityUnit unit) + { + var quantity = LinearDensity.From(3, LinearDensity.BaseUnit); + LinearDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1330,6 +1349,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = LinearDensity.FromKilogramsPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index a375280eca..6dad1a592f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -1073,12 +1073,12 @@ public void ToUnit_WithSameUnits_AreEqual(LinearPowerDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LinearPowerDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = LinearPowerDensity.Units.First(u => u != LinearPowerDensity.BaseUnit); - - var quantity = LinearPowerDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(LinearPowerDensity.Units.Where(u => u != LinearPowerDensity.BaseUnit), fromUnit => + { + var quantity = LinearPowerDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1090,6 +1090,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Line Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LinearPowerDensityUnit unit) + { + var quantity = LinearPowerDensity.From(3, LinearPowerDensity.BaseUnit); + LinearPowerDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1508,6 +1527,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = LinearPowerDensity.FromWattsPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs index bfc81d20ce..8fd16a933f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs @@ -668,12 +668,12 @@ public void ToUnit_WithSameUnits_AreEqual(LuminanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LuminanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Luminance.Units.First(u => u != Luminance.BaseUnit); - - var quantity = Luminance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Luminance.Units.Where(u => u != Luminance.BaseUnit), fromUnit => + { + var quantity = Luminance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -685,6 +685,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Lumi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LuminanceUnit unit) + { + var quantity = Luminance.From(3, Luminance.BaseUnit); + Luminance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1058,6 +1077,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Luminance.FromCandelasPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index 714c2a0d25..f0e329c2dc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -768,12 +768,12 @@ public void ToUnit_WithSameUnits_AreEqual(LuminosityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LuminosityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Luminosity.Units.First(u => u != Luminosity.BaseUnit); - - var quantity = Luminosity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Luminosity.Units.Where(u => u != Luminosity.BaseUnit), fromUnit => + { + var quantity = Luminosity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -785,6 +785,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Lumi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LuminosityUnit unit) + { + var quantity = Luminosity.From(3, Luminosity.BaseUnit); + Luminosity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1170,6 +1189,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Luminosity.FromWatts(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index 8776daf591..160e4ebb2e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(LuminousFluxUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LuminousFluxUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = LuminousFlux.Units.First(u => u != LuminousFlux.BaseUnit); - - var quantity = LuminousFlux.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(LuminousFlux.Units.Where(u => u != LuminousFlux.BaseUnit), fromUnit => + { + var quantity = LuminousFlux.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Lumi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LuminousFluxUnit unit) + { + var quantity = LuminousFlux.From(3, LuminousFlux.BaseUnit); + LuminousFlux expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = LuminousFlux.FromLumens(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index 42c3f1146b..8230107c03 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(LuminousIntensityUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LuminousIntensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = LuminousIntensity.Units.First(u => u != LuminousIntensity.BaseUnit); - - var quantity = LuminousIntensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(LuminousIntensity.Units.Where(u => u != LuminousIntensity.BaseUnit), fromUnit => + { + var quantity = LuminousIntensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Lumi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(LuminousIntensityUnit unit) + { + var quantity = LuminousIntensity.From(3, LuminousIntensity.BaseUnit); + LuminousIntensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = LuminousIntensity.FromCandela(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index 6ad548b2da..a4583b5848 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -544,12 +544,12 @@ public void ToUnit_WithSameUnits_AreEqual(MagneticFieldUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MagneticFieldUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MagneticField.Units.First(u => u != MagneticField.BaseUnit); - - var quantity = MagneticField.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MagneticField.Units.Where(u => u != MagneticField.BaseUnit), fromUnit => + { + var quantity = MagneticField.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -561,6 +561,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Magn Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MagneticFieldUnit unit) + { + var quantity = MagneticField.From(3, MagneticField.BaseUnit); + MagneticField expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -922,6 +941,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MagneticField.FromTeslas(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index ffac86b182..4a7304697a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(MagneticFluxUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MagneticFluxUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MagneticFlux.Units.First(u => u != MagneticFlux.BaseUnit); - - var quantity = MagneticFlux.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MagneticFlux.Units.Where(u => u != MagneticFlux.BaseUnit), fromUnit => + { + var quantity = MagneticFlux.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Magn Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MagneticFluxUnit unit) + { + var quantity = MagneticFlux.From(3, MagneticFlux.BaseUnit); + MagneticFlux expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MagneticFlux.FromWebers(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index 8936bda651..5258a826ff 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(MagnetizationUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MagnetizationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Magnetization.Units.First(u => u != Magnetization.BaseUnit); - - var quantity = Magnetization.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Magnetization.Units.Where(u => u != Magnetization.BaseUnit), fromUnit => + { + var quantity = Magnetization.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Magn Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MagnetizationUnit unit) + { + var quantity = Magnetization.From(3, Magnetization.BaseUnit); + Magnetization expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Magnetization.FromAmperesPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index d4c743e9f9..9da05493c0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -1945,12 +1945,12 @@ public void ToUnit_WithSameUnits_AreEqual(MassConcentrationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MassConcentrationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MassConcentration.Units.First(u => u != MassConcentration.BaseUnit); - - var quantity = MassConcentration.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MassConcentration.Units.Where(u => u != MassConcentration.BaseUnit), fromUnit => + { + var quantity = MassConcentration.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1962,6 +1962,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mass Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MassConcentrationUnit unit) + { + var quantity = MassConcentration.From(3, MassConcentration.BaseUnit); + MassConcentration expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2452,6 +2471,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MassConcentration.FromKilogramsPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index 97c190f13e..76c0556516 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -1592,12 +1592,12 @@ public void ToUnit_WithSameUnits_AreEqual(MassFlowUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MassFlowUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MassFlow.Units.First(u => u != MassFlow.BaseUnit); - - var quantity = MassFlow.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MassFlow.Units.Where(u => u != MassFlow.BaseUnit), fromUnit => + { + var quantity = MassFlow.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1609,6 +1609,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mass Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MassFlowUnit unit) + { + var quantity = MassFlow.From(3, MassFlow.BaseUnit); + MassFlow expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2051,6 +2070,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MassFlow.FromGramsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 6d3c806b5e..977dd21715 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -730,12 +730,12 @@ public void ToUnit_WithSameUnits_AreEqual(MassFluxUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MassFluxUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MassFlux.Units.First(u => u != MassFlux.BaseUnit); - - var quantity = MassFlux.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MassFlux.Units.Where(u => u != MassFlux.BaseUnit), fromUnit => + { + var quantity = MassFlux.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -747,6 +747,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mass Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MassFluxUnit unit) + { + var quantity = MassFlux.From(3, MassFlux.BaseUnit); + MassFlux expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1126,6 +1145,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MassFlux.FromKilogramsPerSecondPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index 914e7128ac..bb9e42263e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -1063,12 +1063,12 @@ public void ToUnit_WithSameUnits_AreEqual(MassFractionUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MassFractionUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MassFraction.Units.First(u => u != MassFraction.BaseUnit); - - var quantity = MassFraction.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MassFraction.Units.Where(u => u != MassFraction.BaseUnit), fromUnit => + { + var quantity = MassFraction.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1080,6 +1080,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mass Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MassFractionUnit unit) + { + var quantity = MassFraction.From(3, MassFraction.BaseUnit); + MassFraction expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1495,6 +1514,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MassFraction.FromDecimalFractions(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index 79bd5ec378..b168a77379 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -1226,12 +1226,12 @@ public void ToUnit_WithSameUnits_AreEqual(MassMomentOfInertiaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MassMomentOfInertiaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MassMomentOfInertia.Units.First(u => u != MassMomentOfInertia.BaseUnit); - - var quantity = MassMomentOfInertia.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MassMomentOfInertia.Units.Where(u => u != MassMomentOfInertia.BaseUnit), fromUnit => + { + var quantity = MassMomentOfInertia.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1243,6 +1243,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mass Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MassMomentOfInertiaUnit unit) + { + var quantity = MassMomentOfInertia.From(3, MassMomentOfInertia.BaseUnit); + MassMomentOfInertia expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1670,6 +1689,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MassMomentOfInertia.FromKilogramSquareMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index b7932ac98d..9fcebac55b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -2021,12 +2021,12 @@ public void ToUnit_WithSameUnits_AreEqual(MassUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MassUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Mass.Units.First(u => u != Mass.BaseUnit); - - var quantity = Mass.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Mass.Units.Where(u => u != Mass.BaseUnit), fromUnit => + { + var quantity = Mass.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -2038,6 +2038,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mass Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MassUnit unit) + { + var quantity = Mass.From(3, Mass.BaseUnit); + Mass expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2462,6 +2481,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Mass.FromKilograms(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs index 395c13d8a8..8f39d4fcaa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(MolalityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolalityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Molality.Units.First(u => u != Molality.BaseUnit); - - var quantity = Molality.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Molality.Units.Where(u => u != Molality.BaseUnit), fromUnit => + { + var quantity = Molality.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MolalityUnit unit) + { + var quantity = Molality.From(3, Molality.BaseUnit); + Molality expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Molality.FromMolesPerKilogram(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 67cc78086e..8e18b466cd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(MolarEnergyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolarEnergyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MolarEnergy.Units.First(u => u != MolarEnergy.BaseUnit); - - var quantity = MolarEnergy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MolarEnergy.Units.Where(u => u != MolarEnergy.BaseUnit), fromUnit => + { + var quantity = MolarEnergy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MolarEnergyUnit unit) + { + var quantity = MolarEnergy.From(3, MolarEnergy.BaseUnit); + MolarEnergy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MolarEnergy.FromJoulesPerMole(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index 787d39027d..8e42af44e9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(MolarEntropyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolarEntropyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MolarEntropy.Units.First(u => u != MolarEntropy.BaseUnit); - - var quantity = MolarEntropy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MolarEntropy.Units.Where(u => u != MolarEntropy.BaseUnit), fromUnit => + { + var quantity = MolarEntropy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MolarEntropyUnit unit) + { + var quantity = MolarEntropy.From(3, MolarEntropy.BaseUnit); + MolarEntropy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MolarEntropy.FromJoulesPerMoleKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs index dc38c81c86..f540b48233 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -637,12 +637,12 @@ public void ToUnit_WithSameUnits_AreEqual(MolarFlowUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolarFlowUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MolarFlow.Units.First(u => u != MolarFlow.BaseUnit); - - var quantity = MolarFlow.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MolarFlow.Units.Where(u => u != MolarFlow.BaseUnit), fromUnit => + { + var quantity = MolarFlow.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -654,6 +654,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MolarFlowUnit unit) + { + var quantity = MolarFlow.From(3, MolarFlow.BaseUnit); + MolarFlow expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1024,6 +1043,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MolarFlow.FromMolesPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index 925dfbc2a0..8d3859ffbb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -965,12 +965,12 @@ public void ToUnit_WithSameUnits_AreEqual(MolarMassUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolarMassUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = MolarMass.Units.First(u => u != MolarMass.BaseUnit); - - var quantity = MolarMass.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(MolarMass.Units.Where(u => u != MolarMass.BaseUnit), fromUnit => + { + var quantity = MolarMass.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -982,6 +982,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MolarMassUnit unit) + { + var quantity = MolarMass.From(3, MolarMass.BaseUnit); + MolarMass expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1364,6 +1383,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = MolarMass.FromKilogramsPerMole(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index cf9549b954..3154ffaea6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -867,12 +867,12 @@ public void ToUnit_WithSameUnits_AreEqual(MolarityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(MolarityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Molarity.Units.First(u => u != Molarity.BaseUnit); - - var quantity = Molarity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Molarity.Units.Where(u => u != Molarity.BaseUnit), fromUnit => + { + var quantity = Molarity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -884,6 +884,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Mola Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(MolarityUnit unit) + { + var quantity = Molarity.From(3, Molarity.BaseUnit); + Molarity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1260,6 +1279,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Molarity.FromMolesPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index 58002953dd..c03925b221 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(PermeabilityUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PermeabilityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Permeability.Units.First(u => u != Permeability.BaseUnit); - - var quantity = Permeability.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Permeability.Units.Where(u => u != Permeability.BaseUnit), fromUnit => + { + var quantity = Permeability.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Perm Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PermeabilityUnit unit) + { + var quantity = Permeability.From(3, Permeability.BaseUnit); + Permeability expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Permeability.FromHenriesPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index 4f69102829..9a275f2ee1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -385,16 +385,16 @@ public void ToUnit_WithSameUnits_AreEqual(PermittivityUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PermittivityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Permittivity.Units.First(u => u != Permittivity.BaseUnit); - - var quantity = Permittivity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Permittivity.Units.Where(u => u != Permittivity.BaseUnit), fromUnit => + { + var quantity = Permittivity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -406,6 +406,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Perm Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PermittivityUnit unit) + { + var quantity = Permittivity.From(3, Permittivity.BaseUnit); + Permittivity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Permittivity.FromFaradsPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs index 5d1b7daf2a..54c44e64d2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs @@ -513,12 +513,12 @@ public void ToUnit_WithSameUnits_AreEqual(PorousMediumPermeabilityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PorousMediumPermeabilityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = PorousMediumPermeability.Units.First(u => u != PorousMediumPermeability.BaseUnit); - - var quantity = PorousMediumPermeability.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(PorousMediumPermeability.Units.Where(u => u != PorousMediumPermeability.BaseUnit), fromUnit => + { + var quantity = PorousMediumPermeability.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -530,6 +530,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Poro Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PorousMediumPermeabilityUnit unit) + { + var quantity = PorousMediumPermeability.From(3, PorousMediumPermeability.BaseUnit); + PorousMediumPermeability expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -888,6 +907,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = PorousMediumPermeability.FromSquareMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index 335817ec18..65c5bf70a8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -1674,12 +1674,12 @@ public void ToUnit_WithSameUnits_AreEqual(PowerDensityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PowerDensityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = PowerDensity.Units.First(u => u != PowerDensity.BaseUnit); - - var quantity = PowerDensity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(PowerDensity.Units.Where(u => u != PowerDensity.BaseUnit), fromUnit => + { + var quantity = PowerDensity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1691,6 +1691,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Powe Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PowerDensityUnit unit) + { + var quantity = PowerDensity.From(3, PowerDensity.BaseUnit); + PowerDensity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2166,6 +2185,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = PowerDensity.FromWattsPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index 35fefce68a..6d91953ce4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -381,12 +381,12 @@ public void ToUnit_WithSameUnits_AreEqual(PowerRatioUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PowerRatioUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = PowerRatio.Units.First(u => u != PowerRatio.BaseUnit); - - var quantity = PowerRatio.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(PowerRatio.Units.Where(u => u != PowerRatio.BaseUnit), fromUnit => + { + var quantity = PowerRatio.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -398,6 +398,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Powe Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PowerRatioUnit unit) + { + var quantity = PowerRatio.From(3, PowerRatio.BaseUnit); + PowerRatio expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -751,6 +770,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = PowerRatio.FromDecibelWatts(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index 134ea0d6a5..a58c390dde 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -1222,12 +1222,12 @@ public void ToUnit_WithSameUnits_AreEqual(PowerUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PowerUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Power.Units.First(u => u != Power.BaseUnit); - - var quantity = Power.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Power.Units.Where(u => u != Power.BaseUnit), fromUnit => + { + var quantity = Power.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1239,6 +1239,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Powe Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PowerUnit unit) + { + var quantity = Power.From(3, Power.BaseUnit); + Power expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1663,6 +1682,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Power.FromWatts(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index 4e153fa08c..c1b2f8fbcd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -1450,12 +1450,12 @@ public void ToUnit_WithSameUnits_AreEqual(PressureChangeRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PressureChangeRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = PressureChangeRate.Units.First(u => u != PressureChangeRate.BaseUnit); - - var quantity = PressureChangeRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(PressureChangeRate.Units.Where(u => u != PressureChangeRate.BaseUnit), fromUnit => + { + var quantity = PressureChangeRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1467,6 +1467,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Pres Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PressureChangeRateUnit unit) + { + var quantity = PressureChangeRate.From(3, PressureChangeRate.BaseUnit); + PressureChangeRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1864,6 +1883,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = PressureChangeRate.FromPascalsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index e2d0aa3289..4707788fa9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -2693,12 +2693,12 @@ public void ToUnit_WithSameUnits_AreEqual(PressureUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(PressureUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Pressure.Units.First(u => u != Pressure.BaseUnit); - - var quantity = Pressure.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Pressure.Units.Where(u => u != Pressure.BaseUnit), fromUnit => + { + var quantity = Pressure.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -2710,6 +2710,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Pres Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(PressureUnit unit) + { + var quantity = Pressure.From(3, Pressure.BaseUnit); + Pressure expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -3200,6 +3219,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Pressure.FromPascals(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs index 08ca343322..076c08aa38 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs @@ -804,12 +804,12 @@ public void ToUnit_WithSameUnits_AreEqual(RadiationEquivalentDoseRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RadiationEquivalentDoseRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RadiationEquivalentDoseRate.Units.First(u => u != RadiationEquivalentDoseRate.BaseUnit); - - var quantity = RadiationEquivalentDoseRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RadiationEquivalentDoseRate.Units.Where(u => u != RadiationEquivalentDoseRate.BaseUnit), fromUnit => + { + var quantity = RadiationEquivalentDoseRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -821,6 +821,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Radi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RadiationEquivalentDoseRateUnit unit) + { + var quantity = RadiationEquivalentDoseRate.From(3, RadiationEquivalentDoseRate.BaseUnit); + RadiationEquivalentDoseRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1194,6 +1213,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RadiationEquivalentDoseRate.FromSievertsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs index 144daed19e..0d59a27966 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs @@ -612,12 +612,12 @@ public void ToUnit_WithSameUnits_AreEqual(RadiationEquivalentDoseUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RadiationEquivalentDoseUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RadiationEquivalentDose.Units.First(u => u != RadiationEquivalentDose.BaseUnit); - - var quantity = RadiationEquivalentDose.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RadiationEquivalentDose.Units.Where(u => u != RadiationEquivalentDose.BaseUnit), fromUnit => + { + var quantity = RadiationEquivalentDose.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -629,6 +629,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Radi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RadiationEquivalentDoseUnit unit) + { + var quantity = RadiationEquivalentDose.From(3, RadiationEquivalentDose.BaseUnit); + RadiationEquivalentDose expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -990,6 +1009,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RadiationEquivalentDose.FromSieverts(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs index b3108a9e1e..0ef0e16bc9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -606,12 +606,12 @@ public void ToUnit_WithSameUnits_AreEqual(RadiationExposureUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RadiationExposureUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RadiationExposure.Units.First(u => u != RadiationExposure.BaseUnit); - - var quantity = RadiationExposure.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RadiationExposure.Units.Where(u => u != RadiationExposure.BaseUnit), fromUnit => + { + var quantity = RadiationExposure.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -623,6 +623,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Radi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RadiationExposureUnit unit) + { + var quantity = RadiationExposure.From(3, RadiationExposure.BaseUnit); + RadiationExposure expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -990,6 +1009,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs index bdee5211d1..7503c02822 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs @@ -1654,12 +1654,12 @@ public void ToUnit_WithSameUnits_AreEqual(RadioactivityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RadioactivityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Radioactivity.Units.First(u => u != Radioactivity.BaseUnit); - - var quantity = Radioactivity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Radioactivity.Units.Where(u => u != Radioactivity.BaseUnit), fromUnit => + { + var quantity = Radioactivity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1671,6 +1671,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Radi Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RadioactivityUnit unit) + { + var quantity = Radioactivity.From(3, Radioactivity.BaseUnit); + Radioactivity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2101,6 +2120,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Radioactivity.FromBecquerels(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index 4756b19f1d..860d2f97be 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -420,12 +420,12 @@ public void ToUnit_WithSameUnits_AreEqual(RatioChangeRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RatioChangeRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RatioChangeRate.Units.First(u => u != RatioChangeRate.BaseUnit); - - var quantity = RatioChangeRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RatioChangeRate.Units.Where(u => u != RatioChangeRate.BaseUnit), fromUnit => + { + var quantity = RatioChangeRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -437,6 +437,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rati Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RatioChangeRateUnit unit) + { + var quantity = RatioChangeRate.From(3, RatioChangeRate.BaseUnit); + RatioChangeRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -786,6 +805,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index 92ea840ee5..34c296eced 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -484,12 +484,12 @@ public void ToUnit_WithSameUnits_AreEqual(RatioUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RatioUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Ratio.Units.First(u => u != Ratio.BaseUnit); - - var quantity = Ratio.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Ratio.Units.Where(u => u != Ratio.BaseUnit), fromUnit => + { + var quantity = Ratio.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -501,6 +501,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rati Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RatioUnit unit) + { + var quantity = Ratio.From(3, Ratio.BaseUnit); + Ratio expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -862,6 +881,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Ratio.FromDecimalFractions(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs index 12c066f81c..90a67526a3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs @@ -699,12 +699,12 @@ public void ToUnit_WithSameUnits_AreEqual(ReciprocalAreaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ReciprocalAreaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ReciprocalArea.Units.First(u => u != ReciprocalArea.BaseUnit); - - var quantity = ReciprocalArea.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ReciprocalArea.Units.Where(u => u != ReciprocalArea.BaseUnit), fromUnit => + { + var quantity = ReciprocalArea.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -716,6 +716,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Reci Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ReciprocalAreaUnit unit) + { + var quantity = ReciprocalArea.From(3, ReciprocalArea.BaseUnit); + ReciprocalArea expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1092,6 +1111,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ReciprocalArea.FromInverseSquareMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index 5a3fb5ee57..011a7a5381 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -878,12 +878,12 @@ public void ToUnit_WithSameUnits_AreEqual(ReciprocalLengthUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ReciprocalLengthUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ReciprocalLength.Units.First(u => u != ReciprocalLength.BaseUnit); - - var quantity = ReciprocalLength.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ReciprocalLength.Units.Where(u => u != ReciprocalLength.BaseUnit), fromUnit => + { + var quantity = ReciprocalLength.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -895,6 +895,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Reci Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ReciprocalLengthUnit unit) + { + var quantity = ReciprocalLength.From(3, ReciprocalLength.BaseUnit); + ReciprocalLength expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1268,6 +1287,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ReciprocalLength.FromInverseMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs index 9bcf4ef2e7..6d27aae36f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs @@ -325,16 +325,16 @@ public void ToUnit_WithSameUnits_AreEqual(RelativeHumidityUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RelativeHumidityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RelativeHumidity.Units.First(u => u != RelativeHumidity.BaseUnit); - - var quantity = RelativeHumidity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RelativeHumidity.Units.Where(u => u != RelativeHumidity.BaseUnit), fromUnit => + { + var quantity = RelativeHumidity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -346,6 +346,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rela Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RelativeHumidityUnit unit) + { + var quantity = RelativeHumidity.From(3, RelativeHumidity.BaseUnit); + RelativeHumidity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -691,6 +710,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RelativeHumidity.FromPercent(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index c9c8f051ce..754123dbd1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -503,12 +503,12 @@ public void ToUnit_WithSameUnits_AreEqual(RotationalAccelerationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RotationalAccelerationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RotationalAcceleration.Units.First(u => u != RotationalAcceleration.BaseUnit); - - var quantity = RotationalAcceleration.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RotationalAcceleration.Units.Where(u => u != RotationalAcceleration.BaseUnit), fromUnit => + { + var quantity = RotationalAcceleration.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -520,6 +520,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rota Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RotationalAccelerationUnit unit) + { + var quantity = RotationalAcceleration.From(3, RotationalAcceleration.BaseUnit); + RotationalAcceleration expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -875,6 +894,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RotationalAcceleration.FromRadiansPerSecondSquared(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index 7f173f30f9..63f25332e1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -1091,12 +1091,12 @@ public void ToUnit_WithSameUnits_AreEqual(RotationalSpeedUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RotationalSpeedUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RotationalSpeed.Units.First(u => u != RotationalSpeed.BaseUnit); - - var quantity = RotationalSpeed.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RotationalSpeed.Units.Where(u => u != RotationalSpeed.BaseUnit), fromUnit => + { + var quantity = RotationalSpeed.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1108,6 +1108,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rota Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RotationalSpeedUnit unit) + { + var quantity = RotationalSpeed.From(3, RotationalSpeed.BaseUnit); + RotationalSpeed expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1490,6 +1509,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RotationalSpeed.FromRadiansPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index 9975daba52..a5f1c4a528 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -681,12 +681,12 @@ public void ToUnit_WithSameUnits_AreEqual(RotationalStiffnessPerLengthUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RotationalStiffnessPerLengthUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RotationalStiffnessPerLength.Units.First(u => u != RotationalStiffnessPerLength.BaseUnit); - - var quantity = RotationalStiffnessPerLength.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RotationalStiffnessPerLength.Units.Where(u => u != RotationalStiffnessPerLength.BaseUnit), fromUnit => + { + var quantity = RotationalStiffnessPerLength.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -698,6 +698,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rota Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RotationalStiffnessPerLengthUnit unit) + { + var quantity = RotationalStiffnessPerLength.From(3, RotationalStiffnessPerLength.BaseUnit); + RotationalStiffnessPerLength expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1056,6 +1075,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index 7bf44c4393..7f5b9db7b7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -2752,12 +2752,12 @@ public void ToUnit_WithSameUnits_AreEqual(RotationalStiffnessUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RotationalStiffnessUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = RotationalStiffness.Units.First(u => u != RotationalStiffness.BaseUnit); - - var quantity = RotationalStiffness.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(RotationalStiffness.Units.Where(u => u != RotationalStiffness.BaseUnit), fromUnit => + { + var quantity = RotationalStiffness.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -2769,6 +2769,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Rota Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(RotationalStiffnessUnit unit) + { + var quantity = RotationalStiffness.From(3, RotationalStiffness.BaseUnit); + RotationalStiffness expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -3211,6 +3230,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = RotationalStiffness.FromNewtonMetersPerRadian(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs index b1e837c211..5ec1d0e605 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs @@ -325,16 +325,16 @@ public void ToUnit_WithSameUnits_AreEqual(ScalarUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ScalarUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Scalar.Units.First(u => u != Scalar.BaseUnit); - - var quantity = Scalar.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Scalar.Units.Where(u => u != Scalar.BaseUnit), fromUnit => + { + var quantity = Scalar.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -346,6 +346,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Scal Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ScalarUnit unit) + { + var quantity = Scalar.From(3, Scalar.BaseUnit); + Scalar expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -691,6 +710,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Scalar.FromAmount(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index 333db9f033..c368c75ce6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -325,16 +325,16 @@ public void ToUnit_WithSameUnits_AreEqual(SolidAngleUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SolidAngleUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = SolidAngle.Units.First(u => u != SolidAngle.BaseUnit); - - var quantity = SolidAngle.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(SolidAngle.Units.Where(u => u != SolidAngle.BaseUnit), fromUnit => + { + var quantity = SolidAngle.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -346,6 +346,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Soli Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SolidAngleUnit unit) + { + var quantity = SolidAngle.From(3, SolidAngle.BaseUnit); + SolidAngle expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -691,6 +710,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = SolidAngle.FromSteradians(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index 8abda52a8d..03876689f4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -1288,12 +1288,12 @@ public void ToUnit_WithSameUnits_AreEqual(SpecificEnergyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SpecificEnergyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = SpecificEnergy.Units.First(u => u != SpecificEnergy.BaseUnit); - - var quantity = SpecificEnergy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(SpecificEnergy.Units.Where(u => u != SpecificEnergy.BaseUnit), fromUnit => + { + var quantity = SpecificEnergy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1305,6 +1305,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Spec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SpecificEnergyUnit unit) + { + var quantity = SpecificEnergy.From(3, SpecificEnergy.BaseUnit); + SpecificEnergy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1738,6 +1757,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = SpecificEnergy.FromJoulesPerKilogram(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index 019da990ac..33e36dd7dd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -658,12 +658,12 @@ public void ToUnit_WithSameUnits_AreEqual(SpecificEntropyUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SpecificEntropyUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = SpecificEntropy.Units.First(u => u != SpecificEntropy.BaseUnit); - - var quantity = SpecificEntropy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(SpecificEntropy.Units.Where(u => u != SpecificEntropy.BaseUnit), fromUnit => + { + var quantity = SpecificEntropy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -675,6 +675,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Spec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SpecificEntropyUnit unit) + { + var quantity = SpecificEntropy.From(3, SpecificEntropy.BaseUnit); + SpecificEntropy expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1045,6 +1064,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = SpecificEntropy.FromJoulesPerKilogramKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs index 07723809cf..f722f4c061 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs @@ -482,12 +482,12 @@ public void ToUnit_WithSameUnits_AreEqual(SpecificFuelConsumptionUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SpecificFuelConsumptionUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = SpecificFuelConsumption.Units.First(u => u != SpecificFuelConsumption.BaseUnit); - - var quantity = SpecificFuelConsumption.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(SpecificFuelConsumption.Units.Where(u => u != SpecificFuelConsumption.BaseUnit), fromUnit => + { + var quantity = SpecificFuelConsumption.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -499,6 +499,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Spec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SpecificFuelConsumptionUnit unit) + { + var quantity = SpecificFuelConsumption.From(3, SpecificFuelConsumption.BaseUnit); + SpecificFuelConsumption expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -854,6 +873,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = SpecificFuelConsumption.FromGramsPerKiloNewtonSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 10bbe39265..735297fd1a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -451,12 +451,12 @@ public void ToUnit_WithSameUnits_AreEqual(SpecificVolumeUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SpecificVolumeUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = SpecificVolume.Units.First(u => u != SpecificVolume.BaseUnit); - - var quantity = SpecificVolume.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(SpecificVolume.Units.Where(u => u != SpecificVolume.BaseUnit), fromUnit => + { + var quantity = SpecificVolume.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -468,6 +468,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Spec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SpecificVolumeUnit unit) + { + var quantity = SpecificVolume.From(3, SpecificVolume.BaseUnit); + SpecificVolume expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -820,6 +839,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = SpecificVolume.FromCubicMetersPerKilogram(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index 75d53c9b09..b116e63d42 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -885,12 +885,12 @@ public void ToUnit_WithSameUnits_AreEqual(SpecificWeightUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SpecificWeightUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = SpecificWeight.Units.First(u => u != SpecificWeight.BaseUnit); - - var quantity = SpecificWeight.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(SpecificWeight.Units.Where(u => u != SpecificWeight.BaseUnit), fromUnit => + { + var quantity = SpecificWeight.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -902,6 +902,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Spec Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SpecificWeightUnit unit) + { + var quantity = SpecificWeight.From(3, SpecificWeight.BaseUnit); + SpecificWeight expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1296,6 +1315,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = SpecificWeight.FromNewtonsPerCubicMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index 4dc68814e8..cfb621c88a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -1915,12 +1915,12 @@ public void ToUnit_WithSameUnits_AreEqual(SpeedUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(SpeedUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Speed.Units.First(u => u != Speed.BaseUnit); - - var quantity = Speed.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Speed.Units.Where(u => u != Speed.BaseUnit), fromUnit => + { + var quantity = Speed.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1932,6 +1932,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Spee Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(SpeedUnit unit) + { + var quantity = Speed.From(3, Speed.BaseUnit); + Speed expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -2374,6 +2393,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Speed.FromMetersPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs index 5200239e9e..d0320603e4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs @@ -637,12 +637,12 @@ public void ToUnit_WithSameUnits_AreEqual(StandardVolumeFlowUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(StandardVolumeFlowUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = StandardVolumeFlow.Units.First(u => u != StandardVolumeFlow.BaseUnit); - - var quantity = StandardVolumeFlow.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(StandardVolumeFlow.Units.Where(u => u != StandardVolumeFlow.BaseUnit), fromUnit => + { + var quantity = StandardVolumeFlow.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -654,6 +654,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Stan Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(StandardVolumeFlowUnit unit) + { + var quantity = StandardVolumeFlow.From(3, StandardVolumeFlow.BaseUnit); + StandardVolumeFlow expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1024,6 +1043,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = StandardVolumeFlow.FromStandardCubicMetersPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index f91f758f28..66863ae5b3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -885,12 +885,12 @@ public void ToUnit_WithSameUnits_AreEqual(TemperatureChangeRateUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(TemperatureChangeRateUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = TemperatureChangeRate.Units.First(u => u != TemperatureChangeRate.BaseUnit); - - var quantity = TemperatureChangeRate.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(TemperatureChangeRate.Units.Where(u => u != TemperatureChangeRate.BaseUnit), fromUnit => + { + var quantity = TemperatureChangeRate.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -902,6 +902,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Temp Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(TemperatureChangeRateUnit unit) + { + var quantity = TemperatureChangeRate.From(3, TemperatureChangeRate.BaseUnit); + TemperatureChangeRate expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1296,6 +1315,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index b18d19b48e..ca18646750 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -637,12 +637,12 @@ public void ToUnit_WithSameUnits_AreEqual(TemperatureDeltaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(TemperatureDeltaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = TemperatureDelta.Units.First(u => u != TemperatureDelta.BaseUnit); - - var quantity = TemperatureDelta.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(TemperatureDelta.Units.Where(u => u != TemperatureDelta.BaseUnit), fromUnit => + { + var quantity = TemperatureDelta.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -654,6 +654,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Temp Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(TemperatureDeltaUnit unit) + { + var quantity = TemperatureDelta.From(3, TemperatureDelta.BaseUnit); + TemperatureDelta expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1024,6 +1043,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = TemperatureDelta.FromKelvins(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs index 8e640f8f0b..9744646ac9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs @@ -482,12 +482,12 @@ public void ToUnit_WithSameUnits_AreEqual(TemperatureGradientUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(TemperatureGradientUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = TemperatureGradient.Units.First(u => u != TemperatureGradient.BaseUnit); - - var quantity = TemperatureGradient.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(TemperatureGradient.Units.Where(u => u != TemperatureGradient.BaseUnit), fromUnit => + { + var quantity = TemperatureGradient.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -499,6 +499,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Temp Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(TemperatureGradientUnit unit) + { + var quantity = TemperatureGradient.From(3, TemperatureGradient.BaseUnit); + TemperatureGradient expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -854,6 +873,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = TemperatureGradient.FromKelvinsPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index 3e408325f9..234ccaf84b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -668,12 +668,12 @@ public void ToUnit_WithSameUnits_AreEqual(TemperatureUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(TemperatureUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Temperature.Units.First(u => u != Temperature.BaseUnit); - - var quantity = Temperature.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Temperature.Units.Where(u => u != Temperature.BaseUnit), fromUnit => + { + var quantity = Temperature.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -685,6 +685,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Temp Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(TemperatureUnit unit) + { + var quantity = Temperature.From(3, Temperature.BaseUnit); + Temperature expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1046,6 +1065,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Temperature.FromKelvins(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index 8fb089a06a..2684c7dc23 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -420,12 +420,12 @@ public void ToUnit_WithSameUnits_AreEqual(ThermalConductivityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ThermalConductivityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ThermalConductivity.Units.First(u => u != ThermalConductivity.BaseUnit); - - var quantity = ThermalConductivity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ThermalConductivity.Units.Where(u => u != ThermalConductivity.BaseUnit), fromUnit => + { + var quantity = ThermalConductivity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -437,6 +437,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Ther Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ThermalConductivityUnit unit) + { + var quantity = ThermalConductivity.From(3, ThermalConductivity.BaseUnit); + ThermalConductivity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -786,6 +805,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ThermalConductivity.FromWattsPerMeterKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs index 1a7a46f52b..c72f44a212 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs @@ -544,12 +544,12 @@ public void ToUnit_WithSameUnits_AreEqual(ThermalInsulanceUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ThermalInsulanceUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ThermalInsulance.Units.First(u => u != ThermalInsulance.BaseUnit); - - var quantity = ThermalInsulance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(ThermalInsulance.Units.Where(u => u != ThermalInsulance.BaseUnit), fromUnit => + { + var quantity = ThermalInsulance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -561,6 +561,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Ther Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(ThermalInsulanceUnit unit) + { + var quantity = ThermalInsulance.From(3, ThermalInsulance.BaseUnit); + ThermalInsulance expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -922,6 +941,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = ThermalInsulance.FromSquareMeterKelvinsPerKilowatt(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index 4a350eb1ef..332f883636 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -1184,12 +1184,12 @@ public void ToUnit_WithSameUnits_AreEqual(TorqueUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(TorqueUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Torque.Units.First(u => u != Torque.BaseUnit); - - var quantity = Torque.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Torque.Units.Where(u => u != Torque.BaseUnit), fromUnit => + { + var quantity = Torque.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -1201,6 +1201,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Torq Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(TorqueUnit unit) + { + var quantity = Torque.From(3, Torque.BaseUnit); + Torque expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1619,6 +1638,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Torque.FromNewtonMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index 4dd519b457..7c6074e518 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -325,16 +325,16 @@ public void ToUnit_WithSameUnits_AreEqual(TurbidityUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(TurbidityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Turbidity.Units.First(u => u != Turbidity.BaseUnit); - - var quantity = Turbidity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Turbidity.Units.Where(u => u != Turbidity.BaseUnit), fromUnit => + { + var quantity = Turbidity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -346,6 +346,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Turb Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(TurbidityUnit unit) + { + var quantity = Turbidity.From(3, Turbidity.BaseUnit); + Turbidity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -691,6 +710,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Turbidity.FromNTU(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index e47ac77147..6006f4dd98 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -325,16 +325,16 @@ public void ToUnit_WithSameUnits_AreEqual(VitaminAUnit unit) Assert.Equal(quantity, toUnitWithSameUnit); } - [Theory(Skip = "Multiple units required")] + [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VitaminAUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = VitaminA.Units.First(u => u != VitaminA.BaseUnit); - - var quantity = VitaminA.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(VitaminA.Units.Where(u => u != VitaminA.BaseUnit), fromUnit => + { + var quantity = VitaminA.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -346,6 +346,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Vita Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VitaminAUnit unit) + { + var quantity = VitaminA.From(3, VitaminA.BaseUnit); + VitaminA expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -691,6 +710,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = VitaminA.FromInternationalUnits(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index c17e4e3f90..9f7b750d99 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -939,12 +939,12 @@ public void ToUnit_WithSameUnits_AreEqual(VolumeConcentrationUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VolumeConcentrationUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = VolumeConcentration.Units.First(u => u != VolumeConcentration.BaseUnit); - - var quantity = VolumeConcentration.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(VolumeConcentration.Units.Where(u => u != VolumeConcentration.BaseUnit), fromUnit => + { + var quantity = VolumeConcentration.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -956,6 +956,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Volu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VolumeConcentrationUnit unit) + { + var quantity = VolumeConcentration.From(3, VolumeConcentration.BaseUnit); + VolumeConcentration expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1359,6 +1378,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = VolumeConcentration.FromDecimalFractions(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs index 58d023b5ae..3d846e5a0c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs @@ -420,12 +420,12 @@ public void ToUnit_WithSameUnits_AreEqual(VolumeFlowPerAreaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VolumeFlowPerAreaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = VolumeFlowPerArea.Units.First(u => u != VolumeFlowPerArea.BaseUnit); - - var quantity = VolumeFlowPerArea.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(VolumeFlowPerArea.Units.Where(u => u != VolumeFlowPerArea.BaseUnit), fromUnit => + { + var quantity = VolumeFlowPerArea.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -437,6 +437,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Volu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VolumeFlowPerAreaUnit unit) + { + var quantity = VolumeFlowPerArea.From(3, VolumeFlowPerArea.BaseUnit); + VolumeFlowPerArea expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -786,6 +805,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = VolumeFlowPerArea.FromCubicMetersPerSecondPerSquareMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index fcb28b7025..525ec31eef 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -4390,12 +4390,12 @@ public void ToUnit_WithSameUnits_AreEqual(VolumeFlowUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VolumeFlowUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = VolumeFlow.Units.First(u => u != VolumeFlow.BaseUnit); - - var quantity = VolumeFlow.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(VolumeFlow.Units.Where(u => u != VolumeFlow.BaseUnit), fromUnit => + { + var quantity = VolumeFlow.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -4407,6 +4407,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Volu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VolumeFlowUnit unit) + { + var quantity = VolumeFlow.From(3, VolumeFlow.BaseUnit); + VolumeFlow expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -4975,6 +4994,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = VolumeFlow.FromCubicMetersPerSecond(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index ace8967bba..f6a65135fa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -637,12 +637,12 @@ public void ToUnit_WithSameUnits_AreEqual(VolumePerLengthUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VolumePerLengthUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = VolumePerLength.Units.First(u => u != VolumePerLength.BaseUnit); - - var quantity = VolumePerLength.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(VolumePerLength.Units.Where(u => u != VolumePerLength.BaseUnit), fromUnit => + { + var quantity = VolumePerLength.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -654,6 +654,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Volu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VolumePerLengthUnit unit) + { + var quantity = VolumePerLength.From(3, VolumePerLength.BaseUnit); + VolumePerLength expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1024,6 +1043,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = VolumePerLength.FromCubicMetersPerMeter(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index 9796f56b63..ae35867748 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -2780,12 +2780,12 @@ public void ToUnit_WithSameUnits_AreEqual(VolumeUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VolumeUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = Volume.Units.First(u => u != Volume.BaseUnit); - - var quantity = Volume.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(Volume.Units.Where(u => u != Volume.BaseUnit), fromUnit => + { + var quantity = Volume.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -2797,6 +2797,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Volu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VolumeUnit unit) + { + var quantity = Volume.From(3, Volume.BaseUnit); + Volume expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -3302,6 +3321,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = Volume.FromCubicMeters(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs index b5a3618a11..d3f5d820cb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs @@ -637,12 +637,12 @@ public void ToUnit_WithSameUnits_AreEqual(VolumetricHeatCapacityUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(VolumetricHeatCapacityUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = VolumetricHeatCapacity.Units.First(u => u != VolumetricHeatCapacity.BaseUnit); - - var quantity = VolumetricHeatCapacity.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(VolumetricHeatCapacity.Units.Where(u => u != VolumetricHeatCapacity.BaseUnit), fromUnit => + { + var quantity = VolumetricHeatCapacity.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -654,6 +654,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Volu Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(VolumetricHeatCapacityUnit unit) + { + var quantity = VolumetricHeatCapacity.From(3, VolumetricHeatCapacity.BaseUnit); + VolumetricHeatCapacity expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1024,6 +1043,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = VolumetricHeatCapacity.FromJoulesPerCubicMeterKelvin(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index 4e1617327f..2d427dc168 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -670,12 +670,12 @@ public void ToUnit_WithSameUnits_AreEqual(WarpingMomentOfInertiaUnit unit) [MemberData(nameof(UnitTypes))] public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(WarpingMomentOfInertiaUnit unit) { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = WarpingMomentOfInertia.Units.First(u => u != WarpingMomentOfInertia.BaseUnit); - - var quantity = WarpingMomentOfInertia.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); + Assert.All(WarpingMomentOfInertia.Units.Where(u => u != WarpingMomentOfInertia.BaseUnit), fromUnit => + { + var quantity = WarpingMomentOfInertia.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + }); } [Theory] @@ -687,6 +687,25 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Warp Assert.Equal(converted.Unit, unit); } + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity(WarpingMomentOfInertiaUnit unit) + { + var quantity = WarpingMomentOfInertia.From(3, WarpingMomentOfInertia.BaseUnit); + WarpingMomentOfInertia expectedQuantity = quantity.ToUnit(unit); + Assert.Multiple(() => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }, () => + { + IQuantity quantityToConvert = quantity; + IQuantity convertedQuantity = quantityToConvert.ToUnit(unit); + Assert.Equal(unit, convertedQuantity.Unit); + }); + } + [Fact] public void ConversionRoundTrip() { @@ -1048,6 +1067,13 @@ public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); } + [Fact] + public void Convert_GetTypeCode_Returns_Object() + { + var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); + Assert.Equal(TypeCode.Object, Convert.GetTypeCode(quantity)); + } + [Fact] public void GetHashCode_Equals() {