diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 2561a73651..e9ffc24cf8 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -74,6 +74,7 @@ public override string Generate() using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -87,7 +88,7 @@ namespace UnitsNet.Tests /// Test of {_quantity.Name}. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class {_quantity.Name}TestsBase + public abstract partial class {_quantity.Name}TestsBase : QuantityTestsBase {{"); foreach (var unit in _quantity.Units) Writer.WL($@" protected abstract double {unit.PluralName}InOne{_baseUnit.SingularName} {{ get; }}"); @@ -127,13 +128,28 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() {{ Assert.Throws(() => new {_quantity.Name}(double.NaN, {_baseUnitFullName})); }} +"); Writer.WL($@" [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() {{ - Assert.Throws(() => new {_quantity.Name}(value: 1.0, unitSystem: null)); + Assert.Throws(() => new {_quantity.Name}(value: 1, unitSystem: null)); + }} + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + {{ + Func TestCode = () => new {_quantity.Name}(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + {{ + var quantity = ({_quantity.Name}) TestCode(); + Assert.Equal(1, quantity.Value); + }} + else + {{ + Assert.Throws(TestCode); + }} }} -"); Writer.WL($@" [Fact] public void {_quantity.Name}_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() @@ -207,6 +223,23 @@ public void As() Writer.WL($@" }} + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + {{ + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + }} + else + {{ + Assert.Throws(AsWithSIUnitSystem); + }} + }} + [Fact] public void ToUnit() {{ @@ -224,6 +257,14 @@ public void ToUnit() Writer.WL($@" }} + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + {{ + var quantityInBaseUnit = {_quantity.Name}.From{_baseUnit.PluralName}(1).ToBaseUnit(); + Assert.Equal({_quantity.Name}.BaseUnit, quantityInBaseUnit.Unit);"); + Writer.WL($@" + }} + [Fact] public void ConversionRoundTrip() {{ @@ -657,11 +698,10 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) {{ var quantity = {_quantity.Name}.From{_baseUnit.PluralName}(value); Assert.Equal({_quantity.Name}.From{_baseUnit.PluralName}(-value), -quantity); - }} -"); + }}"); } -Writer.WL( $@" +Writer.WL($@" }} }}" ); return Writer.ToString(); diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index 048785d823..a6082eccde 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -29,6 +29,9 @@ "FromUnitToBaseFunc": "x", "FromBaseToUnitFunc": "x", "Prefixes": [ "Hecto", "Kilo" ], + "BaseUnits": { + "L": "Meter" + }, "Localization": [ { "Culture": "en-US", diff --git a/UnitsNet.Tests/CustomCode/AccelerationTests.cs b/UnitsNet.Tests/CustomCode/AccelerationTests.cs index 59b0c8891c..4e3ff9422f 100644 --- a/UnitsNet.Tests/CustomCode/AccelerationTests.cs +++ b/UnitsNet.Tests/CustomCode/AccelerationTests.cs @@ -7,6 +7,8 @@ namespace UnitsNet.Tests.CustomCode { public class AccelerationTests : AccelerationTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double KilometersPerSecondSquaredInOneMeterPerSecondSquared => 1E-3; protected override double MetersPerSecondSquaredInOneMeterPerSecondSquared => 1; diff --git a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs index 61560c24ec..fcfa8e337e 100644 --- a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs +++ b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs @@ -28,6 +28,8 @@ namespace UnitsNet.Tests.CustomCode { public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double CentimolesInOneMole => 1e2; protected override double CentipoundMolesInOneMole => 0.002204622621848776 * 1e2; protected override double DecimolesInOneMole => 1e1; @@ -43,7 +45,7 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase protected override double NanopoundMolesInOneMole => 0.002204622621848776 * 1e9; protected override double PoundMolesInOneMole => 0.002204622621848776; protected override double MegamolesInOneMole => 1e-6; - + [Fact] public void NumberOfParticlesInOneMoleEqualsAvogadroConstant() { @@ -71,7 +73,7 @@ public void MassFromAmountOfSubstanceAndMolarMass( { AmountOfSubstance amountOfSubstance = new AmountOfSubstance(amountOfSubstanceValue, amountOfSubstanceUnit); MolarMass molarMass = new MolarMass(molarMassValue, molarMassUnit); - + Mass mass = amountOfSubstance * molarMass; AssertEx.EqualTolerance(expectedMass, mass.As(expectedMassUnit), tolerence); diff --git a/UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs b/UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs index e51ce88b3c..726457cbe1 100644 --- a/UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs +++ b/UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class AmplitudeRatioTests : AmplitudeRatioTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DecibelMicrovoltsInOneDecibelVolt => 121; protected override double DecibelMillivoltsInOneDecibelVolt => 61; diff --git a/UnitsNet.Tests/CustomCode/AngleTests.cs b/UnitsNet.Tests/CustomCode/AngleTests.cs index 1641165cce..77f2956280 100644 --- a/UnitsNet.Tests/CustomCode/AngleTests.cs +++ b/UnitsNet.Tests/CustomCode/AngleTests.cs @@ -8,6 +8,8 @@ namespace UnitsNet.Tests.CustomCode { public class AngleTests : AngleTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double DegreesInOneDegree => 1; protected override double GradiansInOneDegree => 400 / 360.0; diff --git a/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs b/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs index 9de4999797..216ef60102 100644 --- a/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class ApparentEnergyTests : ApparentEnergyTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double VoltampereHoursInOneVoltampereHour => 1; protected override double KilovoltampereHoursInOneVoltampereHour => 1E-3; diff --git a/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs b/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs index ab732bdbdc..ae56c03dd0 100644 --- a/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs +++ b/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class ApparentPowerTests : ApparentPowerTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double VoltamperesInOneVoltampere => 1; protected override double KilovoltamperesInOneVoltampere => 1E-3; diff --git a/UnitsNet.Tests/CustomCode/AreaDensityTests.cs b/UnitsNet.Tests/CustomCode/AreaDensityTests.cs index 4e5e608900..c3f9c19164 100644 --- a/UnitsNet.Tests/CustomCode/AreaDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/AreaDensityTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class AreaDensityTests : AreaDensityTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double KilogramsPerSquareMeterInOneKilogramPerSquareMeter => 1; } } diff --git a/UnitsNet.Tests/CustomCode/AreaMomentOfInertiaTests.cs b/UnitsNet.Tests/CustomCode/AreaMomentOfInertiaTests.cs index e43027813d..04fb07e048 100644 --- a/UnitsNet.Tests/CustomCode/AreaMomentOfInertiaTests.cs +++ b/UnitsNet.Tests/CustomCode/AreaMomentOfInertiaTests.cs @@ -28,6 +28,8 @@ namespace UnitsNet.Tests.CustomCode { public class AreaMomentOfInertiaTests : AreaMomentOfInertiaTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double CentimetersToTheFourthInOneMeterToTheFourth => 1e8; protected override double DecimetersToTheFourthInOneMeterToTheFourth => 1e4; diff --git a/UnitsNet.Tests/CustomCode/AreaTests.cs b/UnitsNet.Tests/CustomCode/AreaTests.cs index 5edc60edba..c917293d45 100644 --- a/UnitsNet.Tests/CustomCode/AreaTests.cs +++ b/UnitsNet.Tests/CustomCode/AreaTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class AreaTests : AreaTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double SquareKilometersInOneSquareMeter => 1E-6; diff --git a/UnitsNet.Tests/CustomCode/BitRateTests.cs b/UnitsNet.Tests/CustomCode/BitRateTests.cs index 89f40758f2..2afe11ae27 100644 --- a/UnitsNet.Tests/CustomCode/BitRateTests.cs +++ b/UnitsNet.Tests/CustomCode/BitRateTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class BitRateTests : BitRateTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double BitsPerSecondInOneBitPerSecond => 1d; protected override double BytesPerSecondInOneBitPerSecond => 1.25E-1d; diff --git a/UnitsNet.Tests/CustomCode/BrakeSpecificFuelConsumptionTests.cs b/UnitsNet.Tests/CustomCode/BrakeSpecificFuelConsumptionTests.cs index ed637226a8..3079c5d0d6 100644 --- a/UnitsNet.Tests/CustomCode/BrakeSpecificFuelConsumptionTests.cs +++ b/UnitsNet.Tests/CustomCode/BrakeSpecificFuelConsumptionTests.cs @@ -8,6 +8,8 @@ namespace UnitsNet.Tests.CustomCode { public class BrakeSpecificFuelConsumptionTests : BrakeSpecificFuelConsumptionTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double GramsPerKiloWattHourInOneKilogramPerJoule => 3600000000; protected override double KilogramsPerJouleInOneKilogramPerJoule => 1.0; diff --git a/UnitsNet.Tests/CustomCode/CapacitanceTests.cs b/UnitsNet.Tests/CustomCode/CapacitanceTests.cs index 122cc96086..91135dfd33 100644 --- a/UnitsNet.Tests/CustomCode/CapacitanceTests.cs +++ b/UnitsNet.Tests/CustomCode/CapacitanceTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class CapacitanceTests : CapacitanceTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double FaradsInOneFarad => 1; protected override double MillifaradsInOneFarad => 1e3; diff --git a/UnitsNet.Tests/CustomCode/CoefficientOfThermalExpansionTests.cs b/UnitsNet.Tests/CustomCode/CoefficientOfThermalExpansionTests.cs index a5de91a71d..10a5768427 100644 --- a/UnitsNet.Tests/CustomCode/CoefficientOfThermalExpansionTests.cs +++ b/UnitsNet.Tests/CustomCode/CoefficientOfThermalExpansionTests.cs @@ -28,6 +28,8 @@ namespace UnitsNet.Tests.CustomCode { public class CoefficientOfThermalExpansionTests : CoefficientOfThermalExpansionTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double InverseDegreeCelsiusInOneInverseKelvin => 1.0; protected override double InverseDegreeFahrenheitInOneInverseKelvin => 0.5555555555555556; diff --git a/UnitsNet.Tests/CustomCode/DensityTests.cs b/UnitsNet.Tests/CustomCode/DensityTests.cs index a2a1cc467d..8e61cb8225 100644 --- a/UnitsNet.Tests/CustomCode/DensityTests.cs +++ b/UnitsNet.Tests/CustomCode/DensityTests.cs @@ -7,6 +7,8 @@ namespace UnitsNet.Tests.CustomCode { public class DensityTests : DensityTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double MilligramsPerCubicMeterInOneKilogramPerCubicMeter => 1e6; protected override double GramsPerCubicCentimeterInOneKilogramPerCubicMeter => 1e-3; @@ -107,7 +109,7 @@ public static void DensityTimesKinematicViscosityEqualsDynamicViscosity() DynamicViscosity dynamicViscosity = Density.FromKilogramsPerCubicMeter(2) * KinematicViscosity.FromSquareMetersPerSecond(10); Assert.Equal(dynamicViscosity, DynamicViscosity.FromNewtonSecondsPerMeterSquared(20)); } - + [Fact] public void DensityTimesSpeedEqualsMassFlux() { diff --git a/UnitsNet.Tests/CustomCode/DurationTests.cs b/UnitsNet.Tests/CustomCode/DurationTests.cs index b6fe1347d6..9c7a6fbe92 100644 --- a/UnitsNet.Tests/CustomCode/DurationTests.cs +++ b/UnitsNet.Tests/CustomCode/DurationTests.cs @@ -9,6 +9,8 @@ namespace UnitsNet.Tests.CustomCode { public class DurationTests : DurationTestsBase { + protected override bool SupportsSIUnitSystem => true; + protected override double DaysInOneSecond => 1.15741e-5; protected override double HoursInOneSecond => 0.0002777784; diff --git a/UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs b/UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs index 6934aeffbd..73efb62140 100644 --- a/UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs +++ b/UnitsNet.Tests/CustomCode/DynamicViscosityTests.cs @@ -8,6 +8,8 @@ namespace UnitsNet.Tests.CustomCode { public class DynamicViscosityTests : DynamicViscosityTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double CentipoiseInOneNewtonSecondPerMeterSquared => 1e3; protected override double MicropascalSecondsInOneNewtonSecondPerMeterSquared => 1e6; protected override double MillipascalSecondsInOneNewtonSecondPerMeterSquared => 1e3; diff --git a/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs index 5b7f13b4d9..c27d4b4b9c 100644 --- a/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricAdmittanceTests : ElectricAdmittanceTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double MicrosiemensInOneSiemens => 1e+6; protected override double MillisiemensInOneSiemens => 1000; diff --git a/UnitsNet.Tests/CustomCode/ElectricChargeDensityTests.cs b/UnitsNet.Tests/CustomCode/ElectricChargeDensityTests.cs index 28315edf4e..ebdc188ca9 100644 --- a/UnitsNet.Tests/CustomCode/ElectricChargeDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricChargeDensityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricChargeDensityTests : ElectricChargeDensityTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double CoulombsPerCubicMeterInOneCoulombPerCubicMeter => 1; } } diff --git a/UnitsNet.Tests/CustomCode/ElectricChargeTests.cs b/UnitsNet.Tests/CustomCode/ElectricChargeTests.cs index 42a031553e..399e80296a 100644 --- a/UnitsNet.Tests/CustomCode/ElectricChargeTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricChargeTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricChargeTests : ElectricChargeTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double CoulombsInOneCoulomb => 1; protected override double MilliampereHoursInOneCoulomb => 2.77777777777e-1; protected override double AmpereHoursInOneCoulomb => 2.77777777777e-4; diff --git a/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs index 9b77815a83..34ae5234c7 100644 --- a/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricConductanceTests : ElectricConductanceTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double SiemensInOneSiemens => 1; protected override double MillisiemensInOneSiemens => 1E3; diff --git a/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs b/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs index db085f3eb2..bbb32fbf10 100644 --- a/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricConductivityTests : ElectricConductivityTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double SiemensPerMeterInOneSiemensPerMeter => 1; protected override double SiemensPerInchInOneSiemensPerMeter => 2.54e-2; protected override double SiemensPerFootInOneSiemensPerMeter => 3.048e-1; diff --git a/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs b/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs index 507bf52ff3..06c29d72c7 100644 --- a/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricCurrentDensityTests : ElectricCurrentDensityTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double AmperesPerSquareMeterInOneAmperePerSquareMeter => 1; protected override double AmperesPerSquareInchInOneAmperePerSquareMeter => 6.4516e-4; protected override double AmperesPerSquareFootInOneAmperePerSquareMeter => 9.290304e-2; diff --git a/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs b/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs index 0f3f5fba49..2d73348dd2 100644 --- a/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricCurrentGradientTests : ElectricCurrentGradientTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double AmperesPerSecondInOneAmperePerSecond => 1; } } diff --git a/UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs b/UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs index 5fb898ebb7..f801c07be6 100644 --- a/UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricCurrentTests : ElectricCurrentTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double PicoamperesInOneAmpere => 1e12; protected override double NanoamperesInOneAmpere => 1e9; diff --git a/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs b/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs index 092e041fac..52d71ec36e 100644 --- a/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricFieldTests : ElectricFieldTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double VoltsPerMeterInOneVoltPerMeter => 1; } } diff --git a/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs index 5adb534628..058665be38 100644 --- a/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricInductanceTests : ElectricInductanceTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double HenriesInOneHenry => 1; protected override double NanohenriesInOneHenry => 1e9; protected override double MicrohenriesInOneHenry => 1e6; diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs index e954eb7840..b001ca7f65 100644 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricPotentialAcTests : ElectricPotentialAcTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilovoltsAcInOneVoltAc => 1e-3; protected override double MegavoltsAcInOneVoltAc => 1e-6; diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs index 8dbc073ccd..478fe93087 100644 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricPotentialChangeRateTests.cs @@ -23,6 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricPotentialChangeRateTests : ElectricPotentialChangeRateTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double KilovoltsPerHoursInOneVoltPerSecond => 3.6; protected override double KilovoltsPerMicrosecondsInOneVoltPerSecond => 1e-09; protected override double KilovoltsPerMinutesInOneVoltPerSecond => 6e-2; diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs index 92b70ec34d..9fa9db32c6 100644 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricPotentialDcTests : ElectricPotentialDcTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilovoltsDcInOneVoltDc => 1e-3; protected override double MegavoltsDcInOneVoltDc => 1e-6; diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialTests.cs index 0fb87452fc..40abf22f22 100644 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricPotentialTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricPotentialTests : ElectricPotentialTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double MicrovoltsInOneVolt => 1e6; protected override double MillivoltsInOneVolt => 1e3; diff --git a/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs index 0b23840888..d970c4fb33 100644 --- a/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricResistanceTests : ElectricResistanceTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double MicroohmsInOneOhm => 1e6; protected override double MilliohmsInOneOhm => 1000; diff --git a/UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs b/UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs index 486cce2383..59cca6e1d8 100644 --- a/UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricResistivityTests.cs @@ -27,7 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricResistivityTests : ElectricResistivityTestsBase { - // TODO Override properties in base class here + protected override bool SupportsSIUnitSystem => false; protected override double KiloohmsCentimeterInOneOhmMeter => 1e-1; protected override double KiloohmMetersInOneOhmMeter => 1e-3; diff --git a/UnitsNet.Tests/CustomCode/ElectricSurfaceChargeDensityTests.cs b/UnitsNet.Tests/CustomCode/ElectricSurfaceChargeDensityTests.cs index 5314164358..b0566b25a5 100644 --- a/UnitsNet.Tests/CustomCode/ElectricSurfaceChargeDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricSurfaceChargeDensityTests.cs @@ -26,6 +26,7 @@ namespace UnitsNet.Tests.CustomCode { public class ElectricSurfaceChargeDensityTests : ElectricSurfaceChargeDensityTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double CoulombsPerSquareMeterInOneCoulombPerSquareMeter => 1.0; protected override double CoulombsPerSquareCentimeterInOneCoulombPerSquareMeter => 1.0e-4; diff --git a/UnitsNet.Tests/CustomCode/EnergyTests.cs b/UnitsNet.Tests/CustomCode/EnergyTests.cs index 91e21c8701..ae058ba101 100644 --- a/UnitsNet.Tests/CustomCode/EnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/EnergyTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class EnergyTests : EnergyTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double ThermsImperialInOneJoule => 9.478171203551087813109937767482e-9; protected override double JoulesInOneJoule => 1; diff --git a/UnitsNet.Tests/CustomCode/EntropyTests.cs b/UnitsNet.Tests/CustomCode/EntropyTests.cs index 8e08cee3ae..0a14bdba95 100644 --- a/UnitsNet.Tests/CustomCode/EntropyTests.cs +++ b/UnitsNet.Tests/CustomCode/EntropyTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class EntropyTests : EntropyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double CaloriesPerKelvinInOneJoulePerKelvin => 0.239006; protected override double JoulesPerDegreeCelsiusInOneJoulePerKelvin => 1e0; protected override double JoulesPerKelvinInOneJoulePerKelvin => 1e0; diff --git a/UnitsNet.Tests/CustomCode/ForceChangeRateTests.cs b/UnitsNet.Tests/CustomCode/ForceChangeRateTests.cs index df3350f40a..c24572b9a0 100644 --- a/UnitsNet.Tests/CustomCode/ForceChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/ForceChangeRateTests.cs @@ -5,6 +5,7 @@ namespace UnitsNet.Tests.CustomCode { public class ForceChangeRateTests : ForceChangeRateTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double NewtonsPerMinuteInOneNewtonPerSecond => 60; protected override double DecanewtonsPerMinuteInOneNewtonPerSecond => 6; protected override double KilonewtonsPerMinuteInOneNewtonPerSecond => 0.06; diff --git a/UnitsNet.Tests/CustomCode/ForcePerLengthTests.cs b/UnitsNet.Tests/CustomCode/ForcePerLengthTests.cs index 410caf25cb..a9050dfeb8 100644 --- a/UnitsNet.Tests/CustomCode/ForcePerLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/ForcePerLengthTests.cs @@ -23,6 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class ForcePerLengthTests : ForcePerLengthTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilopoundsForcePerInchInOneNewtonPerMeter => 5.710147162769201E-6; protected override double KilogramsForcePerMillimeterInOneNewtonPerMeter => 1.019716212977928e-4; protected override double KilogramsForcePerCentimeterInOneNewtonPerMeter => 1.019716212977928e-3; diff --git a/UnitsNet.Tests/CustomCode/ForceTests.cs b/UnitsNet.Tests/CustomCode/ForceTests.cs index 79e8b31fe9..e87ed077c5 100644 --- a/UnitsNet.Tests/CustomCode/ForceTests.cs +++ b/UnitsNet.Tests/CustomCode/ForceTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class ForceTests : ForceTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double DecanewtonsInOneNewton => 1E-1; protected override double DyneInOneNewton => 1E5; diff --git a/UnitsNet.Tests/CustomCode/FrequencyTests.cs b/UnitsNet.Tests/CustomCode/FrequencyTests.cs index f030b07c5b..68a1bf40aa 100644 --- a/UnitsNet.Tests/CustomCode/FrequencyTests.cs +++ b/UnitsNet.Tests/CustomCode/FrequencyTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class FrequencyTests : FrequencyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double HertzInOneHertz => 1; protected override double KilohertzInOneHertz => 1e-3; diff --git a/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs index ccad68f586..9b4f1e7796 100644 --- a/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs +++ b/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs @@ -23,7 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class FuelEfficiencyTests : FuelEfficiencyTestsBase { - // Override properties in base class here + protected override bool SupportsSIUnitSystem => false; protected override double KilometersPerLitersInOneLiterPer100Kilometers => 100; protected override double LitersPer100KilometersInOneLiterPer100Kilometers => 1; protected override double MilesPerUkGallonInOneLiterPer100Kilometers => 282.4809363; diff --git a/UnitsNet.Tests/CustomCode/HeatFluxTests.cs b/UnitsNet.Tests/CustomCode/HeatFluxTests.cs index ea7e2132d9..0c9b742538 100644 --- a/UnitsNet.Tests/CustomCode/HeatFluxTests.cs +++ b/UnitsNet.Tests/CustomCode/HeatFluxTests.cs @@ -28,6 +28,7 @@ namespace UnitsNet.Tests.CustomCode { public class HeatFluxTests : HeatFluxTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double BtusPerHourSquareFootInOneWattPerSquareMeter => 3.16998331e-1; protected override double BtusPerMinuteSquareFootInOneWattPerSquareMeter => 5.28330551e-3; protected override double BtusPerSecondSquareFootInOneWattPerSquareMeter => 8.80550918e-5; diff --git a/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs b/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs index 7226d95974..4e07e9c612 100644 --- a/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs +++ b/UnitsNet.Tests/CustomCode/HeatTransferCoefficientTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class HeatTransferCoefficientTests : HeatTransferCoefficientTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin => 1; protected override double WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin => 1; protected override double BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin => 1.7611018368230584e-1; diff --git a/UnitsNet.Tests/CustomCode/IlluminanceTests.cs b/UnitsNet.Tests/CustomCode/IlluminanceTests.cs index db1b151d8c..b561f238c7 100644 --- a/UnitsNet.Tests/CustomCode/IlluminanceTests.cs +++ b/UnitsNet.Tests/CustomCode/IlluminanceTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class IlluminanceTests : IlluminanceTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double MilliluxInOneLux => 1E3; protected override double LuxInOneLux => 1; diff --git a/UnitsNet.Tests/CustomCode/InformationTests.cs b/UnitsNet.Tests/CustomCode/InformationTests.cs index 2a7383e8cc..a65933ef4b 100644 --- a/UnitsNet.Tests/CustomCode/InformationTests.cs +++ b/UnitsNet.Tests/CustomCode/InformationTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class InformationTests : InformationTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double BitsInOneBit => 1d; protected override double BytesInOneBit => 0.125d; diff --git a/UnitsNet.Tests/CustomCode/IrradianceTests.cs b/UnitsNet.Tests/CustomCode/IrradianceTests.cs index 31da081b01..9f50b586cf 100644 --- a/UnitsNet.Tests/CustomCode/IrradianceTests.cs +++ b/UnitsNet.Tests/CustomCode/IrradianceTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class IrradianceTests : IrradianceTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilowattsPerSquareCentimeterInOneWattPerSquareMeter => 1e-7; protected override double KilowattsPerSquareMeterInOneWattPerSquareMeter => 1e-3; diff --git a/UnitsNet.Tests/CustomCode/IrradiationTests.cs b/UnitsNet.Tests/CustomCode/IrradiationTests.cs index 258fabbb38..91bb9b6e9a 100644 --- a/UnitsNet.Tests/CustomCode/IrradiationTests.cs +++ b/UnitsNet.Tests/CustomCode/IrradiationTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class IrradiationTests : IrradiationTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double JoulesPerSquareMeterInOneJoulePerSquareMeter => 1; protected override double KilojoulesPerSquareMeterInOneJoulePerSquareMeter => 1E-3; diff --git a/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs b/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs index f41e2d5d54..601ac84bda 100644 --- a/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs +++ b/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs @@ -8,6 +8,8 @@ namespace UnitsNet.Tests.CustomCode { public class KinematicViscosityTests : KinematicViscosityTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double CentistokesInOneSquareMeterPerSecond => 1e6; protected override double DecistokesInOneSquareMeterPerSecond => 1e5; diff --git a/UnitsNet.Tests/CustomCode/LapseRateTests.cs b/UnitsNet.Tests/CustomCode/LapseRateTests.cs index 4dbfd650be..7701f7309b 100644 --- a/UnitsNet.Tests/CustomCode/LapseRateTests.cs +++ b/UnitsNet.Tests/CustomCode/LapseRateTests.cs @@ -28,6 +28,7 @@ namespace UnitsNet.Tests.CustomCode { public class LapseRateTests : LapseRateTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer => 1e0; [Fact] diff --git a/UnitsNet.Tests/CustomCode/LengthTests.cs b/UnitsNet.Tests/CustomCode/LengthTests.cs index 19da3e8d47..0f8e85ac88 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.cs @@ -13,6 +13,7 @@ namespace UnitsNet.Tests.CustomCode [Collection(nameof(UnitAbbreviationsCacheFixture))] public class LengthTests : LengthTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double CentimetersInOneMeter => 100; protected override double DecimetersInOneMeter => 10; diff --git a/UnitsNet.Tests/CustomCode/LevelTests.cs b/UnitsNet.Tests/CustomCode/LevelTests.cs index e5d81b2eb8..a3af30a00e 100644 --- a/UnitsNet.Tests/CustomCode/LevelTests.cs +++ b/UnitsNet.Tests/CustomCode/LevelTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class LevelTests : LevelTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DecibelsInOneDecibel => 1; protected override double NepersInOneDecibel => 0.115129254; diff --git a/UnitsNet.Tests/CustomCode/LinearDensityTests.cs b/UnitsNet.Tests/CustomCode/LinearDensityTests.cs index 2acc6e4f96..1b61ac098f 100644 --- a/UnitsNet.Tests/CustomCode/LinearDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/LinearDensityTests.cs @@ -28,10 +28,11 @@ namespace UnitsNet.Tests.CustomCode { public class LinearDensityTests : LinearDensityTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double MicrogramsPerMillimeterInOneKilogramPerMeter => 1e6; protected override double MicrogramsPerCentimeterInOneKilogramPerMeter => 1e7; - protected override double MicrogramsPerMeterInOneKilogramPerMeter => 1e9; + protected override double MicrogramsPerMeterInOneKilogramPerMeter => 1e9; protected override double MilligramsPerMillimeterInOneKilogramPerMeter => 1e3; protected override double MilligramsPerCentimeterInOneKilogramPerMeter => 1e4; diff --git a/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs b/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs index c45766cbfa..698f31d116 100644 --- a/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs @@ -23,30 +23,31 @@ namespace UnitsNet.Tests.CustomCode { public class LinearPowerDensityTests : LinearPowerDensityTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double GigawattsPerCentimeterInOneWattPerMeter => 1e-11; protected override double GigawattsPerFootInOneWattPerMeter => 3.0480e-10; protected override double GigawattsPerInchInOneWattPerMeter => 2.5400e-11; protected override double GigawattsPerMeterInOneWattPerMeter => 1e-9; protected override double GigawattsPerMillimeterInOneWattPerMeter => 1e-12; - + protected override double MegawattsPerCentimeterInOneWattPerMeter => 1e-8; protected override double MegawattsPerFootInOneWattPerMeter => 3.0480e-7; protected override double MegawattsPerInchInOneWattPerMeter => 2.5400e-8; protected override double MegawattsPerMeterInOneWattPerMeter => 1e-6; protected override double MegawattsPerMillimeterInOneWattPerMeter => 1e-9; - + protected override double KilowattsPerCentimeterInOneWattPerMeter => 1e-5; protected override double KilowattsPerFootInOneWattPerMeter => 3.0480e-4; protected override double KilowattsPerInchInOneWattPerMeter => 2.5400e-5; protected override double KilowattsPerMeterInOneWattPerMeter => 1e-3; protected override double KilowattsPerMillimeterInOneWattPerMeter => 1e-6; - + protected override double WattsPerCentimeterInOneWattPerMeter => 1e-2; protected override double WattsPerFootInOneWattPerMeter => 3.0480e-1; protected override double WattsPerInchInOneWattPerMeter => 2.5400e-2; protected override double WattsPerMeterInOneWattPerMeter => 1; protected override double WattsPerMillimeterInOneWattPerMeter => 1e-3; - + protected override double MilliwattsPerCentimeterInOneWattPerMeter => 1e1; protected override double MilliwattsPerFootInOneWattPerMeter => 3.0480e2; protected override double MilliwattsPerInchInOneWattPerMeter => 2.5400e1; diff --git a/UnitsNet.Tests/CustomCode/LuminosityTests.cs b/UnitsNet.Tests/CustomCode/LuminosityTests.cs index 51ee9d494f..02882c3f3c 100644 --- a/UnitsNet.Tests/CustomCode/LuminosityTests.cs +++ b/UnitsNet.Tests/CustomCode/LuminosityTests.cs @@ -23,7 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class LuminosityTests : LuminosityTestsBase { - // Override properties in base class here + protected override bool SupportsSIUnitSystem => false; protected override double FemtowattsInOneWatt => 1e15; protected override double PicowattsInOneWatt => 1e12; diff --git a/UnitsNet.Tests/CustomCode/LuminousFluxTests.cs b/UnitsNet.Tests/CustomCode/LuminousFluxTests.cs index 1891301fcf..b24539f1ed 100644 --- a/UnitsNet.Tests/CustomCode/LuminousFluxTests.cs +++ b/UnitsNet.Tests/CustomCode/LuminousFluxTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class LuminousFluxTests : LuminousFluxTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double LumensInOneLumen => 1; } } diff --git a/UnitsNet.Tests/CustomCode/LuminousIntensityTests.cs b/UnitsNet.Tests/CustomCode/LuminousIntensityTests.cs index acbaf7ef60..437464f316 100644 --- a/UnitsNet.Tests/CustomCode/LuminousIntensityTests.cs +++ b/UnitsNet.Tests/CustomCode/LuminousIntensityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class LuminousIntensityTests : LuminousIntensityTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double CandelaInOneCandela => 1; } } diff --git a/UnitsNet.Tests/CustomCode/MagneticFieldTests.cs b/UnitsNet.Tests/CustomCode/MagneticFieldTests.cs index a22c8b50ae..b0e7e3bfe6 100644 --- a/UnitsNet.Tests/CustomCode/MagneticFieldTests.cs +++ b/UnitsNet.Tests/CustomCode/MagneticFieldTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class MagneticFieldTests : MagneticFieldTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double TeslasInOneTesla => 1; protected override double NanoteslasInOneTesla => 1e9; protected override double MicroteslasInOneTesla => 1e6; diff --git a/UnitsNet.Tests/CustomCode/MagneticFluxTests.cs b/UnitsNet.Tests/CustomCode/MagneticFluxTests.cs index a7ce8b20fa..ea843ab619 100644 --- a/UnitsNet.Tests/CustomCode/MagneticFluxTests.cs +++ b/UnitsNet.Tests/CustomCode/MagneticFluxTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class MagneticFluxTests : MagneticFluxTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double WebersInOneWeber => 1; } } diff --git a/UnitsNet.Tests/CustomCode/MagnetizationTests.cs b/UnitsNet.Tests/CustomCode/MagnetizationTests.cs index 90f87434b3..13065f4eb2 100644 --- a/UnitsNet.Tests/CustomCode/MagnetizationTests.cs +++ b/UnitsNet.Tests/CustomCode/MagnetizationTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class MagnetizationTests : MagnetizationTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double AmperesPerMeterInOneAmperePerMeter => 1; } } diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs index 311b4cc7d6..f5d8091b9d 100644 --- a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -28,6 +28,8 @@ namespace UnitsNet.Tests.CustomCode { public class MassConcentrationTests : MassConcentrationTestsBase { + protected override bool SupportsSIUnitSystem => false; + #region Unit Conversion Coefficients protected override double PicogramsPerLiterInOneKilogramPerCubicMeter => 1e12; protected override double PicogramsPerMicroliterInOneKilogramPerCubicMeter => 1e6; @@ -126,7 +128,7 @@ public static void ComponentMassFromMassConcentrationAndSolutionVolume( var volume = new Volume(volumeValue, volumeUnit); Mass massComponent = massConcentration * volume; - + AssertEx.EqualTolerance(expectedMassValue, massComponent.As(expectedMassUnit), tolerance); } diff --git a/UnitsNet.Tests/CustomCode/MassFlowTests.cs b/UnitsNet.Tests/CustomCode/MassFlowTests.cs index b407d74dfa..e59fa41f18 100644 --- a/UnitsNet.Tests/CustomCode/MassFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFlowTests.cs @@ -8,7 +8,8 @@ namespace UnitsNet.Tests.CustomCode { public class MassFlowTests : MassFlowTestsBase { - /// + protected override bool SupportsSIUnitSystem => false; + protected override double GramsPerSecondInOneGramPerSecond => 1; protected override double DecagramsPerSecondInOneGramPerSecond => 1E-1; diff --git a/UnitsNet.Tests/CustomCode/MassFluxTests.cs b/UnitsNet.Tests/CustomCode/MassFluxTests.cs index 148ed1af37..99be1f8e51 100644 --- a/UnitsNet.Tests/CustomCode/MassFluxTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFluxTests.cs @@ -26,6 +26,7 @@ namespace UnitsNet.Tests.CustomCode { public class MassFluxTests : MassFluxTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 1E3; protected override double GramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 1E-1; protected override double GramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 1E-3; @@ -40,7 +41,7 @@ public class MassFluxTests : MassFluxTestsBase protected override double KilogramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 3.6E3; protected override double KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-1; - protected override double KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-3; + protected override double KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-3; [Fact] diff --git a/UnitsNet.Tests/CustomCode/MassFractionTests.cs b/UnitsNet.Tests/CustomCode/MassFractionTests.cs index 4f29919a7a..39435e7243 100644 --- a/UnitsNet.Tests/CustomCode/MassFractionTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFractionTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class MassFractionTests : MassFractionTestsBase { + protected override bool SupportsSIUnitSystem => false; + #region Unit Conversion Coefficients protected override double KilogramsPerKilogramInOneDecimalFraction => 1; protected override double HectogramsPerKilogramInOneDecimalFraction => 10; @@ -54,7 +56,7 @@ public class MassFractionTests : MassFractionTestsBase protected override double PartsPerTrillionInOneDecimalFraction => 1e12; protected override double DecimalFractionsInOneDecimalFraction => 1; - protected override double PercentInOneDecimalFraction => 100; + protected override double PercentInOneDecimalFraction => 100; #endregion [Fact] diff --git a/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs b/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs index ac2f1ef4c1..edc7d56a16 100644 --- a/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs +++ b/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs @@ -27,6 +27,8 @@ namespace UnitsNet.Tests.CustomCode { public class MassMomentOfInertiaTests : MassMomentOfInertiaTestsBase { + protected override bool SupportsSIUnitSystem => false; + protected override double GramSquareCentimetersInOneKilogramSquareMeter => 1e7; protected override double GramSquareDecimetersInOneKilogramSquareMeter => 1e5; diff --git a/UnitsNet.Tests/CustomCode/MassTests.cs b/UnitsNet.Tests/CustomCode/MassTests.cs index 18cb904f33..decfa077cf 100644 --- a/UnitsNet.Tests/CustomCode/MassTests.cs +++ b/UnitsNet.Tests/CustomCode/MassTests.cs @@ -9,6 +9,8 @@ namespace UnitsNet.Tests.CustomCode { public class MassTests : MassTestsBase { + protected override bool SupportsSIUnitSystem => false; // Should be true, but prefixes on "Gram" not supported yet. + protected override double CentigramsInOneKilogram => 1E5; protected override double DecagramsInOneKilogram => 1E2; diff --git a/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs b/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs index d309d8744a..5b05835c78 100644 --- a/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class MolarEnergyTests : MolarEnergyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double JoulesPerMoleInOneJoulePerMole => 1e0; protected override double KilojoulesPerMoleInOneJoulePerMole => 1e-3; protected override double MegajoulesPerMoleInOneJoulePerMole => 1e-6; diff --git a/UnitsNet.Tests/CustomCode/MolarEntropyTests.cs b/UnitsNet.Tests/CustomCode/MolarEntropyTests.cs index 3021519d49..0c30532e2e 100644 --- a/UnitsNet.Tests/CustomCode/MolarEntropyTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarEntropyTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class MolarEntropyTests : MolarEntropyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double JoulesPerMoleKelvinInOneJoulePerMoleKelvin => 1e0; protected override double KilojoulesPerMoleKelvinInOneJoulePerMoleKelvin => 1e-3; protected override double MegajoulesPerMoleKelvinInOneJoulePerMoleKelvin => 1e-6; diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs index 585c4e1dfa..d954425a7a 100644 --- a/UnitsNet.Tests/CustomCode/MolarMassTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs @@ -28,6 +28,7 @@ namespace UnitsNet.Tests.CustomCode { public class MolarMassTests : MolarMassTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double CentigramsPerMoleInOneKilogramPerMole => 1e5; protected override double DecagramsPerMoleInOneKilogramPerMole => 1e2; protected override double DecigramsPerMoleInOneKilogramPerMole => 1e4; @@ -41,6 +42,6 @@ public class MolarMassTests : MolarMassTestsBase protected override double NanogramsPerMoleTolerance => 1e-3; protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12; protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; - + } } diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index c7cfadd076..04150f0dca 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -29,6 +29,8 @@ namespace UnitsNet.Tests.CustomCode { public class MolarityTests : MolarityTestsBase { + protected override bool SupportsSIUnitSystem => true; + #region Unit Conversion Coefficients protected override double CentimolesPerLiterInOneMolesPerCubicMeter => 1e-1; protected override double DecimolesPerLiterInOneMolesPerCubicMeter => 1e-2; @@ -39,7 +41,7 @@ public class MolarityTests : MolarityTestsBase protected override double NanomolesPerLiterInOneMolesPerCubicMeter => 1e6; protected override double PicomolesPerLiterInOneMolesPerCubicMeter => 1e9; #endregion - + [Theory] [InlineData(0.5, MolarityUnit.MolesPerLiter, KnownQuantities.DensityOfEthanolInKgPerCubicMeter, DensityUnit.KilogramPerCubicMeter, diff --git a/UnitsNet.Tests/CustomCode/PermeabilityTests.cs b/UnitsNet.Tests/CustomCode/PermeabilityTests.cs index 7052a2132a..5127ff430d 100644 --- a/UnitsNet.Tests/CustomCode/PermeabilityTests.cs +++ b/UnitsNet.Tests/CustomCode/PermeabilityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class PermeabilityTests : PermeabilityTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double HenriesPerMeterInOneHenryPerMeter => 1; } } diff --git a/UnitsNet.Tests/CustomCode/PermittivityTests.cs b/UnitsNet.Tests/CustomCode/PermittivityTests.cs index bbb7cb9355..5a13b8bb2d 100644 --- a/UnitsNet.Tests/CustomCode/PermittivityTests.cs +++ b/UnitsNet.Tests/CustomCode/PermittivityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class PermittivityTests : PermittivityTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double FaradsPerMeterInOneFaradPerMeter => 1; } } diff --git a/UnitsNet.Tests/CustomCode/PowerDensityTests.cs b/UnitsNet.Tests/CustomCode/PowerDensityTests.cs index 1d5a2c8817..b90313935e 100644 --- a/UnitsNet.Tests/CustomCode/PowerDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/PowerDensityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class PowerDensityTests : PowerDensityTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double WattsPerCubicMeterInOneWattPerCubicMeter => 1; protected override double PicowattsPerCubicMeterInOneWattPerCubicMeter => 1e12; protected override double NanowattsPerCubicMeterInOneWattPerCubicMeter => 1e9; diff --git a/UnitsNet.Tests/CustomCode/PowerRatioTests.cs b/UnitsNet.Tests/CustomCode/PowerRatioTests.cs index 896c60b9bc..e6820ea023 100644 --- a/UnitsNet.Tests/CustomCode/PowerRatioTests.cs +++ b/UnitsNet.Tests/CustomCode/PowerRatioTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class PowerRatioTests : PowerRatioTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DecibelMilliwattsInOneDecibelWatt => 31; protected override double DecibelWattsInOneDecibelWatt => 1; diff --git a/UnitsNet.Tests/CustomCode/PowerTests.cs b/UnitsNet.Tests/CustomCode/PowerTests.cs index 03f5d72b24..5214d7a432 100644 --- a/UnitsNet.Tests/CustomCode/PowerTests.cs +++ b/UnitsNet.Tests/CustomCode/PowerTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class PowerTests : PowerTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double FemtowattsInOneWatt => 1e15; protected override double GigajoulesPerHourInOneWatt => 3600e-9; diff --git a/UnitsNet.Tests/CustomCode/PressureChangeRateTests.cs b/UnitsNet.Tests/CustomCode/PressureChangeRateTests.cs index fe16b06d88..5aa974e135 100644 --- a/UnitsNet.Tests/CustomCode/PressureChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/PressureChangeRateTests.cs @@ -5,6 +5,7 @@ namespace UnitsNet.Tests.CustomCode { public class PressureChangeRateTests : PressureChangeRateTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double AtmospheresPerSecondInOnePascalPerSecond => 9.8692*1E-6; protected override double KilopascalsPerSecondInOnePascalPerSecond => 1e-3; diff --git a/UnitsNet.Tests/CustomCode/PressureTests.cs b/UnitsNet.Tests/CustomCode/PressureTests.cs index 80288d8469..9e8f73f4d1 100644 --- a/UnitsNet.Tests/CustomCode/PressureTests.cs +++ b/UnitsNet.Tests/CustomCode/PressureTests.cs @@ -10,6 +10,7 @@ namespace UnitsNet.Tests.CustomCode { public class PressureTests : PressureTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double AtmospheresInOnePascal => 9.8692 * 1E-6; protected override double BarsInOnePascal => 1E-5; diff --git a/UnitsNet.Tests/CustomCode/RatioChangeRateTests.cs b/UnitsNet.Tests/CustomCode/RatioChangeRateTests.cs index b53dcbe33c..0bdcb0993f 100644 --- a/UnitsNet.Tests/CustomCode/RatioChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/RatioChangeRateTests.cs @@ -23,6 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class RatioChangeRateTests : RatioChangeRateTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DecimalFractionsPerSecondInOneDecimalFractionPerSecond => 1; protected override double PercentsPerSecondInOneDecimalFractionPerSecond => 100; } diff --git a/UnitsNet.Tests/CustomCode/RatioTests.cs b/UnitsNet.Tests/CustomCode/RatioTests.cs index c9d789e374..d48694a80c 100644 --- a/UnitsNet.Tests/CustomCode/RatioTests.cs +++ b/UnitsNet.Tests/CustomCode/RatioTests.cs @@ -5,6 +5,7 @@ namespace UnitsNet.Tests.CustomCode { public class RatioTests : RatioTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DecimalFractionsInOneDecimalFraction => 1; protected override double PartsPerBillionInOneDecimalFraction => 1e9; diff --git a/UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs b/UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs index 26b0ff2031..2cd682b8ae 100644 --- a/UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ReactiveEnergyTests : ReactiveEnergyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double VoltampereReactiveHoursInOneVoltampereReactiveHour => 1; protected override double KilovoltampereReactiveHoursInOneVoltampereReactiveHour => 1E-3; diff --git a/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs b/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs index b6c11ad9aa..184a40d2f4 100644 --- a/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs +++ b/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ReactivePowerTests : ReactivePowerTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double VoltamperesReactiveInOneVoltampereReactive => 1; protected override double KilovoltamperesReactiveInOneVoltampereReactive => 1E-3; diff --git a/UnitsNet.Tests/CustomCode/RotationalAccelerationTests.cs b/UnitsNet.Tests/CustomCode/RotationalAccelerationTests.cs index 571f26aa72..03ca646477 100644 --- a/UnitsNet.Tests/CustomCode/RotationalAccelerationTests.cs +++ b/UnitsNet.Tests/CustomCode/RotationalAccelerationTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class RotationalAccelerationTests : RotationalAccelerationTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DegreesPerSecondSquaredInOneRadianPerSecondSquared => 180 / Math.PI; protected override double RadiansPerSecondSquaredInOneRadianPerSecondSquared => 1; protected override double RevolutionsPerMinutePerSecondInOneRadianPerSecondSquared => 9.549296586; diff --git a/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs b/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs index e65f9f8f92..d06ba83b0d 100644 --- a/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class RotationalSpeedTests : RotationalSpeedTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double RadiansPerSecondInOneRadianPerSecond => 1; protected override double DeciradiansPerSecondInOneRadianPerSecond => 1E1; diff --git a/UnitsNet.Tests/CustomCode/RotationalStiffnessPerLengthTests.cs b/UnitsNet.Tests/CustomCode/RotationalStiffnessPerLengthTests.cs index 674008b663..ff49df615e 100644 --- a/UnitsNet.Tests/CustomCode/RotationalStiffnessPerLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/RotationalStiffnessPerLengthTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class RotationalStiffnessPerLengthTests : RotationalStiffnessPerLengthTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter => 1E-3; protected override double KilopoundForceFeetPerDegreesPerFeetInOneNewtonMeterPerRadianPerMeter => 3.92365625e-6; protected override double MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter => 1E-6; diff --git a/UnitsNet.Tests/CustomCode/RotationalStiffnessTests.cs b/UnitsNet.Tests/CustomCode/RotationalStiffnessTests.cs index 28fd8ea29e..223accaec8 100644 --- a/UnitsNet.Tests/CustomCode/RotationalStiffnessTests.cs +++ b/UnitsNet.Tests/CustomCode/RotationalStiffnessTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class RotationalStiffnessTests : RotationalStiffnessTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilopoundForceFeetPerDegreesInOneNewtonMeterPerRadian => 0.0128729e-3; protected override double PoundForceFeetPerRadianInOneNewtonMeterPerRadian => 7.375621e-1; protected override double PoundForceFeetPerDegreesInOneNewtonMeterPerRadian => 1.287290e-2; diff --git a/UnitsNet.Tests/CustomCode/SolidAngleTests.cs b/UnitsNet.Tests/CustomCode/SolidAngleTests.cs index 33776fc85f..942c8b6ab0 100644 --- a/UnitsNet.Tests/CustomCode/SolidAngleTests.cs +++ b/UnitsNet.Tests/CustomCode/SolidAngleTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class SolidAngleTests : SolidAngleTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double SteradiansInOneSteradian => 1; } } diff --git a/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs b/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs index c15a517bba..d0e073042e 100644 --- a/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/SpecificEnergyTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class SpecificEnergyTests : SpecificEnergyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double JoulesPerKilogramInOneJoulePerKilogram => 1e0; protected override double KilojoulesPerKilogramInOneJoulePerKilogram => 1e-3; protected override double MegajoulesPerKilogramInOneJoulePerKilogram => 1e-6; @@ -38,7 +39,7 @@ public class SpecificEnergyTests : SpecificEnergyTestsBase protected override double MegawattDaysPerTonneInOneJoulePerKilogram => 1.15740741E-8; protected override double GigawattDaysPerTonneInOneJoulePerKilogram => 1.15740741E-11; protected override double TerawattDaysPerTonneInOneJoulePerKilogram => 1.15740741E-14; - + [Fact] public void MassTimesSpecificEnergyEqualsEnergy() diff --git a/UnitsNet.Tests/CustomCode/SpecificEntropyTests.cs b/UnitsNet.Tests/CustomCode/SpecificEntropyTests.cs index f627e7a254..eedf26d423 100644 --- a/UnitsNet.Tests/CustomCode/SpecificEntropyTests.cs +++ b/UnitsNet.Tests/CustomCode/SpecificEntropyTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class SpecificEntropyTests : SpecificEntropyTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double JoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin => 1e0; protected override double JoulesPerKilogramKelvinInOneJoulePerKilogramKelvin => 1e0; protected override double KilojoulesPerKilogramDegreeCelsiusInOneJoulePerKilogramKelvin => 1e-3; diff --git a/UnitsNet.Tests/CustomCode/SpecificVolumeTests.cs b/UnitsNet.Tests/CustomCode/SpecificVolumeTests.cs index 22fa0ff17e..11fd0a396d 100644 --- a/UnitsNet.Tests/CustomCode/SpecificVolumeTests.cs +++ b/UnitsNet.Tests/CustomCode/SpecificVolumeTests.cs @@ -26,6 +26,7 @@ namespace UnitsNet.Tests.CustomCode { public class SpecificVolumeTests : SpecificVolumeTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double CubicMetersPerKilogramInOneCubicMeterPerKilogram => 1; protected override double CubicFeetPerPoundInOneCubicMeterPerKilogram => 16.01846353; diff --git a/UnitsNet.Tests/CustomCode/SpecificWeightTests.cs b/UnitsNet.Tests/CustomCode/SpecificWeightTests.cs index ca86cd7f5e..6a4a4ceecc 100644 --- a/UnitsNet.Tests/CustomCode/SpecificWeightTests.cs +++ b/UnitsNet.Tests/CustomCode/SpecificWeightTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class SpecificWeightTests : SpecificWeightTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilogramsForcePerCubicCentimeterInOneNewtonPerCubicMeter => 1.019716212977928e-7; protected override double KilogramsForcePerCubicMeterInOneNewtonPerCubicMeter => 0.101971621; diff --git a/UnitsNet.Tests/CustomCode/SpeedTests.cs b/UnitsNet.Tests/CustomCode/SpeedTests.cs index cc96ce9c80..f47618c4e5 100644 --- a/UnitsNet.Tests/CustomCode/SpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/SpeedTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class SpeedTests : SpeedTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double FeetPerSecondInOneMeterPerSecond => 3.28084; protected override double KilometersPerHourInOneMeterPerSecond => 3.6; diff --git a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs index 17f17a8201..bc3ea93e2d 100644 --- a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs @@ -5,6 +5,7 @@ namespace UnitsNet.Tests.CustomCode { public class TemperatureChangeRateTests : TemperatureChangeRateTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond => 1; protected override double DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond => 1E-1; diff --git a/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs b/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs index 782c02f3ae..1efbdffbac 100644 --- a/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs +++ b/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs @@ -26,6 +26,7 @@ namespace UnitsNet.Tests.CustomCode { public class TemperatureDeltaTests : TemperatureDeltaTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double DegreesCelsiusInOneKelvin => 1; protected override double DegreesDelisleInOneKelvin => -1.5d; protected override double DegreesFahrenheitInOneKelvin => 1.8; diff --git a/UnitsNet.Tests/CustomCode/TemperatureTests.cs b/UnitsNet.Tests/CustomCode/TemperatureTests.cs index 5deedb882e..441ce154ae 100644 --- a/UnitsNet.Tests/CustomCode/TemperatureTests.cs +++ b/UnitsNet.Tests/CustomCode/TemperatureTests.cs @@ -9,6 +9,7 @@ namespace UnitsNet.Tests.CustomCode { public class TemperatureTests : TemperatureTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double DegreesCelsiusInOneKelvin => -272.15; protected override double DegreesDelisleInOneKelvin => 558.2249999999999; diff --git a/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs b/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs new file mode 100644 index 0000000000..ec0d61aa69 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs @@ -0,0 +1,11 @@ +namespace UnitsNet.Tests.TestsBase +{ + public abstract class QuantityTestsBase + { + /// + /// Whether this quantity has one or more units compatible with . + /// This is used to test whether methods methods accepting this unit system value will throw an exception or produce a value. + /// + protected abstract bool SupportsSIUnitSystem { get; } + } +} diff --git a/UnitsNet.Tests/CustomCode/ThermalConductivityTests.cs b/UnitsNet.Tests/CustomCode/ThermalConductivityTests.cs index fe566b4a13..d626049d23 100644 --- a/UnitsNet.Tests/CustomCode/ThermalConductivityTests.cs +++ b/UnitsNet.Tests/CustomCode/ThermalConductivityTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ThermalConductivityTests : ThermalConductivityTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double WattsPerMeterKelvinInOneWattPerMeterKelvin => 1; protected override double BtusPerHourFootFahrenheitInOneWattPerMeterKelvin => 5.77789317e-1; } diff --git a/UnitsNet.Tests/CustomCode/ThermalResistanceTests.cs b/UnitsNet.Tests/CustomCode/ThermalResistanceTests.cs index c44027c3a7..3f34f6cd7c 100644 --- a/UnitsNet.Tests/CustomCode/ThermalResistanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ThermalResistanceTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class ThermalResistanceTests : ThermalResistanceTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double HourSquareFeetDegreesFahrenheitPerBtuInOneSquareMeterKelvinPerKilowatt => 0.0056782d; protected override double SquareCentimeterHourDegreesCelsiusPerKilocalorieInOneSquareMeterKelvinPerKilowatt => 11.63088897992627d; protected override double SquareCentimeterKelvinsPerWattInOneSquareMeterKelvinPerKilowatt => 10.00035223670306d; diff --git a/UnitsNet.Tests/CustomCode/TorquePerLengthTests.cs b/UnitsNet.Tests/CustomCode/TorquePerLengthTests.cs index 04217bfe2a..783cd49716 100644 --- a/UnitsNet.Tests/CustomCode/TorquePerLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/TorquePerLengthTests.cs @@ -23,7 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class TorquePerLengthTests : TorquePerLengthTestsBase { - // Override properties in base class here + protected override bool SupportsSIUnitSystem => false; protected override double KilogramForceCentimetersPerMeterInOneNewtonMeterPerMeter => 10.197162130; protected override double KilogramForceMetersPerMeterInOneNewtonMeterPerMeter => 0.101971621; protected override double KilogramForceMillimetersPerMeterInOneNewtonMeterPerMeter => 101.971621298; diff --git a/UnitsNet.Tests/CustomCode/TorqueTests.cs b/UnitsNet.Tests/CustomCode/TorqueTests.cs index aef7961cb1..2c9b540ab8 100644 --- a/UnitsNet.Tests/CustomCode/TorqueTests.cs +++ b/UnitsNet.Tests/CustomCode/TorqueTests.cs @@ -7,6 +7,7 @@ namespace UnitsNet.Tests.CustomCode { public class TorqueTests : TorqueTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double KilogramForceCentimetersInOneNewtonMeter => 10.1971621; protected override double KilogramForceMetersInOneNewtonMeter => 0.101971621; diff --git a/UnitsNet.Tests/CustomCode/TurbidityTests.cs b/UnitsNet.Tests/CustomCode/TurbidityTests.cs index 941f4d8e65..6b7041290b 100644 --- a/UnitsNet.Tests/CustomCode/TurbidityTests.cs +++ b/UnitsNet.Tests/CustomCode/TurbidityTests.cs @@ -23,7 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class TurbidityTests : TurbidityTestsBase { - // Override properties in base class here + protected override bool SupportsSIUnitSystem => false; protected override double NTUInOneNTU => 1; } } diff --git a/UnitsNet.Tests/CustomCode/VitaminATests.cs b/UnitsNet.Tests/CustomCode/VitaminATests.cs index 08fd058b54..5bd368c651 100644 --- a/UnitsNet.Tests/CustomCode/VitaminATests.cs +++ b/UnitsNet.Tests/CustomCode/VitaminATests.cs @@ -5,6 +5,7 @@ namespace UnitsNet.Tests.CustomCode { public class VitaminATests : VitaminATestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double InternationalUnitsInOneInternationalUnit => 1; } } diff --git a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs index 729517d139..92a8ab8406 100644 --- a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs @@ -28,6 +28,8 @@ namespace UnitsNet.Tests.CustomCode { public class VolumeConcentrationTests : VolumeConcentrationTestsBase { + protected override bool SupportsSIUnitSystem => false; + #region Unit Conversion Coefficients protected override double LitersPerMililiterInOneDecimalFraction => 1E-3; protected override double DecilitersPerMililiterInOneDecimalFraction => 1E-2; @@ -44,7 +46,7 @@ public class VolumeConcentrationTests : VolumeConcentrationTestsBase protected override double MicrolitersPerLiterInOneDecimalFraction => 1E6; protected override double NanolitersPerLiterInOneDecimalFraction => 1E9; protected override double PicolitersPerLiterInOneDecimalFraction => 1E12; - + protected override double PartsPerThousandInOneDecimalFraction => 1e3; protected override double PartsPerMillionInOneDecimalFraction => 1e6; protected override double PartsPerBillionInOneDecimalFraction => 1e9; @@ -60,7 +62,7 @@ public class VolumeConcentrationTests : VolumeConcentrationTestsBase 5, MassConcentrationUnit.GramPerCubicMeter)] // synthetic data [InlineData(29.19419518377693, VolumeConcentrationUnit.MillilitersPerLiter, KnownQuantities.DensityOfEthanolInKgPerCubicMeter, DensityUnit.KilogramPerCubicMeter, - 23.03422, MassConcentrationUnit.GramPerLiter)] // 29.19419518377693 = VolumeConcentration_0_5M_Ethanol + 23.03422, MassConcentrationUnit.GramPerLiter)] // 29.19419518377693 = VolumeConcentration_0_5M_Ethanol public void MassConcentrationFromVolumeConcentrationAndComponentDensity( double volumeConcValue, VolumeConcentrationUnit volumeConcUnit, double componentDensityValue, DensityUnit componentDensityUnit, diff --git a/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs b/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs index 4a79bf98e5..27c8c92d81 100644 --- a/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeFlowTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class VolumeFlowTests : VolumeFlowTestsBase { + protected override bool SupportsSIUnitSystem => false; protected override double CubicMetersPerHourInOneCubicMeterPerSecond => 3.6e3; protected override double CubicDecimetersPerMinuteInOneCubicMeterPerSecond => 6e4; diff --git a/UnitsNet.Tests/CustomCode/VolumePerLengthTests.cs b/UnitsNet.Tests/CustomCode/VolumePerLengthTests.cs index 011a8cb5ce..6379c4ac9c 100644 --- a/UnitsNet.Tests/CustomCode/VolumePerLengthTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumePerLengthTests.cs @@ -26,7 +26,7 @@ namespace UnitsNet.Tests.CustomCode { public class VolumePerLengthTests : VolumePerLengthTestsBase { - // Override properties in base class here + protected override bool SupportsSIUnitSystem => true; protected override double CubicMetersPerMeterInOneCubicMeterPerMeter => 1; protected override double LitersPerMeterInOneCubicMeterPerMeter => 1000; @@ -34,7 +34,7 @@ public class VolumePerLengthTests : VolumePerLengthTestsBase protected override double OilBarrelsPerFootInOneCubicMeterPerMeter => 1.917134088; protected override double CubicYardsPerFootInOneCubicMeterPerMeter => 0.3986633487670267521605; - + protected override double CubicYardsPerUsSurveyFootInOneCubicMeterPerMeter => 0.3986641460953189427984; protected override double LitersPerKilometerInOneCubicMeterPerMeter => 1E6; diff --git a/UnitsNet.Tests/CustomCode/VolumeTests.cs b/UnitsNet.Tests/CustomCode/VolumeTests.cs index 67d067ea6b..59413e5435 100644 --- a/UnitsNet.Tests/CustomCode/VolumeTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeTests.cs @@ -8,6 +8,7 @@ namespace UnitsNet.Tests.CustomCode { public class VolumeTests : VolumeTestsBase { + protected override bool SupportsSIUnitSystem => true; protected override double CentilitersInOneCubicMeter => 1E5; protected override double CubicCentimetersInOneCubicMeter => 1E6; diff --git a/UnitsNet.Tests/CustomCode/WarpingMomentOfInertiaTests.cs b/UnitsNet.Tests/CustomCode/WarpingMomentOfInertiaTests.cs index 1bc83cc3d6..d5155a5e73 100644 --- a/UnitsNet.Tests/CustomCode/WarpingMomentOfInertiaTests.cs +++ b/UnitsNet.Tests/CustomCode/WarpingMomentOfInertiaTests.cs @@ -23,7 +23,7 @@ namespace UnitsNet.Tests.CustomCode { public class WarpingMomentOfInertiaTests : WarpingMomentOfInertiaTestsBase { - // Override properties in base class here + protected override bool SupportsSIUnitSystem => true; protected override double CentimetersToTheSixthInOneMeterToTheSixth => 1e12; protected override double DecimetersToTheSixthInOneMeterToTheSixth => 1e6; protected override double FeetToTheSixthInOneMeterToTheSixth => 1247.12569; diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index a7bfeb7b11..f98c36cc8b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Acceleration. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AccelerationTestsBase + public abstract partial class AccelerationTestsBase : QuantityTestsBase { protected abstract double CentimetersPerSecondSquaredInOneMeterPerSecondSquared { get; } protected abstract double DecimetersPerSecondSquaredInOneMeterPerSecondSquared { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Acceleration(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Acceleration(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Acceleration(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Acceleration) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(StandardGravityInOneMeterPerSecondSquared, meterpersecondsquared.As(AccelerationUnit.StandardGravity), StandardGravityTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(AccelerationUnit.StandardGravity, standardgravityQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Acceleration.FromMetersPerSecondSquared(1).ToBaseUnit(); + Assert.Equal(Acceleration.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Acceleration.FromMetersPerSecondSquared(value); Assert.Equal(Acceleration.FromMetersPerSecondSquared(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index a98c19d80d..ba6a2ac882 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of AmountOfSubstance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AmountOfSubstanceTestsBase + public abstract partial class AmountOfSubstanceTestsBase : QuantityTestsBase { protected abstract double CentimolesInOneMole { get; } protected abstract double CentipoundMolesInOneMole { get; } @@ -101,7 +102,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new AmountOfSubstance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new AmountOfSubstance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new AmountOfSubstance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (AmountOfSubstance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -245,6 +261,23 @@ public void As() AssertEx.EqualTolerance(PoundMolesInOneMole, mole.As(AmountOfSubstanceUnit.PoundMole), PoundMolesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -311,6 +344,13 @@ public void ToUnit() Assert.Equal(AmountOfSubstanceUnit.PoundMole, poundmoleQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = AmountOfSubstance.FromMoles(1).ToBaseUnit(); + Assert.Equal(AmountOfSubstance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -739,6 +779,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = AmountOfSubstance.FromMoles(value); Assert.Equal(AmountOfSubstance.FromMoles(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index 708b250965..d03543b09f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of AmplitudeRatio. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AmplitudeRatioTestsBase + public abstract partial class AmplitudeRatioTestsBase : QuantityTestsBase { protected abstract double DecibelMicrovoltsInOneDecibelVolt { get; } protected abstract double DecibelMillivoltsInOneDecibelVolt { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new AmplitudeRatio(value: 1.0, unitSystem: null)); + Assert.Throws(() => new AmplitudeRatio(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new AmplitudeRatio(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (AmplitudeRatio) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(DecibelVoltsInOneDecibelVolt, decibelvolt.As(AmplitudeRatioUnit.DecibelVolt), DecibelVoltsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(AmplitudeRatioUnit.DecibelVolt, decibelvoltQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = AmplitudeRatio.FromDecibelVolts(1).ToBaseUnit(); + Assert.Equal(AmplitudeRatio.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -578,6 +618,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = AmplitudeRatio.FromDecibelVolts(value); Assert.Equal(AmplitudeRatio.FromDecibelVolts(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index 0febe024a9..175e958d5b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Angle. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AngleTestsBase + public abstract partial class AngleTestsBase : QuantityTestsBase { protected abstract double ArcminutesInOneDegree { get; } protected abstract double ArcsecondsInOneDegree { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Angle(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Angle(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Angle(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Angle) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(RevolutionsInOneDegree, degree.As(AngleUnit.Revolution), RevolutionsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Angle(value: 1, unit: Angle.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(AngleUnit.Revolution, revolutionQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Angle.FromDegrees(1).ToBaseUnit(); + Assert.Equal(Angle.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Angle.FromDegrees(value); Assert.Equal(Angle.FromDegrees(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs index 4fa051c4f5..4ca4ff3eea 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ApparentEnergy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ApparentEnergyTestsBase + public abstract partial class ApparentEnergyTestsBase : QuantityTestsBase { protected abstract double KilovoltampereHoursInOneVoltampereHour { get; } protected abstract double MegavoltampereHoursInOneVoltampereHour { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ApparentEnergy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ApparentEnergy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ApparentEnergy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ApparentEnergy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.VoltampereHour), VoltampereHoursTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ApparentEnergy(value: 1, unit: ApparentEnergy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(ApparentEnergyUnit.VoltampereHour, voltamperehourQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ApparentEnergy.FromVoltampereHours(1).ToBaseUnit(); + Assert.Equal(ApparentEnergy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ApparentEnergy.FromVoltampereHours(value); Assert.Equal(ApparentEnergy.FromVoltampereHours(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs index a26aece968..abc15b577e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ApparentPower. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ApparentPowerTestsBase + public abstract partial class ApparentPowerTestsBase : QuantityTestsBase { protected abstract double GigavoltamperesInOneVoltampere { get; } protected abstract double KilovoltamperesInOneVoltampere { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ApparentPower(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ApparentPower(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ApparentPower(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ApparentPower) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(VoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Voltampere), VoltamperesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ApparentPower(value: 1, unit: ApparentPower.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(ApparentPowerUnit.Voltampere, voltampereQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ApparentPower.FromVoltamperes(1).ToBaseUnit(); + Assert.Equal(ApparentPower.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ApparentPower.FromVoltamperes(value); Assert.Equal(ApparentPower.FromVoltamperes(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index dddc3a8f76..dcf0c7e6ce 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of AreaDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AreaDensityTestsBase + public abstract partial class AreaDensityTestsBase : QuantityTestsBase { protected abstract double KilogramsPerSquareMeterInOneKilogramPerSquareMeter { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new AreaDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new AreaDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new AreaDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (AreaDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(KilogramsPerSquareMeterInOneKilogramPerSquareMeter, kilogrampersquaremeter.As(AreaDensityUnit.KilogramPerSquareMeter), KilogramsPerSquareMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(AreaDensityUnit.KilogramPerSquareMeter, kilogrampersquaremeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = AreaDensity.FromKilogramsPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(AreaDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = AreaDensity.FromKilogramsPerSquareMeter(value); Assert.Equal(AreaDensity.FromKilogramsPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 2249a49b0a..ea27040de2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of AreaMomentOfInertia. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AreaMomentOfInertiaTestsBase + public abstract partial class AreaMomentOfInertiaTestsBase : QuantityTestsBase { protected abstract double CentimetersToTheFourthInOneMeterToTheFourth { get; } protected abstract double DecimetersToTheFourthInOneMeterToTheFourth { get; } @@ -83,7 +84,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new AreaMomentOfInertia(value: 1.0, unitSystem: null)); + Assert.Throws(() => new AreaMomentOfInertia(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new AreaMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (AreaMomentOfInertia) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -173,6 +189,23 @@ public void As() AssertEx.EqualTolerance(MillimetersToTheFourthInOneMeterToTheFourth, metertothefourth.As(AreaMomentOfInertiaUnit.MillimeterToTheFourth), MillimetersToTheFourthTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -203,6 +236,13 @@ public void ToUnit() Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, millimetertothefourthQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = AreaMomentOfInertia.FromMetersToTheFourth(1).ToBaseUnit(); + Assert.Equal(AreaMomentOfInertia.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -604,6 +644,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = AreaMomentOfInertia.FromMetersToTheFourth(value); Assert.Equal(AreaMomentOfInertia.FromMetersToTheFourth(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index 8c75c47491..a36d595122 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Area. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class AreaTestsBase + public abstract partial class AreaTestsBase : QuantityTestsBase { protected abstract double AcresInOneSquareMeter { get; } protected abstract double HectaresInOneSquareMeter { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Area(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Area(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Area(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Area) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(UsSurveySquareFeetInOneSquareMeter, squaremeter.As(AreaUnit.UsSurveySquareFoot), UsSurveySquareFeetTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Area(value: 1, unit: Area.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(AreaUnit.UsSurveySquareFoot, ussurveysquarefootQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Area.FromSquareMeters(1).ToBaseUnit(); + Assert.Equal(Area.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Area.FromSquareMeters(value); Assert.Equal(Area.FromSquareMeters(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index 412db29a2d..bc8b14eed8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of BitRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class BitRateTestsBase + public abstract partial class BitRateTestsBase : QuantityTestsBase { protected abstract double BitsPerSecondInOneBitPerSecond { get; } protected abstract double BytesPerSecondInOneBitPerSecond { get; } @@ -107,6 +108,27 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() } + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new BitRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new BitRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (BitRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + [Fact] public void BitRate_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -301,6 +323,23 @@ public void As() AssertEx.EqualTolerance(TerabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TerabytePerSecond), TerabytesPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -411,6 +450,13 @@ public void ToUnit() Assert.Equal(BitRateUnit.TerabytePerSecond, terabytepersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = BitRate.FromBitsPerSecond(1).ToBaseUnit(); + Assert.Equal(BitRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -872,6 +918,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = BitRate.FromBitsPerSecond(value); Assert.Equal(BitRate.FromBitsPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index c23cdb9618..8f6daa3d32 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of BrakeSpecificFuelConsumption. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class BrakeSpecificFuelConsumptionTestsBase + public abstract partial class BrakeSpecificFuelConsumptionTestsBase : QuantityTestsBase { protected abstract double GramsPerKiloWattHourInOneKilogramPerJoule { get; } protected abstract double KilogramsPerJouleInOneKilogramPerJoule { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new BrakeSpecificFuelConsumption(value: 1.0, unitSystem: null)); + Assert.Throws(() => new BrakeSpecificFuelConsumption(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new BrakeSpecificFuelConsumption(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (BrakeSpecificFuelConsumption) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(PoundsPerMechanicalHorsepowerHourInOneKilogramPerJoule, kilogramperjoule.As(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour), PoundsPerMechanicalHorsepowerHourTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, poundpermechanicalhorsepowerhourQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(1).ToBaseUnit(); + Assert.Equal(BrakeSpecificFuelConsumption.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = BrakeSpecificFuelConsumption.FromKilogramsPerJoule(value); Assert.Equal(BrakeSpecificFuelConsumption.FromKilogramsPerJoule(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs index 9d80acb031..b67fb6607f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Capacitance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class CapacitanceTestsBase + public abstract partial class CapacitanceTestsBase : QuantityTestsBase { protected abstract double FaradsInOneFarad { get; } protected abstract double KilofaradsInOneFarad { get; } @@ -85,7 +86,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Capacitance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Capacitance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Capacitance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Capacitance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -181,6 +197,23 @@ public void As() AssertEx.EqualTolerance(PicofaradsInOneFarad, farad.As(CapacitanceUnit.Picofarad), PicofaradsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Capacitance(value: 1, unit: Capacitance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -215,6 +248,13 @@ public void ToUnit() Assert.Equal(CapacitanceUnit.Picofarad, picofaradQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Capacitance.FromFarads(1).ToBaseUnit(); + Assert.Equal(Capacitance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -619,6 +659,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Capacitance.FromFarads(value); Assert.Equal(Capacitance.FromFarads(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index ca39d1c031..7f7986e144 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of CoefficientOfThermalExpansion. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class CoefficientOfThermalExpansionTestsBase + public abstract partial class CoefficientOfThermalExpansionTestsBase : QuantityTestsBase { protected abstract double InverseDegreeCelsiusInOneInverseKelvin { get; } protected abstract double InverseDegreeFahrenheitInOneInverseKelvin { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new CoefficientOfThermalExpansion(value: 1.0, unitSystem: null)); + Assert.Throws(() => new CoefficientOfThermalExpansion(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new CoefficientOfThermalExpansion(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (CoefficientOfThermalExpansion) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(InverseKelvinInOneInverseKelvin, inversekelvin.As(CoefficientOfThermalExpansionUnit.InverseKelvin), InverseKelvinTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(CoefficientOfThermalExpansionUnit.InverseKelvin, inversekelvinQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = CoefficientOfThermalExpansion.FromInverseKelvin(1).ToBaseUnit(); + Assert.Equal(CoefficientOfThermalExpansion.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = CoefficientOfThermalExpansion.FromInverseKelvin(value); Assert.Equal(CoefficientOfThermalExpansion.FromInverseKelvin(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index 0e541d999b..c0564e3d87 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Density. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class DensityTestsBase + public abstract partial class DensityTestsBase : QuantityTestsBase { protected abstract double CentigramsPerDeciLiterInOneKilogramPerCubicMeter { get; } protected abstract double CentigramsPerLiterInOneKilogramPerCubicMeter { get; } @@ -151,7 +152,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Density(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Density(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Density(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Density) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -445,6 +461,23 @@ public void As() AssertEx.EqualTolerance(TonnesPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(DensityUnit.TonnePerCubicMillimeter), TonnesPerCubicMillimeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Density(value: 1, unit: Density.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -611,6 +644,13 @@ public void ToUnit() Assert.Equal(DensityUnit.TonnePerCubicMillimeter, tonnepercubicmillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Density.FromKilogramsPerCubicMeter(1).ToBaseUnit(); + Assert.Equal(Density.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1114,6 +1154,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Density.FromKilogramsPerCubicMeter(value); Assert.Equal(Density.FromKilogramsPerCubicMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index ec6cd5b9df..5faf7e3faa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Duration. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class DurationTestsBase + public abstract partial class DurationTestsBase : QuantityTestsBase { protected abstract double DaysInOneSecond { get; } protected abstract double HoursInOneSecond { get; } @@ -91,7 +92,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Duration(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Duration(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Duration(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Duration) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -205,6 +221,23 @@ public void As() AssertEx.EqualTolerance(Years365InOneSecond, second.As(DurationUnit.Year365), Years365Tolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -251,6 +284,13 @@ public void ToUnit() Assert.Equal(DurationUnit.Year365, year365Quantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Duration.FromSeconds(1).ToBaseUnit(); + Assert.Equal(Duration.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -664,6 +704,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Duration.FromSeconds(value); Assert.Equal(Duration.FromSeconds(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index 1165333af8..f6b72cc08b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of DynamicViscosity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class DynamicViscosityTestsBase + public abstract partial class DynamicViscosityTestsBase : QuantityTestsBase { protected abstract double CentipoiseInOneNewtonSecondPerMeterSquared { get; } protected abstract double MicropascalSecondsInOneNewtonSecondPerMeterSquared { get; } @@ -91,7 +92,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new DynamicViscosity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new DynamicViscosity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new DynamicViscosity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (DynamicViscosity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -205,6 +221,23 @@ public void As() AssertEx.EqualTolerance(ReynsInOneNewtonSecondPerMeterSquared, newtonsecondpermetersquared.As(DynamicViscosityUnit.Reyn), ReynsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -251,6 +284,13 @@ public void ToUnit() Assert.Equal(DynamicViscosityUnit.Reyn, reynQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = DynamicViscosity.FromNewtonSecondsPerMeterSquared(1).ToBaseUnit(); + Assert.Equal(DynamicViscosity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -664,6 +704,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = DynamicViscosity.FromNewtonSecondsPerMeterSquared(value); Assert.Equal(DynamicViscosity.FromNewtonSecondsPerMeterSquared(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index 2b0a035135..ebdd4d0503 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricAdmittance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricAdmittanceTestsBase + public abstract partial class ElectricAdmittanceTestsBase : QuantityTestsBase { protected abstract double MicrosiemensInOneSiemens { get; } protected abstract double MillisiemensInOneSiemens { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricAdmittance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricAdmittance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricAdmittance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricAdmittance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Siemens), SiemensTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(ElectricAdmittanceUnit.Siemens, siemensQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricAdmittance.FromSiemens(1).ToBaseUnit(); + Assert.Equal(ElectricAdmittance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricAdmittance.FromSiemens(value); Assert.Equal(ElectricAdmittance.FromSiemens(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index 0b0a1a8b91..0b8554d7d7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricChargeDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricChargeDensityTestsBase + public abstract partial class ElectricChargeDensityTestsBase : QuantityTestsBase { protected abstract double CoulombsPerCubicMeterInOneCoulombPerCubicMeter { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricChargeDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricChargeDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricChargeDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricChargeDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(CoulombsPerCubicMeterInOneCoulombPerCubicMeter, coulombpercubicmeter.As(ElectricChargeDensityUnit.CoulombPerCubicMeter), CoulombsPerCubicMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(ElectricChargeDensityUnit.CoulombPerCubicMeter, coulombpercubicmeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricChargeDensity.FromCoulombsPerCubicMeter(1).ToBaseUnit(); + Assert.Equal(ElectricChargeDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricChargeDensity.FromCoulombsPerCubicMeter(value); Assert.Equal(ElectricChargeDensity.FromCoulombsPerCubicMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index 6758d3fcea..5a53f18fb2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricCharge. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricChargeTestsBase + public abstract partial class ElectricChargeTestsBase : QuantityTestsBase { protected abstract double AmpereHoursInOneCoulomb { get; } protected abstract double CoulombsInOneCoulomb { get; } @@ -81,7 +82,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricCharge(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricCharge(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricCharge(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricCharge) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -165,6 +181,23 @@ public void As() AssertEx.EqualTolerance(MilliampereHoursInOneCoulomb, coulomb.As(ElectricChargeUnit.MilliampereHour), MilliampereHoursTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -191,6 +224,13 @@ public void ToUnit() Assert.Equal(ElectricChargeUnit.MilliampereHour, milliamperehourQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricCharge.FromCoulombs(1).ToBaseUnit(); + Assert.Equal(ElectricCharge.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -589,6 +629,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricCharge.FromCoulombs(value); Assert.Equal(ElectricCharge.FromCoulombs(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index 910069f4c3..787f81b99f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricConductance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricConductanceTestsBase + public abstract partial class ElectricConductanceTestsBase : QuantityTestsBase { protected abstract double MicrosiemensInOneSiemens { get; } protected abstract double MillisiemensInOneSiemens { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricConductance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricConductance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricConductance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricConductance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Siemens), SiemensTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(ElectricConductanceUnit.Siemens, siemensQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricConductance.FromSiemens(1).ToBaseUnit(); + Assert.Equal(ElectricConductance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricConductance.FromSiemens(value); Assert.Equal(ElectricConductance.FromSiemens(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index ecfc40aa40..6fc86c260b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricConductivity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricConductivityTestsBase + public abstract partial class ElectricConductivityTestsBase : QuantityTestsBase { protected abstract double SiemensPerFootInOneSiemensPerMeter { get; } protected abstract double SiemensPerInchInOneSiemensPerMeter { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricConductivity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricConductivity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricConductivity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricConductivity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(SiemensPerMeterInOneSiemensPerMeter, siemenspermeter.As(ElectricConductivityUnit.SiemensPerMeter), SiemensPerMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(ElectricConductivityUnit.SiemensPerMeter, siemenspermeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricConductivity.FromSiemensPerMeter(1).ToBaseUnit(); + Assert.Equal(ElectricConductivity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricConductivity.FromSiemensPerMeter(value); Assert.Equal(ElectricConductivity.FromSiemensPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index fe9de9d9ea..b4faadff06 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricCurrentDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricCurrentDensityTestsBase + public abstract partial class ElectricCurrentDensityTestsBase : QuantityTestsBase { protected abstract double AmperesPerSquareFootInOneAmperePerSquareMeter { get; } protected abstract double AmperesPerSquareInchInOneAmperePerSquareMeter { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricCurrentDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricCurrentDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricCurrentDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricCurrentDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(AmperesPerSquareMeterInOneAmperePerSquareMeter, amperepersquaremeter.As(ElectricCurrentDensityUnit.AmperePerSquareMeter), AmperesPerSquareMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareMeter, amperepersquaremeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricCurrentDensity.FromAmperesPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(ElectricCurrentDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricCurrentDensity.FromAmperesPerSquareMeter(value); Assert.Equal(ElectricCurrentDensity.FromAmperesPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index 95314e1e5e..12fec2b5dc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricCurrentGradient. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricCurrentGradientTestsBase + public abstract partial class ElectricCurrentGradientTestsBase : QuantityTestsBase { protected abstract double AmperesPerSecondInOneAmperePerSecond { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricCurrentGradient(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricCurrentGradient(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricCurrentGradient(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricCurrentGradient) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerSecond), AmperesPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, amperepersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricCurrentGradient.FromAmperesPerSecond(1).ToBaseUnit(); + Assert.Equal(ElectricCurrentGradient.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricCurrentGradient.FromAmperesPerSecond(value); Assert.Equal(ElectricCurrentGradient.FromAmperesPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index 317bf286b1..3140e04fe3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricCurrent. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricCurrentTestsBase + public abstract partial class ElectricCurrentTestsBase : QuantityTestsBase { protected abstract double AmperesInOneAmpere { get; } protected abstract double CentiamperesInOneAmpere { get; } @@ -87,7 +88,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricCurrent(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricCurrent(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricCurrent(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricCurrent) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -189,6 +205,23 @@ public void As() AssertEx.EqualTolerance(PicoamperesInOneAmpere, ampere.As(ElectricCurrentUnit.Picoampere), PicoamperesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -227,6 +260,13 @@ public void ToUnit() Assert.Equal(ElectricCurrentUnit.Picoampere, picoampereQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricCurrent.FromAmperes(1).ToBaseUnit(); + Assert.Equal(ElectricCurrent.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -634,6 +674,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricCurrent.FromAmperes(value); Assert.Equal(ElectricCurrent.FromAmperes(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index 6c1a712012..af7f19acd2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricField. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricFieldTestsBase + public abstract partial class ElectricFieldTestsBase : QuantityTestsBase { protected abstract double VoltsPerMeterInOneVoltPerMeter { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricField(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricField(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricField(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricField) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(VoltsPerMeterInOneVoltPerMeter, voltpermeter.As(ElectricFieldUnit.VoltPerMeter), VoltsPerMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(ElectricFieldUnit.VoltPerMeter, voltpermeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricField.FromVoltsPerMeter(1).ToBaseUnit(); + Assert.Equal(ElectricField.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricField.FromVoltsPerMeter(value); Assert.Equal(ElectricField.FromVoltsPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index 12c90919fc..4e45fdc963 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricInductance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricInductanceTestsBase + public abstract partial class ElectricInductanceTestsBase : QuantityTestsBase { protected abstract double HenriesInOneHenry { get; } protected abstract double MicrohenriesInOneHenry { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricInductance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricInductance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricInductance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricInductance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(NanohenriesInOneHenry, henry.As(ElectricInductanceUnit.Nanohenry), NanohenriesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(ElectricInductanceUnit.Nanohenry, nanohenryQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricInductance.FromHenries(1).ToBaseUnit(); + Assert.Equal(ElectricInductance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricInductance.FromHenries(value); Assert.Equal(ElectricInductance.FromHenries(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs index ca27c93970..130cbdf65d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricPotentialAc. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialAcTestsBase + public abstract partial class ElectricPotentialAcTestsBase : QuantityTestsBase { protected abstract double KilovoltsAcInOneVoltAc { get; } protected abstract double MegavoltsAcInOneVoltAc { get; } @@ -81,7 +82,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricPotentialAc(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricPotentialAc(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricPotentialAc(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricPotentialAc) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -165,6 +181,23 @@ public void As() AssertEx.EqualTolerance(VoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.VoltAc), VoltsAcTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricPotentialAc(value: 1, unit: ElectricPotentialAc.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -191,6 +224,13 @@ public void ToUnit() Assert.Equal(ElectricPotentialAcUnit.VoltAc, voltacQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricPotentialAc.FromVoltsAc(1).ToBaseUnit(); + Assert.Equal(ElectricPotentialAc.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -589,6 +629,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricPotentialAc.FromVoltsAc(value); Assert.Equal(ElectricPotentialAc.FromVoltsAc(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index 9bea7822d6..b7866168a2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricPotentialChangeRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialChangeRateTestsBase + public abstract partial class ElectricPotentialChangeRateTestsBase : QuantityTestsBase { protected abstract double KilovoltsPerHoursInOneVoltPerSecond { get; } protected abstract double KilovoltsPerMicrosecondsInOneVoltPerSecond { get; } @@ -111,7 +112,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricPotentialChangeRate(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricPotentialChangeRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricPotentialChangeRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricPotentialChangeRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -285,6 +301,23 @@ public void As() AssertEx.EqualTolerance(VoltsPerSecondsInOneVoltPerSecond, voltpersecond.As(ElectricPotentialChangeRateUnit.VoltPerSecond), VoltsPerSecondsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -371,6 +404,13 @@ public void ToUnit() Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, voltpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricPotentialChangeRate.FromVoltsPerSeconds(1).ToBaseUnit(); + Assert.Equal(ElectricPotentialChangeRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -814,6 +854,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricPotentialChangeRate.FromVoltsPerSeconds(value); Assert.Equal(ElectricPotentialChangeRate.FromVoltsPerSeconds(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs index ef1b6a2d63..9aee1ec661 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricPotentialDc. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialDcTestsBase + public abstract partial class ElectricPotentialDcTestsBase : QuantityTestsBase { protected abstract double KilovoltsDcInOneVoltDc { get; } protected abstract double MegavoltsDcInOneVoltDc { get; } @@ -81,7 +82,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricPotentialDc(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricPotentialDc(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricPotentialDc(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricPotentialDc) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -165,6 +181,23 @@ public void As() AssertEx.EqualTolerance(VoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.VoltDc), VoltsDcTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricPotentialDc(value: 1, unit: ElectricPotentialDc.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -191,6 +224,13 @@ public void ToUnit() Assert.Equal(ElectricPotentialDcUnit.VoltDc, voltdcQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricPotentialDc.FromVoltsDc(1).ToBaseUnit(); + Assert.Equal(ElectricPotentialDc.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -589,6 +629,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricPotentialDc.FromVoltsDc(value); Assert.Equal(ElectricPotentialDc.FromVoltsDc(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index c984d21229..3dcb3fb730 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricPotential. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialTestsBase + public abstract partial class ElectricPotentialTestsBase : QuantityTestsBase { protected abstract double KilovoltsInOneVolt { get; } protected abstract double MegavoltsInOneVolt { get; } @@ -81,7 +82,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricPotential(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricPotential(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricPotential(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricPotential) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -165,6 +181,23 @@ public void As() AssertEx.EqualTolerance(VoltsInOneVolt, volt.As(ElectricPotentialUnit.Volt), VoltsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -191,6 +224,13 @@ public void ToUnit() Assert.Equal(ElectricPotentialUnit.Volt, voltQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricPotential.FromVolts(1).ToBaseUnit(); + Assert.Equal(ElectricPotential.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -589,6 +629,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricPotential.FromVolts(value); Assert.Equal(ElectricPotential.FromVolts(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index 2176bc6587..9de3bd8081 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricResistance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricResistanceTestsBase + public abstract partial class ElectricResistanceTestsBase : QuantityTestsBase { protected abstract double GigaohmsInOneOhm { get; } protected abstract double KiloohmsInOneOhm { get; } @@ -83,7 +84,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricResistance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricResistance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricResistance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricResistance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -173,6 +189,23 @@ public void As() AssertEx.EqualTolerance(OhmsInOneOhm, ohm.As(ElectricResistanceUnit.Ohm), OhmsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -203,6 +236,13 @@ public void ToUnit() Assert.Equal(ElectricResistanceUnit.Ohm, ohmQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricResistance.FromOhms(1).ToBaseUnit(); + Assert.Equal(ElectricResistance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -604,6 +644,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricResistance.FromOhms(value); Assert.Equal(ElectricResistance.FromOhms(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index 88ff7e8500..523e13bb74 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricResistivity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricResistivityTestsBase + public abstract partial class ElectricResistivityTestsBase : QuantityTestsBase { protected abstract double KiloohmsCentimeterInOneOhmMeter { get; } protected abstract double KiloohmMetersInOneOhmMeter { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricResistivity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricResistivity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricResistivity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricResistivity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(PicoohmMetersInOneOhmMeter, ohmmeter.As(ElectricResistivityUnit.PicoohmMeter), PicoohmMetersTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(ElectricResistivityUnit.PicoohmMeter, picoohmmeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricResistivity.FromOhmMeters(1).ToBaseUnit(); + Assert.Equal(ElectricResistivity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricResistivity.FromOhmMeters(value); Assert.Equal(ElectricResistivity.FromOhmMeters(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index c7a52e7880..cf87122653 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ElectricSurfaceChargeDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricSurfaceChargeDensityTestsBase + public abstract partial class ElectricSurfaceChargeDensityTestsBase : QuantityTestsBase { protected abstract double CoulombsPerSquareCentimeterInOneCoulombPerSquareMeter { get; } protected abstract double CoulombsPerSquareInchInOneCoulombPerSquareMeter { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ElectricSurfaceChargeDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ElectricSurfaceChargeDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricSurfaceChargeDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricSurfaceChargeDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(CoulombsPerSquareMeterInOneCoulombPerSquareMeter, coulombpersquaremeter.As(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter), CoulombsPerSquareMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, coulombpersquaremeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ElectricSurfaceChargeDensity.FromCoulombsPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(ElectricSurfaceChargeDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ElectricSurfaceChargeDensity.FromCoulombsPerSquareMeter(value); Assert.Equal(ElectricSurfaceChargeDensity.FromCoulombsPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index 50bc4b5c24..146cbdb49c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Energy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class EnergyTestsBase + public abstract partial class EnergyTestsBase : QuantityTestsBase { protected abstract double BritishThermalUnitsInOneJoule { get; } protected abstract double CaloriesInOneJoule { get; } @@ -143,7 +144,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Energy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Energy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Energy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Energy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -413,6 +429,23 @@ public void As() AssertEx.EqualTolerance(WattHoursInOneJoule, joule.As(EnergyUnit.WattHour), WattHoursTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -563,6 +596,13 @@ public void ToUnit() Assert.Equal(EnergyUnit.WattHour, watthourQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Energy.FromJoules(1).ToBaseUnit(); + Assert.Equal(Energy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1054,6 +1094,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Energy.FromJoules(value); Assert.Equal(Energy.FromJoules(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index dd87f6ab7a..bf152e26bc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Entropy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class EntropyTestsBase + public abstract partial class EntropyTestsBase : QuantityTestsBase { protected abstract double CaloriesPerKelvinInOneJoulePerKelvin { get; } protected abstract double JoulesPerDegreeCelsiusInOneJoulePerKelvin { get; } @@ -85,7 +86,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Entropy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Entropy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Entropy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Entropy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -181,6 +197,23 @@ public void As() AssertEx.EqualTolerance(MegajoulesPerKelvinInOneJoulePerKelvin, jouleperkelvin.As(EntropyUnit.MegajoulePerKelvin), MegajoulesPerKelvinTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -215,6 +248,13 @@ public void ToUnit() Assert.Equal(EntropyUnit.MegajoulePerKelvin, megajouleperkelvinQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Entropy.FromJoulesPerKelvin(1).ToBaseUnit(); + Assert.Equal(Entropy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -619,6 +659,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Entropy.FromJoulesPerKelvin(value); Assert.Equal(Entropy.FromJoulesPerKelvin(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index 548df4c745..5c30792b7e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ForceChangeRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ForceChangeRateTestsBase + public abstract partial class ForceChangeRateTestsBase : QuantityTestsBase { protected abstract double CentinewtonsPerSecondInOneNewtonPerSecond { get; } protected abstract double DecanewtonsPerMinuteInOneNewtonPerSecond { get; } @@ -93,7 +94,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ForceChangeRate(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ForceChangeRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ForceChangeRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ForceChangeRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -213,6 +229,23 @@ public void As() AssertEx.EqualTolerance(NewtonsPerSecondInOneNewtonPerSecond, newtonpersecond.As(ForceChangeRateUnit.NewtonPerSecond), NewtonsPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -263,6 +296,13 @@ public void ToUnit() Assert.Equal(ForceChangeRateUnit.NewtonPerSecond, newtonpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ForceChangeRate.FromNewtonsPerSecond(1).ToBaseUnit(); + Assert.Equal(ForceChangeRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -679,6 +719,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ForceChangeRate.FromNewtonsPerSecond(value); Assert.Equal(ForceChangeRate.FromNewtonsPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index 51626b8468..f0960c978c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ForcePerLength. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ForcePerLengthTestsBase + public abstract partial class ForcePerLengthTestsBase : QuantityTestsBase { protected abstract double CentinewtonsPerCentimeterInOneNewtonPerMeter { get; } protected abstract double CentinewtonsPerMeterInOneNewtonPerMeter { get; } @@ -147,7 +148,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ForcePerLength(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ForcePerLength(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ForcePerLength(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ForcePerLength) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -429,6 +445,23 @@ public void As() AssertEx.EqualTolerance(TonnesForcePerMillimeterInOneNewtonPerMeter, newtonpermeter.As(ForcePerLengthUnit.TonneForcePerMillimeter), TonnesForcePerMillimeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -587,6 +620,13 @@ public void ToUnit() Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, tonneforcepermillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ForcePerLength.FromNewtonsPerMeter(1).ToBaseUnit(); + Assert.Equal(ForcePerLength.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1084,6 +1124,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ForcePerLength.FromNewtonsPerMeter(value); Assert.Equal(ForcePerLength.FromNewtonsPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 9689367bb5..f1c556d865 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Force. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ForceTestsBase + public abstract partial class ForceTestsBase : QuantityTestsBase { protected abstract double DecanewtonsInOneNewton { get; } protected abstract double DyneInOneNewton { get; } @@ -101,7 +102,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Force(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Force(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Force(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Force) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -245,6 +261,23 @@ public void As() AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.As(ForceUnit.TonneForce), TonnesForceTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Force(value: 1, unit: Force.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -311,6 +344,13 @@ public void ToUnit() Assert.Equal(ForceUnit.TonneForce, tonneforceQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Force.FromNewtons(1).ToBaseUnit(); + Assert.Equal(Force.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -739,6 +779,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Force.FromNewtons(value); Assert.Equal(Force.FromNewtons(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index a73055bce6..9bced6348b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Frequency. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class FrequencyTestsBase + public abstract partial class FrequencyTestsBase : QuantityTestsBase { protected abstract double BeatsPerMinuteInOneHertz { get; } protected abstract double CyclesPerHourInOneHertz { get; } @@ -91,7 +92,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Frequency(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Frequency(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Frequency(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Frequency) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -205,6 +221,23 @@ public void As() AssertEx.EqualTolerance(TerahertzInOneHertz, hertz.As(FrequencyUnit.Terahertz), TerahertzTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -251,6 +284,13 @@ public void ToUnit() Assert.Equal(FrequencyUnit.Terahertz, terahertzQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Frequency.FromHertz(1).ToBaseUnit(); + Assert.Equal(Frequency.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -664,6 +704,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Frequency.FromHertz(value); Assert.Equal(Frequency.FromHertz(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 1e7d191669..ff5795aefe 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of FuelEfficiency. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class FuelEfficiencyTestsBase + public abstract partial class FuelEfficiencyTestsBase : QuantityTestsBase { protected abstract double KilometersPerLitersInOneLiterPer100Kilometers { get; } protected abstract double LitersPer100KilometersInOneLiterPer100Kilometers { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new FuelEfficiency(value: 1.0, unitSystem: null)); + Assert.Throws(() => new FuelEfficiency(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new FuelEfficiency(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (FuelEfficiency) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.MilePerUsGallon), MilesPerUsGallonTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new FuelEfficiency(value: 1, unit: FuelEfficiency.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, mileperusgallonQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = FuelEfficiency.FromLitersPer100Kilometers(1).ToBaseUnit(); + Assert.Equal(FuelEfficiency.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = FuelEfficiency.FromLitersPer100Kilometers(value); Assert.Equal(FuelEfficiency.FromLitersPer100Kilometers(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index 3fbffc36a7..6422ff84f5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of HeatFlux. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class HeatFluxTestsBase + public abstract partial class HeatFluxTestsBase : QuantityTestsBase { protected abstract double BtusPerHourSquareFootInOneWattPerSquareMeter { get; } protected abstract double BtusPerMinuteSquareFootInOneWattPerSquareMeter { get; } @@ -107,7 +108,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new HeatFlux(value: 1.0, unitSystem: null)); + Assert.Throws(() => new HeatFlux(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new HeatFlux(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (HeatFlux) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -269,6 +285,23 @@ public void As() AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(HeatFluxUnit.WattPerSquareMeter), WattsPerSquareMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -347,6 +380,13 @@ public void ToUnit() Assert.Equal(HeatFluxUnit.WattPerSquareMeter, wattpersquaremeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = HeatFlux.FromWattsPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(HeatFlux.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -784,6 +824,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = HeatFlux.FromWattsPerSquareMeter(value); Assert.Equal(HeatFlux.FromWattsPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index da082abe14..e7be2de7b7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of HeatTransferCoefficient. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class HeatTransferCoefficientTestsBase + public abstract partial class HeatTransferCoefficientTestsBase : QuantityTestsBase { protected abstract double BtusPerSquareFootDegreeFahrenheitInOneWattPerSquareMeterKelvin { get; } protected abstract double WattsPerSquareMeterCelsiusInOneWattPerSquareMeterKelvin { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new HeatTransferCoefficient(value: 1.0, unitSystem: null)); + Assert.Throws(() => new HeatTransferCoefficient(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new HeatTransferCoefficient(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (HeatTransferCoefficient) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(WattsPerSquareMeterKelvinInOneWattPerSquareMeterKelvin, wattpersquaremeterkelvin.As(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin), WattsPerSquareMeterKelvinTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, wattpersquaremeterkelvinQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(1).ToBaseUnit(); + Assert.Equal(HeatTransferCoefficient.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(value); Assert.Equal(HeatTransferCoefficient.FromWattsPerSquareMeterKelvin(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index 9476f78b1e..a9a19b77d1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Illuminance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class IlluminanceTestsBase + public abstract partial class IlluminanceTestsBase : QuantityTestsBase { protected abstract double KiloluxInOneLux { get; } protected abstract double LuxInOneLux { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Illuminance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Illuminance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Illuminance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Illuminance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(MilliluxInOneLux, lux.As(IlluminanceUnit.Millilux), MilliluxTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(IlluminanceUnit.Millilux, milliluxQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Illuminance.FromLux(1).ToBaseUnit(); + Assert.Equal(Illuminance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Illuminance.FromLux(value); Assert.Equal(Illuminance.FromLux(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index 1e63906500..e8536db262 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Information. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class InformationTestsBase + public abstract partial class InformationTestsBase : QuantityTestsBase { protected abstract double BitsInOneBit { get; } protected abstract double BytesInOneBit { get; } @@ -107,6 +108,27 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() } + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new Information(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Information(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Information) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + [Fact] public void Information_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -301,6 +323,23 @@ public void As() AssertEx.EqualTolerance(TerabytesInOneBit, bit.As(InformationUnit.Terabyte), TerabytesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Information(value: 1, unit: Information.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -411,6 +450,13 @@ public void ToUnit() Assert.Equal(InformationUnit.Terabyte, terabyteQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Information.FromBits(1).ToBaseUnit(); + Assert.Equal(Information.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -872,6 +918,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Information.FromBits(value); Assert.Equal(Information.FromBits(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index 2761d2f34b..f87f962c43 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Irradiance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class IrradianceTestsBase + public abstract partial class IrradianceTestsBase : QuantityTestsBase { protected abstract double KilowattsPerSquareCentimeterInOneWattPerSquareMeter { get; } protected abstract double KilowattsPerSquareMeterInOneWattPerSquareMeter { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Irradiance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Irradiance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Irradiance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Irradiance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(WattsPerSquareMeterInOneWattPerSquareMeter, wattpersquaremeter.As(IrradianceUnit.WattPerSquareMeter), WattsPerSquareMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(IrradianceUnit.WattPerSquareMeter, wattpersquaremeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Irradiance.FromWattsPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(Irradiance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Irradiance.FromWattsPerSquareMeter(value); Assert.Equal(Irradiance.FromWattsPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index 212a5f8ec2..026f79b043 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Irradiation. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class IrradiationTestsBase + public abstract partial class IrradiationTestsBase : QuantityTestsBase { protected abstract double JoulesPerSquareCentimeterInOneJoulePerSquareMeter { get; } protected abstract double JoulesPerSquareMeterInOneJoulePerSquareMeter { get; } @@ -85,7 +86,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Irradiation(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Irradiation(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Irradiation(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Irradiation) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -181,6 +197,23 @@ public void As() AssertEx.EqualTolerance(WattHoursPerSquareMeterInOneJoulePerSquareMeter, joulepersquaremeter.As(IrradiationUnit.WattHourPerSquareMeter), WattHoursPerSquareMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -215,6 +248,13 @@ public void ToUnit() Assert.Equal(IrradiationUnit.WattHourPerSquareMeter, watthourpersquaremeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Irradiation.FromJoulesPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(Irradiation.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -619,6 +659,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Irradiation.FromJoulesPerSquareMeter(value); Assert.Equal(Irradiation.FromJoulesPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index b3ec7fef99..9a2d23c5c4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of KinematicViscosity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class KinematicViscosityTestsBase + public abstract partial class KinematicViscosityTestsBase : QuantityTestsBase { protected abstract double CentistokesInOneSquareMeterPerSecond { get; } protected abstract double DecistokesInOneSquareMeterPerSecond { get; } @@ -87,7 +88,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new KinematicViscosity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new KinematicViscosity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new KinematicViscosity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (KinematicViscosity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -189,6 +205,23 @@ public void As() AssertEx.EqualTolerance(StokesInOneSquareMeterPerSecond, squaremeterpersecond.As(KinematicViscosityUnit.Stokes), StokesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -227,6 +260,13 @@ public void ToUnit() Assert.Equal(KinematicViscosityUnit.Stokes, stokesQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = KinematicViscosity.FromSquareMetersPerSecond(1).ToBaseUnit(); + Assert.Equal(KinematicViscosity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -634,6 +674,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = KinematicViscosity.FromSquareMetersPerSecond(value); Assert.Equal(KinematicViscosity.FromSquareMetersPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs index fd006236d2..7a3b288e5d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of LapseRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LapseRateTestsBase + public abstract partial class LapseRateTestsBase : QuantityTestsBase { protected abstract double DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new LapseRate(value: 1.0, unitSystem: null)); + Assert.Throws(() => new LapseRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new LapseRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (LapseRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(DegreesCelciusPerKilometerInOneDegreeCelsiusPerKilometer, degreecelsiusperkilometer.As(LapseRateUnit.DegreeCelsiusPerKilometer), DegreesCelciusPerKilometerTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LapseRate(value: 1, unit: LapseRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(LapseRateUnit.DegreeCelsiusPerKilometer, degreecelsiusperkilometerQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = LapseRate.FromDegreesCelciusPerKilometer(1).ToBaseUnit(); + Assert.Equal(LapseRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = LapseRate.FromDegreesCelciusPerKilometer(value); Assert.Equal(LapseRate.FromDegreesCelciusPerKilometer(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 695b44d3f9..657b7db6b1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Length. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LengthTestsBase + public abstract partial class LengthTestsBase : QuantityTestsBase { protected abstract double AstronomicalUnitsInOneMeter { get; } protected abstract double CentimetersInOneMeter { get; } @@ -137,7 +138,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Length(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Length(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Length(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Length) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -389,6 +405,23 @@ public void As() AssertEx.EqualTolerance(YardsInOneMeter, meter.As(LengthUnit.Yard), YardsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Length(value: 1, unit: Length.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -527,6 +560,13 @@ public void ToUnit() Assert.Equal(LengthUnit.Yard, yardQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Length.FromMeters(1).ToBaseUnit(); + Assert.Equal(Length.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1009,6 +1049,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Length.FromMeters(value); Assert.Equal(Length.FromMeters(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index 8bd8f79de0..4ff3b091d8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Level. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LevelTestsBase + public abstract partial class LevelTestsBase : QuantityTestsBase { protected abstract double DecibelsInOneDecibel { get; } protected abstract double NepersInOneDecibel { get; } @@ -75,7 +76,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Level(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Level(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Level(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Level) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -141,6 +157,23 @@ public void As() AssertEx.EqualTolerance(NepersInOneDecibel, decibel.As(LevelUnit.Neper), NepersTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Level(value: 1, unit: Level.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -155,6 +188,13 @@ public void ToUnit() Assert.Equal(LevelUnit.Neper, neperQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Level.FromDecibels(1).ToBaseUnit(); + Assert.Equal(Level.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -548,6 +588,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Level.FromDecibels(value); Assert.Equal(Level.FromDecibels(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index 01a64a5151..1a4115793a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of LinearDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LinearDensityTestsBase + public abstract partial class LinearDensityTestsBase : QuantityTestsBase { protected abstract double GramsPerCentimeterInOneKilogramPerMeter { get; } protected abstract double GramsPerMeterInOneKilogramPerMeter { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new LinearDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new LinearDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new LinearDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (LinearDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(PoundsPerInchInOneKilogramPerMeter, kilogrampermeter.As(LinearDensityUnit.PoundPerInch), PoundsPerInchTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(LinearDensityUnit.PoundPerInch, poundperinchQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = LinearDensity.FromKilogramsPerMeter(1).ToBaseUnit(); + Assert.Equal(LinearDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = LinearDensity.FromKilogramsPerMeter(value); Assert.Equal(LinearDensity.FromKilogramsPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index d13e557ff5..ddedc4c990 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of LinearPowerDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LinearPowerDensityTestsBase + public abstract partial class LinearPowerDensityTestsBase : QuantityTestsBase { protected abstract double GigawattsPerCentimeterInOneWattPerMeter { get; } protected abstract double GigawattsPerFootInOneWattPerMeter { get; } @@ -121,7 +122,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new LinearPowerDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new LinearPowerDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new LinearPowerDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (LinearPowerDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -325,6 +341,23 @@ public void As() AssertEx.EqualTolerance(WattsPerMillimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.WattPerMillimeter), WattsPerMillimeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -431,6 +464,13 @@ public void ToUnit() Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, wattpermillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = LinearPowerDensity.FromWattsPerMeter(1).ToBaseUnit(); + Assert.Equal(LinearPowerDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -889,6 +929,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = LinearPowerDensity.FromWattsPerMeter(value); Assert.Equal(LinearPowerDensity.FromWattsPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index 4c6bbef389..be8d7382cb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Luminosity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LuminosityTestsBase + public abstract partial class LuminosityTestsBase : QuantityTestsBase { protected abstract double DecawattsInOneWatt { get; } protected abstract double DeciwattsInOneWatt { get; } @@ -99,7 +100,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Luminosity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Luminosity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Luminosity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Luminosity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -237,6 +253,23 @@ public void As() AssertEx.EqualTolerance(WattsInOneWatt, watt.As(LuminosityUnit.Watt), WattsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -299,6 +332,13 @@ public void ToUnit() Assert.Equal(LuminosityUnit.Watt, wattQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Luminosity.FromWatts(1).ToBaseUnit(); + Assert.Equal(Luminosity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -724,6 +764,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Luminosity.FromWatts(value); Assert.Equal(Luminosity.FromWatts(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index 8e5c85740d..99f2f7e818 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of LuminousFlux. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LuminousFluxTestsBase + public abstract partial class LuminousFluxTestsBase : QuantityTestsBase { protected abstract double LumensInOneLumen { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new LuminousFlux(value: 1.0, unitSystem: null)); + Assert.Throws(() => new LuminousFlux(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new LuminousFlux(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (LuminousFlux) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(LumensInOneLumen, lumen.As(LuminousFluxUnit.Lumen), LumensTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(LuminousFluxUnit.Lumen, lumenQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = LuminousFlux.FromLumens(1).ToBaseUnit(); + Assert.Equal(LuminousFlux.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = LuminousFlux.FromLumens(value); Assert.Equal(LuminousFlux.FromLumens(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index d1d9a354b5..7303fdf130 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of LuminousIntensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class LuminousIntensityTestsBase + public abstract partial class LuminousIntensityTestsBase : QuantityTestsBase { protected abstract double CandelaInOneCandela { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new LuminousIntensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new LuminousIntensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new LuminousIntensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (LuminousIntensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(CandelaInOneCandela, candela.As(LuminousIntensityUnit.Candela), CandelaTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(LuminousIntensityUnit.Candela, candelaQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = LuminousIntensity.FromCandela(1).ToBaseUnit(); + Assert.Equal(LuminousIntensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = LuminousIntensity.FromCandela(value); Assert.Equal(LuminousIntensity.FromCandela(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index 334fb7b3ad..44483c96e6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MagneticField. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MagneticFieldTestsBase + public abstract partial class MagneticFieldTestsBase : QuantityTestsBase { protected abstract double MicroteslasInOneTesla { get; } protected abstract double MilliteslasInOneTesla { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MagneticField(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MagneticField(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MagneticField(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MagneticField) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(TeslasInOneTesla, tesla.As(MagneticFieldUnit.Tesla), TeslasTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(MagneticFieldUnit.Tesla, teslaQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MagneticField.FromTeslas(1).ToBaseUnit(); + Assert.Equal(MagneticField.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MagneticField.FromTeslas(value); Assert.Equal(MagneticField.FromTeslas(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index 461fedc57d..bf45e7d3ae 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MagneticFlux. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MagneticFluxTestsBase + public abstract partial class MagneticFluxTestsBase : QuantityTestsBase { protected abstract double WebersInOneWeber { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MagneticFlux(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MagneticFlux(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MagneticFlux(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MagneticFlux) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(WebersInOneWeber, weber.As(MagneticFluxUnit.Weber), WebersTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(MagneticFluxUnit.Weber, weberQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MagneticFlux.FromWebers(1).ToBaseUnit(); + Assert.Equal(MagneticFlux.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MagneticFlux.FromWebers(value); Assert.Equal(MagneticFlux.FromWebers(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index 95f91dccf6..5f042a805e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Magnetization. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MagnetizationTestsBase + public abstract partial class MagnetizationTestsBase : QuantityTestsBase { protected abstract double AmperesPerMeterInOneAmperePerMeter { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Magnetization(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Magnetization(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Magnetization(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Magnetization) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(AmperesPerMeterInOneAmperePerMeter, amperepermeter.As(MagnetizationUnit.AmperePerMeter), AmperesPerMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(MagnetizationUnit.AmperePerMeter, amperepermeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Magnetization.FromAmperesPerMeter(1).ToBaseUnit(); + Assert.Equal(Magnetization.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Magnetization.FromAmperesPerMeter(value); Assert.Equal(Magnetization.FromAmperesPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index 582820f9a7..1b835a5b52 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MassConcentration. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassConcentrationTestsBase + public abstract partial class MassConcentrationTestsBase : QuantityTestsBase { protected abstract double CentigramsPerDeciliterInOneKilogramPerCubicMeter { get; } protected abstract double CentigramsPerLiterInOneKilogramPerCubicMeter { get; } @@ -165,7 +166,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MassConcentration(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MassConcentration(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MassConcentration(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MassConcentration) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -501,6 +517,23 @@ public void As() AssertEx.EqualTolerance(TonnesPerCubicMillimeterInOneKilogramPerCubicMeter, kilogrampercubicmeter.As(MassConcentrationUnit.TonnePerCubicMillimeter), TonnesPerCubicMillimeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -695,6 +728,13 @@ public void ToUnit() Assert.Equal(MassConcentrationUnit.TonnePerCubicMillimeter, tonnepercubicmillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MassConcentration.FromKilogramsPerCubicMeter(1).ToBaseUnit(); + Assert.Equal(MassConcentration.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1219,6 +1259,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MassConcentration.FromKilogramsPerCubicMeter(value); Assert.Equal(MassConcentration.FromKilogramsPerCubicMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index 5e4f903ecc..2e928a6ec0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MassFlow. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassFlowTestsBase + public abstract partial class MassFlowTestsBase : QuantityTestsBase { protected abstract double CentigramsPerDayInOneGramPerSecond { get; } protected abstract double CentigramsPerSecondInOneGramPerSecond { get; } @@ -137,7 +138,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MassFlow(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MassFlow(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MassFlow(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MassFlow) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -389,6 +405,23 @@ public void As() AssertEx.EqualTolerance(TonnesPerHourInOneGramPerSecond, grampersecond.As(MassFlowUnit.TonnePerHour), TonnesPerHourTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -527,6 +560,13 @@ public void ToUnit() Assert.Equal(MassFlowUnit.TonnePerHour, tonneperhourQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MassFlow.FromGramsPerSecond(1).ToBaseUnit(); + Assert.Equal(MassFlow.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1009,6 +1049,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MassFlow.FromGramsPerSecond(value); Assert.Equal(MassFlow.FromGramsPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 98c2f6c2c8..5fbca119fe 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MassFlux. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassFluxTestsBase + public abstract partial class MassFluxTestsBase : QuantityTestsBase { protected abstract double GramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter { get; } protected abstract double GramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } @@ -95,7 +96,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MassFlux(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MassFlux(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MassFlux(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MassFlux) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -221,6 +237,23 @@ public void As() AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerSecondPerSquareMillimeter), KilogramsPerSecondPerSquareMillimeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -275,6 +308,13 @@ public void ToUnit() Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, kilogrampersecondpersquaremillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MassFlux.FromKilogramsPerSecondPerSquareMeter(1).ToBaseUnit(); + Assert.Equal(MassFlux.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -694,6 +734,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MassFlux.FromKilogramsPerSecondPerSquareMeter(value); Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index 3d38e4fec8..13d7926311 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MassFraction. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassFractionTestsBase + public abstract partial class MassFractionTestsBase : QuantityTestsBase { protected abstract double CentigramsPerGramInOneDecimalFraction { get; } protected abstract double CentigramsPerKilogramInOneDecimalFraction { get; } @@ -119,7 +120,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MassFraction(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MassFraction(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MassFraction(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MassFraction) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -317,6 +333,23 @@ public void As() AssertEx.EqualTolerance(PercentInOneDecimalFraction, decimalfraction.As(MassFractionUnit.Percent), PercentTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassFraction(value: 1, unit: MassFraction.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -419,6 +452,13 @@ public void ToUnit() Assert.Equal(MassFractionUnit.Percent, percentQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MassFraction.FromDecimalFractions(1).ToBaseUnit(); + Assert.Equal(MassFraction.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -874,6 +914,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MassFraction.FromDecimalFractions(value); Assert.Equal(MassFraction.FromDecimalFractions(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index 2b8a75b0c7..cd4f2f2edb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MassMomentOfInertia. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassMomentOfInertiaTestsBase + public abstract partial class MassMomentOfInertiaTestsBase : QuantityTestsBase { protected abstract double GramSquareCentimetersInOneKilogramSquareMeter { get; } protected abstract double GramSquareDecimetersInOneKilogramSquareMeter { get; } @@ -127,7 +128,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MassMomentOfInertia(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MassMomentOfInertia(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MassMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MassMomentOfInertia) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -349,6 +365,23 @@ public void As() AssertEx.EqualTolerance(TonneSquareMilimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareMilimeter), TonneSquareMilimetersTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -467,6 +500,13 @@ public void ToUnit() Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMilimeter, tonnesquaremilimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MassMomentOfInertia.FromKilogramSquareMeters(1).ToBaseUnit(); + Assert.Equal(MassMomentOfInertia.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -934,6 +974,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MassMomentOfInertia.FromKilogramSquareMeters(value); Assert.Equal(MassMomentOfInertia.FromKilogramSquareMeters(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index d3e6c78afc..02fe71e214 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Mass. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MassTestsBase + public abstract partial class MassTestsBase : QuantityTestsBase { protected abstract double CentigramsInOneKilogram { get; } protected abstract double DecagramsInOneKilogram { get; } @@ -121,7 +122,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Mass(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Mass(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Mass(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Mass) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -325,6 +341,23 @@ public void As() AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.As(MassUnit.Tonne), TonnesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -431,6 +464,13 @@ public void ToUnit() Assert.Equal(MassUnit.Tonne, tonneQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Mass.FromKilograms(1).ToBaseUnit(); + Assert.Equal(Mass.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -889,6 +929,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Mass.FromKilograms(value); Assert.Equal(Mass.FromKilograms(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 3950ef38e4..33991bf759 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MolarEnergy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarEnergyTestsBase + public abstract partial class MolarEnergyTestsBase : QuantityTestsBase { protected abstract double JoulesPerMoleInOneJoulePerMole { get; } protected abstract double KilojoulesPerMoleInOneJoulePerMole { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MolarEnergy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MolarEnergy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MolarEnergy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MolarEnergy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(MegajoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.MegajoulePerMole), MegajoulesPerMoleTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(MolarEnergyUnit.MegajoulePerMole, megajoulepermoleQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MolarEnergy.FromJoulesPerMole(1).ToBaseUnit(); + Assert.Equal(MolarEnergy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MolarEnergy.FromJoulesPerMole(value); Assert.Equal(MolarEnergy.FromJoulesPerMole(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index 61f6d59220..76db6b4947 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MolarEntropy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarEntropyTestsBase + public abstract partial class MolarEntropyTestsBase : QuantityTestsBase { protected abstract double JoulesPerMoleKelvinInOneJoulePerMoleKelvin { get; } protected abstract double KilojoulesPerMoleKelvinInOneJoulePerMoleKelvin { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MolarEntropy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MolarEntropy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MolarEntropy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MolarEntropy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(MegajoulesPerMoleKelvinInOneJoulePerMoleKelvin, joulepermolekelvin.As(MolarEntropyUnit.MegajoulePerMoleKelvin), MegajoulesPerMoleKelvinTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(MolarEntropyUnit.MegajoulePerMoleKelvin, megajoulepermolekelvinQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MolarEntropy.FromJoulesPerMoleKelvin(1).ToBaseUnit(); + Assert.Equal(MolarEntropy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MolarEntropy.FromJoulesPerMoleKelvin(value); Assert.Equal(MolarEntropy.FromJoulesPerMoleKelvin(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index 64eaf2504e..7c86b9f53b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of MolarMass. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarMassTestsBase + public abstract partial class MolarMassTestsBase : QuantityTestsBase { protected abstract double CentigramsPerMoleInOneKilogramPerMole { get; } protected abstract double DecagramsPerMoleInOneKilogramPerMole { get; } @@ -95,7 +96,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new MolarMass(value: 1.0, unitSystem: null)); + Assert.Throws(() => new MolarMass(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new MolarMass(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (MolarMass) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -221,6 +237,23 @@ public void As() AssertEx.EqualTolerance(PoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.PoundPerMole), PoundsPerMoleTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -275,6 +308,13 @@ public void ToUnit() Assert.Equal(MolarMassUnit.PoundPerMole, poundpermoleQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = MolarMass.FromKilogramsPerMole(1).ToBaseUnit(); + Assert.Equal(MolarMass.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -694,6 +734,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = MolarMass.FromKilogramsPerMole(value); Assert.Equal(MolarMass.FromKilogramsPerMole(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index 5379595111..18ae44a2ff 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Molarity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class MolarityTestsBase + public abstract partial class MolarityTestsBase : QuantityTestsBase { protected abstract double CentimolesPerLiterInOneMolesPerCubicMeter { get; } protected abstract double DecimolesPerLiterInOneMolesPerCubicMeter { get; } @@ -87,7 +88,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Molarity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Molarity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Molarity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Molarity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -189,6 +205,23 @@ public void As() AssertEx.EqualTolerance(PicomolesPerLiterInOneMolesPerCubicMeter, molespercubicmeter.As(MolarityUnit.PicomolesPerLiter), PicomolesPerLiterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -227,6 +260,13 @@ public void ToUnit() Assert.Equal(MolarityUnit.PicomolesPerLiter, picomolesperliterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Molarity.FromMolesPerCubicMeter(1).ToBaseUnit(); + Assert.Equal(Molarity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -634,6 +674,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Molarity.FromMolesPerCubicMeter(value); Assert.Equal(Molarity.FromMolesPerCubicMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index fe2da572fb..ddfe6ebb83 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Permeability. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PermeabilityTestsBase + public abstract partial class PermeabilityTestsBase : QuantityTestsBase { protected abstract double HenriesPerMeterInOneHenryPerMeter { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Permeability(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Permeability(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Permeability(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Permeability) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(HenriesPerMeterInOneHenryPerMeter, henrypermeter.As(PermeabilityUnit.HenryPerMeter), HenriesPerMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(PermeabilityUnit.HenryPerMeter, henrypermeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Permeability.FromHenriesPerMeter(1).ToBaseUnit(); + Assert.Equal(Permeability.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Permeability.FromHenriesPerMeter(value); Assert.Equal(Permeability.FromHenriesPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index ca601bf52a..4ac2d31c9c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Permittivity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PermittivityTestsBase + public abstract partial class PermittivityTestsBase : QuantityTestsBase { protected abstract double FaradsPerMeterInOneFaradPerMeter { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Permittivity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Permittivity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Permittivity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Permittivity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(FaradsPerMeterInOneFaradPerMeter, faradpermeter.As(PermittivityUnit.FaradPerMeter), FaradsPerMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(PermittivityUnit.FaradPerMeter, faradpermeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Permittivity.FromFaradsPerMeter(1).ToBaseUnit(); + Assert.Equal(Permittivity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Permittivity.FromFaradsPerMeter(value); Assert.Equal(Permittivity.FromFaradsPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index e3ec3d1386..ef43ed42d5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of PowerDensity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PowerDensityTestsBase + public abstract partial class PowerDensityTestsBase : QuantityTestsBase { protected abstract double DecawattsPerCubicFootInOneWattPerCubicMeter { get; } protected abstract double DecawattsPerCubicInchInOneWattPerCubicMeter { get; } @@ -159,7 +160,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new PowerDensity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new PowerDensity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new PowerDensity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (PowerDensity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -477,6 +493,23 @@ public void As() AssertEx.EqualTolerance(WattsPerLiterInOneWattPerCubicMeter, wattpercubicmeter.As(PowerDensityUnit.WattPerLiter), WattsPerLiterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -659,6 +692,13 @@ public void ToUnit() Assert.Equal(PowerDensityUnit.WattPerLiter, wattperliterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = PowerDensity.FromWattsPerCubicMeter(1).ToBaseUnit(); + Assert.Equal(PowerDensity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1174,6 +1214,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = PowerDensity.FromWattsPerCubicMeter(value); Assert.Equal(PowerDensity.FromWattsPerCubicMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index 6e396fa839..c71740ec9c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of PowerRatio. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PowerRatioTestsBase + public abstract partial class PowerRatioTestsBase : QuantityTestsBase { protected abstract double DecibelMilliwattsInOneDecibelWatt { get; } protected abstract double DecibelWattsInOneDecibelWatt { get; } @@ -75,7 +76,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new PowerRatio(value: 1.0, unitSystem: null)); + Assert.Throws(() => new PowerRatio(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new PowerRatio(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (PowerRatio) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -141,6 +157,23 @@ public void As() AssertEx.EqualTolerance(DecibelWattsInOneDecibelWatt, decibelwatt.As(PowerRatioUnit.DecibelWatt), DecibelWattsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new PowerRatio(value: 1, unit: PowerRatio.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -155,6 +188,13 @@ public void ToUnit() Assert.Equal(PowerRatioUnit.DecibelWatt, decibelwattQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = PowerRatio.FromDecibelWatts(1).ToBaseUnit(); + Assert.Equal(PowerRatio.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -548,6 +588,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = PowerRatio.FromDecibelWatts(value); Assert.Equal(PowerRatio.FromDecibelWatts(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index 50cd2cb275..44e19e1f6c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Power. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PowerTestsBase + public abstract partial class PowerTestsBase : QuantityTestsBase { protected abstract double BoilerHorsepowerInOneWatt { get; } protected abstract double BritishThermalUnitsPerHourInOneWatt { get; } @@ -105,6 +106,27 @@ public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() } + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new Power(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Power(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Power) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + [Fact] public void Power_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -293,6 +315,23 @@ public void As() AssertEx.EqualTolerance(WattsInOneWatt, watt.As(PowerUnit.Watt), WattsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Power(value: 1, unit: Power.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -399,6 +438,13 @@ public void ToUnit() Assert.Equal(PowerUnit.Watt, wattQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Power.FromWatts(1).ToBaseUnit(); + Assert.Equal(Power.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -857,6 +903,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Power.FromWatts(value); Assert.Equal(Power.FromWatts(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index f0a131094a..d66b3c1414 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of PressureChangeRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PressureChangeRateTestsBase + public abstract partial class PressureChangeRateTestsBase : QuantityTestsBase { protected abstract double AtmospheresPerSecondInOnePascalPerSecond { get; } protected abstract double KilopascalsPerMinuteInOnePascalPerSecond { get; } @@ -85,7 +86,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new PressureChangeRate(value: 1.0, unitSystem: null)); + Assert.Throws(() => new PressureChangeRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new PressureChangeRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (PressureChangeRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -181,6 +197,23 @@ public void As() AssertEx.EqualTolerance(PascalsPerSecondInOnePascalPerSecond, pascalpersecond.As(PressureChangeRateUnit.PascalPerSecond), PascalsPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -215,6 +248,13 @@ public void ToUnit() Assert.Equal(PressureChangeRateUnit.PascalPerSecond, pascalpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = PressureChangeRate.FromPascalsPerSecond(1).ToBaseUnit(); + Assert.Equal(PressureChangeRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -619,6 +659,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = PressureChangeRate.FromPascalsPerSecond(value); Assert.Equal(PressureChangeRate.FromPascalsPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index 8651214baa..52c5a4df50 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Pressure. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class PressureTestsBase + public abstract partial class PressureTestsBase : QuantityTestsBase { protected abstract double AtmospheresInOnePascal { get; } protected abstract double BarsInOnePascal { get; } @@ -155,7 +156,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Pressure(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Pressure(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Pressure(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Pressure) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -461,6 +477,23 @@ public void As() AssertEx.EqualTolerance(TorrsInOnePascal, pascal.As(PressureUnit.Torr), TorrsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -635,6 +668,13 @@ public void ToUnit() Assert.Equal(PressureUnit.Torr, torrQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Pressure.FromPascals(1).ToBaseUnit(); + Assert.Equal(Pressure.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1144,6 +1184,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Pressure.FromPascals(value); Assert.Equal(Pressure.FromPascals(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index 634226dd3b..ec9f52ec48 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of RatioChangeRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RatioChangeRateTestsBase + public abstract partial class RatioChangeRateTestsBase : QuantityTestsBase { protected abstract double DecimalFractionsPerSecondInOneDecimalFractionPerSecond { get; } protected abstract double PercentsPerSecondInOneDecimalFractionPerSecond { get; } @@ -75,7 +76,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new RatioChangeRate(value: 1.0, unitSystem: null)); + Assert.Throws(() => new RatioChangeRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new RatioChangeRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (RatioChangeRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -141,6 +157,23 @@ public void As() AssertEx.EqualTolerance(PercentsPerSecondInOneDecimalFractionPerSecond, decimalfractionpersecond.As(RatioChangeRateUnit.PercentPerSecond), PercentsPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -155,6 +188,13 @@ public void ToUnit() Assert.Equal(RatioChangeRateUnit.PercentPerSecond, percentpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = RatioChangeRate.FromDecimalFractionsPerSecond(1).ToBaseUnit(); + Assert.Equal(RatioChangeRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -544,6 +584,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(value); Assert.Equal(RatioChangeRate.FromDecimalFractionsPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index 3eae28326a..43f80dd35d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Ratio. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RatioTestsBase + public abstract partial class RatioTestsBase : QuantityTestsBase { protected abstract double DecimalFractionsInOneDecimalFraction { get; } protected abstract double PartsPerBillionInOneDecimalFraction { get; } @@ -83,7 +84,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Ratio(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Ratio(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Ratio(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Ratio) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -173,6 +189,23 @@ public void As() AssertEx.EqualTolerance(PercentInOneDecimalFraction, decimalfraction.As(RatioUnit.Percent), PercentTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Ratio(value: 1, unit: Ratio.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -203,6 +236,13 @@ public void ToUnit() Assert.Equal(RatioUnit.Percent, percentQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Ratio.FromDecimalFractions(1).ToBaseUnit(); + Assert.Equal(Ratio.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -604,6 +644,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Ratio.FromDecimalFractions(value); Assert.Equal(Ratio.FromDecimalFractions(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs index 9eb8376660..24a47f8e45 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ReactiveEnergy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ReactiveEnergyTestsBase + public abstract partial class ReactiveEnergyTestsBase : QuantityTestsBase { protected abstract double KilovoltampereReactiveHoursInOneVoltampereReactiveHour { get; } protected abstract double MegavoltampereReactiveHoursInOneVoltampereReactiveHour { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ReactiveEnergy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ReactiveEnergy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ReactiveEnergy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ReactiveEnergy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.VoltampereReactiveHour), VoltampereReactiveHoursTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ReactiveEnergy(value: 1, unit: ReactiveEnergy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, voltamperereactivehourQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ReactiveEnergy.FromVoltampereReactiveHours(1).ToBaseUnit(); + Assert.Equal(ReactiveEnergy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ReactiveEnergy.FromVoltampereReactiveHours(value); Assert.Equal(ReactiveEnergy.FromVoltampereReactiveHours(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs index 43ad08f7e5..504b3c3497 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ReactivePower. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ReactivePowerTestsBase + public abstract partial class ReactivePowerTestsBase : QuantityTestsBase { protected abstract double GigavoltamperesReactiveInOneVoltampereReactive { get; } protected abstract double KilovoltamperesReactiveInOneVoltampereReactive { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ReactivePower(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ReactivePower(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ReactivePower(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ReactivePower) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.VoltampereReactive), VoltamperesReactiveTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ReactivePower(value: 1, unit: ReactivePower.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(ReactivePowerUnit.VoltampereReactive, voltamperereactiveQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ReactivePower.FromVoltamperesReactive(1).ToBaseUnit(); + Assert.Equal(ReactivePower.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ReactivePower.FromVoltamperesReactive(value); Assert.Equal(ReactivePower.FromVoltamperesReactive(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index d253c9abcf..77fbeb7c60 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of RotationalAcceleration. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalAccelerationTestsBase + public abstract partial class RotationalAccelerationTestsBase : QuantityTestsBase { protected abstract double DegreesPerSecondSquaredInOneRadianPerSecondSquared { get; } protected abstract double RadiansPerSecondSquaredInOneRadianPerSecondSquared { get; } @@ -79,7 +80,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new RotationalAcceleration(value: 1.0, unitSystem: null)); + Assert.Throws(() => new RotationalAcceleration(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new RotationalAcceleration(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (RotationalAcceleration) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -157,6 +173,23 @@ public void As() AssertEx.EqualTolerance(RevolutionsPerSecondSquaredInOneRadianPerSecondSquared, radianpersecondsquared.As(RotationalAccelerationUnit.RevolutionPerSecondSquared), RevolutionsPerSecondSquaredTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -179,6 +212,13 @@ public void ToUnit() Assert.Equal(RotationalAccelerationUnit.RevolutionPerSecondSquared, revolutionpersecondsquaredQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = RotationalAcceleration.FromRadiansPerSecondSquared(1).ToBaseUnit(); + Assert.Equal(RotationalAcceleration.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -574,6 +614,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = RotationalAcceleration.FromRadiansPerSecondSquared(value); Assert.Equal(RotationalAcceleration.FromRadiansPerSecondSquared(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index 3c299b7771..9bc3045351 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of RotationalSpeed. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalSpeedTestsBase + public abstract partial class RotationalSpeedTestsBase : QuantityTestsBase { protected abstract double CentiradiansPerSecondInOneRadianPerSecond { get; } protected abstract double DeciradiansPerSecondInOneRadianPerSecond { get; } @@ -97,7 +98,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new RotationalSpeed(value: 1.0, unitSystem: null)); + Assert.Throws(() => new RotationalSpeed(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new RotationalSpeed(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (RotationalSpeed) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -229,6 +245,23 @@ public void As() AssertEx.EqualTolerance(RevolutionsPerSecondInOneRadianPerSecond, radianpersecond.As(RotationalSpeedUnit.RevolutionPerSecond), RevolutionsPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -287,6 +320,13 @@ public void ToUnit() Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, revolutionpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = RotationalSpeed.FromRadiansPerSecond(1).ToBaseUnit(); + Assert.Equal(RotationalSpeed.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -709,6 +749,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = RotationalSpeed.FromRadiansPerSecond(value); Assert.Equal(RotationalSpeed.FromRadiansPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index 051f000328..48e838fecc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of RotationalStiffnessPerLength. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalStiffnessPerLengthTestsBase + public abstract partial class RotationalStiffnessPerLengthTestsBase : QuantityTestsBase { protected abstract double KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter { get; } protected abstract double KilopoundForceFeetPerDegreesPerFeetInOneNewtonMeterPerRadianPerMeter { get; } @@ -81,7 +82,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new RotationalStiffnessPerLength(value: 1.0, unitSystem: null)); + Assert.Throws(() => new RotationalStiffnessPerLength(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new RotationalStiffnessPerLength(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (RotationalStiffnessPerLength) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -165,6 +181,23 @@ public void As() AssertEx.EqualTolerance(PoundForceFeetPerDegreesPerFeetInOneNewtonMeterPerRadianPerMeter, newtonmeterperradianpermeter.As(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot), PoundForceFeetPerDegreesPerFeetTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -191,6 +224,13 @@ public void ToUnit() Assert.Equal(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, poundforcefootperdegreesperfootQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(1).ToBaseUnit(); + Assert.Equal(RotationalStiffnessPerLength.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -589,6 +629,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(value); Assert.Equal(RotationalStiffnessPerLength.FromNewtonMetersPerRadianPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index 99df23a76b..3f032388c1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of RotationalStiffness. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class RotationalStiffnessTestsBase + public abstract partial class RotationalStiffnessTestsBase : QuantityTestsBase { protected abstract double CentinewtonMetersPerDegreeInOneNewtonMeterPerRadian { get; } protected abstract double CentinewtonMillimetersPerDegreeInOneNewtonMeterPerRadian { get; } @@ -137,7 +138,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new RotationalStiffness(value: 1.0, unitSystem: null)); + Assert.Throws(() => new RotationalStiffness(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new RotationalStiffness(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (RotationalStiffness) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -389,6 +405,23 @@ public void As() AssertEx.EqualTolerance(PoundForceFeetPerDegreesInOneNewtonMeterPerRadian, newtonmeterperradian.As(RotationalStiffnessUnit.PoundForceFootPerDegrees), PoundForceFeetPerDegreesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -527,6 +560,13 @@ public void ToUnit() Assert.Equal(RotationalStiffnessUnit.PoundForceFootPerDegrees, poundforcefootperdegreesQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = RotationalStiffness.FromNewtonMetersPerRadian(1).ToBaseUnit(); + Assert.Equal(RotationalStiffness.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1009,6 +1049,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = RotationalStiffness.FromNewtonMetersPerRadian(value); Assert.Equal(RotationalStiffness.FromNewtonMetersPerRadian(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index c74314396d..0a5726da2e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of SolidAngle. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SolidAngleTestsBase + public abstract partial class SolidAngleTestsBase : QuantityTestsBase { protected abstract double SteradiansInOneSteradian { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new SolidAngle(value: 1.0, unitSystem: null)); + Assert.Throws(() => new SolidAngle(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new SolidAngle(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (SolidAngle) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(SteradiansInOneSteradian, steradian.As(SolidAngleUnit.Steradian), SteradiansTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SolidAngle(value: 1, unit: SolidAngle.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(SolidAngleUnit.Steradian, steradianQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = SolidAngle.FromSteradians(1).ToBaseUnit(); + Assert.Equal(SolidAngle.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = SolidAngle.FromSteradians(value); Assert.Equal(SolidAngle.FromSteradians(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index 26758681b1..e91f4be6a5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of SpecificEnergy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificEnergyTestsBase + public abstract partial class SpecificEnergyTestsBase : QuantityTestsBase { protected abstract double BtuPerPoundInOneJoulePerKilogram { get; } protected abstract double CaloriesPerGramInOneJoulePerKilogram { get; } @@ -121,7 +122,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new SpecificEnergy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new SpecificEnergy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new SpecificEnergy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (SpecificEnergy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -325,6 +341,23 @@ public void As() AssertEx.EqualTolerance(WattHoursPerKilogramInOneJoulePerKilogram, jouleperkilogram.As(SpecificEnergyUnit.WattHourPerKilogram), WattHoursPerKilogramTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -431,6 +464,13 @@ public void ToUnit() Assert.Equal(SpecificEnergyUnit.WattHourPerKilogram, watthourperkilogramQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = SpecificEnergy.FromJoulesPerKilogram(1).ToBaseUnit(); + Assert.Equal(SpecificEnergy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -889,6 +929,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = SpecificEnergy.FromJoulesPerKilogram(value); Assert.Equal(SpecificEnergy.FromJoulesPerKilogram(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index 42e3875924..25c780bddf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of SpecificEntropy. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificEntropyTestsBase + public abstract partial class SpecificEntropyTestsBase : QuantityTestsBase { protected abstract double BtusPerPoundFahrenheitInOneJoulePerKilogramKelvin { get; } protected abstract double CaloriesPerGramKelvinInOneJoulePerKilogramKelvin { get; } @@ -89,7 +90,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new SpecificEntropy(value: 1.0, unitSystem: null)); + Assert.Throws(() => new SpecificEntropy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new SpecificEntropy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (SpecificEntropy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -197,6 +213,23 @@ public void As() AssertEx.EqualTolerance(MegajoulesPerKilogramKelvinInOneJoulePerKilogramKelvin, jouleperkilogramkelvin.As(SpecificEntropyUnit.MegajoulePerKilogramKelvin), MegajoulesPerKilogramKelvinTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -239,6 +272,13 @@ public void ToUnit() Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramKelvin, megajouleperkilogramkelvinQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = SpecificEntropy.FromJoulesPerKilogramKelvin(1).ToBaseUnit(); + Assert.Equal(SpecificEntropy.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -649,6 +689,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = SpecificEntropy.FromJoulesPerKilogramKelvin(value); Assert.Equal(SpecificEntropy.FromJoulesPerKilogramKelvin(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 78bbf330e8..7f8ee12f67 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of SpecificVolume. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificVolumeTestsBase + public abstract partial class SpecificVolumeTestsBase : QuantityTestsBase { protected abstract double CubicFeetPerPoundInOneCubicMeterPerKilogram { get; } protected abstract double CubicMetersPerKilogramInOneCubicMeterPerKilogram { get; } @@ -77,7 +78,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new SpecificVolume(value: 1.0, unitSystem: null)); + Assert.Throws(() => new SpecificVolume(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new SpecificVolume(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (SpecificVolume) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -149,6 +165,23 @@ public void As() AssertEx.EqualTolerance(MillicubicMetersPerKilogramInOneCubicMeterPerKilogram, cubicmeterperkilogram.As(SpecificVolumeUnit.MillicubicMeterPerKilogram), MillicubicMetersPerKilogramTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -167,6 +200,13 @@ public void ToUnit() Assert.Equal(SpecificVolumeUnit.MillicubicMeterPerKilogram, millicubicmeterperkilogramQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = SpecificVolume.FromCubicMetersPerKilogram(1).ToBaseUnit(); + Assert.Equal(SpecificVolume.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -559,6 +599,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = SpecificVolume.FromCubicMetersPerKilogram(value); Assert.Equal(SpecificVolume.FromCubicMetersPerKilogram(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index b4ffa0649f..a10b2b1c39 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of SpecificWeight. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpecificWeightTestsBase + public abstract partial class SpecificWeightTestsBase : QuantityTestsBase { protected abstract double KilogramsForcePerCubicCentimeterInOneNewtonPerCubicMeter { get; } protected abstract double KilogramsForcePerCubicMeterInOneNewtonPerCubicMeter { get; } @@ -105,7 +106,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new SpecificWeight(value: 1.0, unitSystem: null)); + Assert.Throws(() => new SpecificWeight(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new SpecificWeight(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (SpecificWeight) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -261,6 +277,23 @@ public void As() AssertEx.EqualTolerance(TonnesForcePerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.TonneForcePerCubicMillimeter), TonnesForcePerCubicMillimeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -335,6 +368,13 @@ public void ToUnit() Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMillimeter, tonneforcepercubicmillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = SpecificWeight.FromNewtonsPerCubicMeter(1).ToBaseUnit(); + Assert.Equal(SpecificWeight.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -769,6 +809,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = SpecificWeight.FromNewtonsPerCubicMeter(value); Assert.Equal(SpecificWeight.FromNewtonsPerCubicMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index ca618db312..3a6b749338 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Speed. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class SpeedTestsBase + public abstract partial class SpeedTestsBase : QuantityTestsBase { protected abstract double CentimetersPerHourInOneMeterPerSecond { get; } protected abstract double CentimetersPerMinutesInOneMeterPerSecond { get; } @@ -135,7 +136,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Speed(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Speed(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Speed(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Speed) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -381,6 +397,23 @@ public void As() AssertEx.EqualTolerance(YardsPerSecondInOneMeterPerSecond, meterpersecond.As(SpeedUnit.YardPerSecond), YardsPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -515,6 +548,13 @@ public void ToUnit() Assert.Equal(SpeedUnit.YardPerSecond, yardpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Speed.FromMetersPerSecond(1).ToBaseUnit(); + Assert.Equal(Speed.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -994,6 +1034,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Speed.FromMetersPerSecond(value); Assert.Equal(Speed.FromMetersPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index bcf8f66f5e..241327a2dc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of TemperatureChangeRate. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TemperatureChangeRateTestsBase + public abstract partial class TemperatureChangeRateTestsBase : QuantityTestsBase { protected abstract double CentidegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } protected abstract double DecadegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond { get; } @@ -91,7 +92,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new TemperatureChangeRate(value: 1.0, unitSystem: null)); + Assert.Throws(() => new TemperatureChangeRate(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new TemperatureChangeRate(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (TemperatureChangeRate) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -205,6 +221,23 @@ public void As() AssertEx.EqualTolerance(NanodegreesCelsiusPerSecondInOneDegreeCelsiusPerSecond, degreecelsiuspersecond.As(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond), NanodegreesCelsiusPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -251,6 +284,13 @@ public void ToUnit() Assert.Equal(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, nanodegreecelsiuspersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = TemperatureChangeRate.FromDegreesCelsiusPerSecond(1).ToBaseUnit(); + Assert.Equal(TemperatureChangeRate.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -664,6 +704,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = TemperatureChangeRate.FromDegreesCelsiusPerSecond(value); Assert.Equal(TemperatureChangeRate.FromDegreesCelsiusPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index 701405483b..932b55697a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of TemperatureDelta. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TemperatureDeltaTestsBase + public abstract partial class TemperatureDeltaTestsBase : QuantityTestsBase { protected abstract double DegreesCelsiusInOneKelvin { get; } protected abstract double DegreesDelisleInOneKelvin { get; } @@ -89,7 +90,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new TemperatureDelta(value: 1.0, unitSystem: null)); + Assert.Throws(() => new TemperatureDelta(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new TemperatureDelta(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (TemperatureDelta) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -197,6 +213,23 @@ public void As() AssertEx.EqualTolerance(MillidegreesCelsiusInOneKelvin, kelvin.As(TemperatureDeltaUnit.MillidegreeCelsius), MillidegreesCelsiusTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -239,6 +272,13 @@ public void ToUnit() Assert.Equal(TemperatureDeltaUnit.MillidegreeCelsius, millidegreecelsiusQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = TemperatureDelta.FromKelvins(1).ToBaseUnit(); + Assert.Equal(TemperatureDelta.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -649,6 +689,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = TemperatureDelta.FromKelvins(value); Assert.Equal(TemperatureDelta.FromKelvins(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index 15bebb3f2d..d13423cb50 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Temperature. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TemperatureTestsBase + public abstract partial class TemperatureTestsBase : QuantityTestsBase { protected abstract double DegreesCelsiusInOneKelvin { get; } protected abstract double DegreesDelisleInOneKelvin { get; } @@ -91,7 +92,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Temperature(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Temperature(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Temperature(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Temperature) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -205,6 +221,23 @@ public void As() AssertEx.EqualTolerance(SolarTemperaturesInOneKelvin, kelvin.As(TemperatureUnit.SolarTemperature), SolarTemperaturesTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -251,6 +284,13 @@ public void ToUnit() Assert.Equal(TemperatureUnit.SolarTemperature, solartemperatureQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Temperature.FromKelvins(1).ToBaseUnit(); + Assert.Equal(Temperature.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index e333aa2023..9f9d60327c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ThermalConductivity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ThermalConductivityTestsBase + public abstract partial class ThermalConductivityTestsBase : QuantityTestsBase { protected abstract double BtusPerHourFootFahrenheitInOneWattPerMeterKelvin { get; } protected abstract double WattsPerMeterKelvinInOneWattPerMeterKelvin { get; } @@ -75,7 +76,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ThermalConductivity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ThermalConductivity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ThermalConductivity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ThermalConductivity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -141,6 +157,23 @@ public void As() AssertEx.EqualTolerance(WattsPerMeterKelvinInOneWattPerMeterKelvin, wattpermeterkelvin.As(ThermalConductivityUnit.WattPerMeterKelvin), WattsPerMeterKelvinTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -155,6 +188,13 @@ public void ToUnit() Assert.Equal(ThermalConductivityUnit.WattPerMeterKelvin, wattpermeterkelvinQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ThermalConductivity.FromWattsPerMeterKelvin(1).ToBaseUnit(); + Assert.Equal(ThermalConductivity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -544,6 +584,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ThermalConductivity.FromWattsPerMeterKelvin(value); Assert.Equal(ThermalConductivity.FromWattsPerMeterKelvin(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs index fb86d52699..c23f5b7c10 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of ThermalResistance. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ThermalResistanceTestsBase + public abstract partial class ThermalResistanceTestsBase : QuantityTestsBase { protected abstract double HourSquareFeetDegreesFahrenheitPerBtuInOneSquareMeterKelvinPerKilowatt { get; } protected abstract double SquareCentimeterHourDegreesCelsiusPerKilocalorieInOneSquareMeterKelvinPerKilowatt { get; } @@ -81,7 +82,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new ThermalResistance(value: 1.0, unitSystem: null)); + Assert.Throws(() => new ThermalResistance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ThermalResistance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ThermalResistance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -165,6 +181,23 @@ public void As() AssertEx.EqualTolerance(SquareMeterKelvinsPerKilowattInOneSquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowatt.As(ThermalResistanceUnit.SquareMeterKelvinPerKilowatt), SquareMeterKelvinsPerKilowattTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ThermalResistance(value: 1, unit: ThermalResistance.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -191,6 +224,13 @@ public void ToUnit() Assert.Equal(ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, squaremeterkelvinperkilowattQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(1).ToBaseUnit(); + Assert.Equal(ThermalResistance.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -589,6 +629,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = ThermalResistance.FromSquareMeterKelvinsPerKilowatt(value); Assert.Equal(ThermalResistance.FromSquareMeterKelvinsPerKilowatt(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs index f5bfc4c2de..468e186f9d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of TorquePerLength. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TorquePerLengthTestsBase + public abstract partial class TorquePerLengthTestsBase : QuantityTestsBase { protected abstract double KilogramForceCentimetersPerMeterInOneNewtonMeterPerMeter { get; } protected abstract double KilogramForceMetersPerMeterInOneNewtonMeterPerMeter { get; } @@ -113,7 +114,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new TorquePerLength(value: 1.0, unitSystem: null)); + Assert.Throws(() => new TorquePerLength(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new TorquePerLength(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (TorquePerLength) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -293,6 +309,23 @@ public void As() AssertEx.EqualTolerance(TonneForceMillimetersPerMeterInOneNewtonMeterPerMeter, newtonmeterpermeter.As(TorquePerLengthUnit.TonneForceMillimeterPerMeter), TonneForceMillimetersPerMeterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new TorquePerLength(value: 1, unit: TorquePerLength.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -383,6 +416,13 @@ public void ToUnit() Assert.Equal(TorquePerLengthUnit.TonneForceMillimeterPerMeter, tonneforcemillimeterpermeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = TorquePerLength.FromNewtonMetersPerMeter(1).ToBaseUnit(); + Assert.Equal(TorquePerLength.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -829,6 +869,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = TorquePerLength.FromNewtonMetersPerMeter(value); Assert.Equal(TorquePerLength.FromNewtonMetersPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index 9c641c3f06..90d11412d2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Torque. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TorqueTestsBase + public abstract partial class TorqueTestsBase : QuantityTestsBase { protected abstract double KilogramForceCentimetersInOneNewtonMeter { get; } protected abstract double KilogramForceMetersInOneNewtonMeter { get; } @@ -113,7 +114,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Torque(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Torque(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Torque(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Torque) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -293,6 +309,23 @@ public void As() AssertEx.EqualTolerance(TonneForceMillimetersInOneNewtonMeter, newtonmeter.As(TorqueUnit.TonneForceMillimeter), TonneForceMillimetersTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -383,6 +416,13 @@ public void ToUnit() Assert.Equal(TorqueUnit.TonneForceMillimeter, tonneforcemillimeterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Torque.FromNewtonMeters(1).ToBaseUnit(); + Assert.Equal(Torque.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -829,6 +869,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Torque.FromNewtonMeters(value); Assert.Equal(Torque.FromNewtonMeters(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index c0a719c379..9b6e6d2cc7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Turbidity. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class TurbidityTestsBase + public abstract partial class TurbidityTestsBase : QuantityTestsBase { protected abstract double NTUInOneNTU { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Turbidity(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Turbidity(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Turbidity(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Turbidity) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(NTUInOneNTU, ntu.As(TurbidityUnit.NTU), NTUTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Turbidity(value: 1, unit: Turbidity.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(TurbidityUnit.NTU, ntuQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Turbidity.FromNTU(1).ToBaseUnit(); + Assert.Equal(Turbidity.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Turbidity.FromNTU(value); Assert.Equal(Turbidity.FromNTU(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index b54ba26f2d..bf19e9becf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of VitaminA. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VitaminATestsBase + public abstract partial class VitaminATestsBase : QuantityTestsBase { protected abstract double InternationalUnitsInOneInternationalUnit { get; } @@ -73,7 +74,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new VitaminA(value: 1.0, unitSystem: null)); + Assert.Throws(() => new VitaminA(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new VitaminA(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (VitaminA) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -133,6 +149,23 @@ public void As() AssertEx.EqualTolerance(InternationalUnitsInOneInternationalUnit, internationalunit.As(VitaminAUnit.InternationalUnit), InternationalUnitsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VitaminA(value: 1, unit: VitaminA.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -143,6 +176,13 @@ public void ToUnit() Assert.Equal(VitaminAUnit.InternationalUnit, internationalunitQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = VitaminA.FromInternationalUnits(1).ToBaseUnit(); + Assert.Equal(VitaminA.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -529,6 +569,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = VitaminA.FromInternationalUnits(value); Assert.Equal(VitaminA.FromInternationalUnits(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index 60cfa492d2..c0c85613ee 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of VolumeConcentration. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VolumeConcentrationTestsBase + public abstract partial class VolumeConcentrationTestsBase : QuantityTestsBase { protected abstract double CentilitersPerLiterInOneDecimalFraction { get; } protected abstract double CentilitersPerMililiterInOneDecimalFraction { get; } @@ -111,7 +112,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new VolumeConcentration(value: 1.0, unitSystem: null)); + Assert.Throws(() => new VolumeConcentration(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new VolumeConcentration(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (VolumeConcentration) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -285,6 +301,23 @@ public void As() AssertEx.EqualTolerance(PicolitersPerMililiterInOneDecimalFraction, decimalfraction.As(VolumeConcentrationUnit.PicolitersPerMililiter), PicolitersPerMililiterTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumeConcentration(value: 1, unit: VolumeConcentration.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -371,6 +404,13 @@ public void ToUnit() Assert.Equal(VolumeConcentrationUnit.PicolitersPerMililiter, picoliterspermililiterQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = VolumeConcentration.FromDecimalFractions(1).ToBaseUnit(); + Assert.Equal(VolumeConcentration.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -814,6 +854,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = VolumeConcentration.FromDecimalFractions(value); Assert.Equal(VolumeConcentration.FromDecimalFractions(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index 7b02e1cc04..ccc5d889e2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of VolumeFlow. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VolumeFlowTestsBase + public abstract partial class VolumeFlowTestsBase : QuantityTestsBase { protected abstract double AcreFeetPerDayInOneCubicMeterPerSecond { get; } protected abstract double AcreFeetPerHourInOneCubicMeterPerSecond { get; } @@ -169,7 +170,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new VolumeFlow(value: 1.0, unitSystem: null)); + Assert.Throws(() => new VolumeFlow(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new VolumeFlow(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (VolumeFlow) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -517,6 +533,23 @@ public void As() AssertEx.EqualTolerance(UsGallonsPerSecondInOneCubicMeterPerSecond, cubicmeterpersecond.As(VolumeFlowUnit.UsGallonPerSecond), UsGallonsPerSecondTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -719,6 +752,13 @@ public void ToUnit() Assert.Equal(VolumeFlowUnit.UsGallonPerSecond, usgallonpersecondQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = VolumeFlow.FromCubicMetersPerSecond(1).ToBaseUnit(); + Assert.Equal(VolumeFlow.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1249,6 +1289,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = VolumeFlow.FromCubicMetersPerSecond(value); Assert.Equal(VolumeFlow.FromCubicMetersPerSecond(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index 4db337c2be..56050df1bf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of VolumePerLength. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VolumePerLengthTestsBase + public abstract partial class VolumePerLengthTestsBase : QuantityTestsBase { protected abstract double CubicMetersPerMeterInOneCubicMeterPerMeter { get; } protected abstract double CubicYardsPerFootInOneCubicMeterPerMeter { get; } @@ -85,7 +86,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new VolumePerLength(value: 1.0, unitSystem: null)); + Assert.Throws(() => new VolumePerLength(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new VolumePerLength(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (VolumePerLength) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -181,6 +197,23 @@ public void As() AssertEx.EqualTolerance(OilBarrelsPerFootInOneCubicMeterPerMeter, cubicmeterpermeter.As(VolumePerLengthUnit.OilBarrelPerFoot), OilBarrelsPerFootTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -215,6 +248,13 @@ public void ToUnit() Assert.Equal(VolumePerLengthUnit.OilBarrelPerFoot, oilbarrelperfootQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = VolumePerLength.FromCubicMetersPerMeter(1).ToBaseUnit(); + Assert.Equal(VolumePerLength.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -619,6 +659,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = VolumePerLength.FromCubicMetersPerMeter(value); Assert.Equal(VolumePerLength.FromCubicMetersPerMeter(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index c62321d6a3..31807f6932 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of Volume. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class VolumeTestsBase + public abstract partial class VolumeTestsBase : QuantityTestsBase { protected abstract double AcreFeetInOneCubicMeter { get; } protected abstract double AuTablespoonsInOneCubicMeter { get; } @@ -173,7 +174,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new Volume(value: 1.0, unitSystem: null)); + Assert.Throws(() => new Volume(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Volume(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Volume) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -533,6 +549,23 @@ public void As() AssertEx.EqualTolerance(UsTeaspoonsInOneCubicMeter, cubicmeter.As(VolumeUnit.UsTeaspoon), UsTeaspoonsTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -743,6 +776,13 @@ public void ToUnit() Assert.Equal(VolumeUnit.UsTeaspoon, usteaspoonQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = Volume.FromCubicMeters(1).ToBaseUnit(); + Assert.Equal(Volume.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -1279,6 +1319,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = Volume.FromCubicMeters(value); Assert.Equal(Volume.FromCubicMeters(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index e31cb57a48..178dd2bdb9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -21,6 +21,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -34,7 +35,7 @@ namespace UnitsNet.Tests /// Test of WarpingMomentOfInertia. /// // ReSharper disable once PartialTypeWithSinglePart - public abstract partial class WarpingMomentOfInertiaTestsBase + public abstract partial class WarpingMomentOfInertiaTestsBase : QuantityTestsBase { protected abstract double CentimetersToTheSixthInOneMeterToTheSixth { get; } protected abstract double DecimetersToTheSixthInOneMeterToTheSixth { get; } @@ -83,7 +84,22 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() { - Assert.Throws(() => new WarpingMomentOfInertia(value: 1.0, unitSystem: null)); + Assert.Throws(() => new WarpingMomentOfInertia(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new WarpingMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (WarpingMomentOfInertia) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } } [Fact] @@ -173,6 +189,23 @@ public void As() AssertEx.EqualTolerance(MillimetersToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.MillimeterToTheSixth), MillimetersToTheSixthTolerance); } + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + [Fact] public void ToUnit() { @@ -203,6 +236,13 @@ public void ToUnit() Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, millimetertothesixthQuantity.Unit); } + [Fact] + public void ToBaseUnit_ReturnsQuantityWithBaseUnit() + { + var quantityInBaseUnit = WarpingMomentOfInertia.FromMetersToTheSixth(1).ToBaseUnit(); + Assert.Equal(WarpingMomentOfInertia.BaseUnit, quantityInBaseUnit.Unit); + } + [Fact] public void ConversionRoundTrip() { @@ -604,6 +644,5 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(value); Assert.Equal(WarpingMomentOfInertia.FromMetersToTheSixth(-value), -quantity); } - } } diff --git a/UnitsNet.Tests/QuantityTests.Ctor.cs b/UnitsNet.Tests/QuantityTests.Ctor.cs deleted file mode 100644 index 747ae174c2..0000000000 --- a/UnitsNet.Tests/QuantityTests.Ctor.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using JetBrains.Annotations; -using UnitsNet.Units; -using Xunit; - -namespace UnitsNet.Tests -{ - [UsedImplicitly] - public partial class QuantityTests - { - /// - /// Tests constructors of quantity types. - /// - public class Ctor - { - /// - /// This test shows what quantities support the SI UnitSystem, which is not many. - /// UnitSystem is still experimental and this design will probably change at some point as we see problems with ambiguity - /// as well as representing anything else but the SI unit system like CGS or British Engineering Units. - /// - /// Extending the functionality of BaseUnits & UnitSystem · Issue #651 · angularsen/UnitsNet - /// https://github.com/angularsen/UnitsNet/issues/651 - /// - [Fact] - public void Ctor_WithValueAndSIUnitSystem_ReturnsQuantityWithSIUnitOrThrowsArgumentExceptionIfNotImplemented() - { - AssertUnitValue(new Acceleration(1, UnitSystem.SI), 1, AccelerationUnit.MeterPerSecondSquared); - AssertUnitValue(new AmountOfSubstance(1, UnitSystem.SI), 1, AmountOfSubstanceUnit.Mole); - Assert.Throws(() => new AmplitudeRatio(1, UnitSystem.SI)); - Assert.Throws(() => new Angle(1, UnitSystem.SI)); - Assert.Throws(() => new ApparentEnergy(1, UnitSystem.SI)); - Assert.Throws(() => new ApparentPower(1, UnitSystem.SI)); - AssertUnitValue(new AreaDensity(1, UnitSystem.SI), 1, AreaDensityUnit.KilogramPerSquareMeter); - AssertUnitValue(new AreaMomentOfInertia(1, UnitSystem.SI), 1, AreaMomentOfInertiaUnit.MeterToTheFourth); - AssertUnitValue(new Area(1, UnitSystem.SI), 1, AreaUnit.SquareMeter); - Assert.Throws(() => new BitRate(1, UnitSystem.SI)); - Assert.Throws(() => new BrakeSpecificFuelConsumption(1, UnitSystem.SI)); - AssertUnitValue(new Capacitance(1, UnitSystem.SI), 1, CapacitanceUnit.Farad); - AssertUnitValue(new CoefficientOfThermalExpansion(1, UnitSystem.SI), 1, CoefficientOfThermalExpansionUnit.InverseKelvin); - Assert.Throws(() => new Density(1, UnitSystem.SI)); - AssertUnitValue(new Duration(1, UnitSystem.SI), 1, DurationUnit.Second); - Assert.Throws(() => new DynamicViscosity(1, UnitSystem.SI)); - Assert.Throws(() => new ElectricAdmittance(1, UnitSystem.SI)); - AssertUnitValue(new ElectricChargeDensity(1, UnitSystem.SI), 1, ElectricChargeDensityUnit.CoulombPerCubicMeter); - Assert.Throws(() => new ElectricCharge(1, UnitSystem.SI)); - Assert.Throws(() => new ElectricConductance(1, UnitSystem.SI)); - AssertUnitValue(new ElectricConductivity(1, UnitSystem.SI), 1, ElectricConductivityUnit.SiemensPerMeter); - AssertUnitValue(new ElectricCurrentDensity(1, UnitSystem.SI), 1, ElectricCurrentDensityUnit.AmperePerSquareMeter); - Assert.Throws(() => new ElectricCurrentGradient(1, UnitSystem.SI)); - AssertUnitValue(new ElectricField(1, UnitSystem.SI), 1, ElectricFieldUnit.VoltPerMeter); - Assert.Throws(() => new ElectricInductance(1, UnitSystem.SI)); - Assert.Throws(() => new ElectricPotentialAc(1, UnitSystem.SI)); - Assert.Throws(() => new ElectricPotentialDc(1, UnitSystem.SI)); - AssertUnitValue(new ElectricPotential(1, UnitSystem.SI), 1, ElectricPotentialUnit.Volt); - Assert.Throws(() => new ElectricResistance(1, UnitSystem.SI)); - Assert.Throws(() => new ElectricResistivity(1, UnitSystem.SI)); - AssertUnitValue(new ElectricSurfaceChargeDensity(1, UnitSystem.SI), 1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter); - AssertUnitValue(new Energy(1, UnitSystem.SI), 1, EnergyUnit.Joule); - Assert.Throws(() => new Entropy(1, UnitSystem.SI)); - Assert.Throws(() => new ForceChangeRate(1, UnitSystem.SI)); - Assert.Throws(() => new ForcePerLength(1, UnitSystem.SI)); - AssertUnitValue(new Force(1, UnitSystem.SI), 1, ForceUnit.Newton); - Assert.Throws(() => new Frequency(1, UnitSystem.SI)); - AssertUnitValue(new HeatFlux(1, UnitSystem.SI), 1, HeatFluxUnit.WattPerSquareMeter); - Assert.Throws(() => new HeatTransferCoefficient(1, UnitSystem.SI)); - Assert.Throws(() => new Illuminance(1, UnitSystem.SI)); - Assert.Throws(() => new Information(1, UnitSystem.SI)); - Assert.Throws(() => new Irradiance(1, UnitSystem.SI)); - Assert.Throws(() => new Irradiation(1, UnitSystem.SI)); - Assert.Throws(() => new KinematicViscosity(1, UnitSystem.SI)); - Assert.Throws(() => new LapseRate(1, UnitSystem.SI)); - AssertUnitValue(new Length(1, UnitSystem.SI), 1, LengthUnit.Meter); - Assert.Throws(() => new Level(1, UnitSystem.SI)); - Assert.Throws(() => new LinearDensity(1, UnitSystem.SI)); - Assert.Throws(() => new Luminosity(1, UnitSystem.SI)); - Assert.Throws(() => new LuminousFlux(1, UnitSystem.SI)); - AssertUnitValue(new LuminousIntensity(1, UnitSystem.SI), 1, LuminousIntensityUnit.Candela); - Assert.Throws(() => new MagneticField(1, UnitSystem.SI)); - Assert.Throws(() => new MagneticFlux(1, UnitSystem.SI)); - AssertUnitValue(new Magnetization(1, UnitSystem.SI), 1, MagnetizationUnit.AmperePerMeter); - Assert.Throws(() => new MassConcentration(1, UnitSystem.SI)); - Assert.Throws(() => new MassFlow(1, UnitSystem.SI)); - Assert.Throws(() => new MassFlux(1, UnitSystem.SI)); - Assert.Throws(() => new MassFraction(1, UnitSystem.SI)); - Assert.Throws(() => new MassMomentOfInertia(1, UnitSystem.SI)); - Assert.Throws(() => new Mass(1, UnitSystem.SI)); - Assert.Throws(() => new MolarEnergy(1, UnitSystem.SI)); - Assert.Throws(() => new MolarEntropy(1, UnitSystem.SI)); - AssertUnitValue(new Molarity(1, UnitSystem.SI), 1, MolarityUnit.MolesPerCubicMeter); - Assert.Throws(() => new MolarMass(1, UnitSystem.SI)); - Assert.Throws(() => new Permeability(1, UnitSystem.SI)); - Assert.Throws(() => new Permittivity(1, UnitSystem.SI)); - AssertUnitValue(new PowerDensity(1, UnitSystem.SI), 1, PowerDensityUnit.WattPerCubicMeter); - Assert.Throws(() => new PowerRatio(1, UnitSystem.SI)); - Assert.Throws(() => new Power(1, UnitSystem.SI)); - Assert.Throws(() => new PressureChangeRate(1, UnitSystem.SI)); - AssertUnitValue(new Pressure(1, UnitSystem.SI), 1, PressureUnit.Pascal); - Assert.Throws(() => new RatioChangeRate(1, UnitSystem.SI)); - Assert.Throws(() => new Ratio(1, UnitSystem.SI)); - Assert.Throws(() => new ReactiveEnergy(1, UnitSystem.SI)); - Assert.Throws(() => new ReactivePower(1, UnitSystem.SI)); - Assert.Throws(() => new RotationalAcceleration(1, UnitSystem.SI)); - Assert.Throws(() => new RotationalSpeed(1, UnitSystem.SI)); - Assert.Throws(() => new RotationalStiffness(1, UnitSystem.SI)); - Assert.Throws(() => new SolidAngle(1, UnitSystem.SI)); - Assert.Throws(() => new SpecificEnergy(1, UnitSystem.SI)); - Assert.Throws(() => new SpecificEntropy(1, UnitSystem.SI)); - Assert.Throws(() => new SpecificVolume(1, UnitSystem.SI)); - Assert.Throws(() => new SpecificWeight(1, UnitSystem.SI)); - AssertUnitValue(new Speed(1, UnitSystem.SI), 1, SpeedUnit.MeterPerSecond); - Assert.Throws(() => new TemperatureChangeRate(1, UnitSystem.SI)); - Assert.Throws(() => new TemperatureDelta(1, UnitSystem.SI)); - AssertUnitValue(new Temperature(1, UnitSystem.SI), 1, TemperatureUnit.Kelvin); - Assert.Throws(() => new ThermalConductivity(1, UnitSystem.SI)); - Assert.Throws(() => new ThermalResistance(1, UnitSystem.SI)); - Assert.Throws(() => new Torque(1, UnitSystem.SI)); - Assert.Throws(() => new VitaminA(1, UnitSystem.SI)); - Assert.Throws(() => new VolumeConcentration(1, UnitSystem.SI)); - Assert.Throws(() => new VolumeFlow(1, UnitSystem.SI)); - AssertUnitValue(new VolumePerLength(1, UnitSystem.SI), 1, VolumePerLengthUnit.CubicMeterPerMeter); - Assert.Throws(() => new Volume(1, UnitSystem.SI)); - } - - private static void AssertUnitValue(IQuantity actual, double expectedValue, Enum expectedUnit) - { - Assert.Equal(expectedValue, actual.Value); - Assert.Equal(expectedUnit, actual.Unit); - } - } - } -} diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index 4f6fa268e8..40bc324b0d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -62,7 +62,7 @@ static Volume() new UnitInfo(VolumeUnit.CubicHectometer, new BaseUnits(length: LengthUnit.Hectometer)), new UnitInfo(VolumeUnit.CubicInch, BaseUnits.Undefined), new UnitInfo(VolumeUnit.CubicKilometer, BaseUnits.Undefined), - new UnitInfo(VolumeUnit.CubicMeter, BaseUnits.Undefined), + new UnitInfo(VolumeUnit.CubicMeter, new BaseUnits(length: LengthUnit.Meter)), new UnitInfo(VolumeUnit.CubicMicrometer, BaseUnits.Undefined), new UnitInfo(VolumeUnit.CubicMile, BaseUnits.Undefined), new UnitInfo(VolumeUnit.CubicMillimeter, BaseUnits.Undefined),