diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs index 1a1acbb388..0238c804ae 100644 --- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs @@ -214,7 +214,10 @@ private void GenerateInstanceConstructors() Writer.WL($@" _unit = unit; }} - +"); + if (!_isDimensionless) + { + Writer.WL($@" /// /// Creates an instance of the quantity with the given numeric value in units compatible with the given . /// If multiple compatible units were found, the first match is used. @@ -225,18 +228,11 @@ private void GenerateInstanceConstructors() /// No unit was found for the given . public {_quantity.Name}(double value, UnitSystem unitSystem) {{ - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); -"); - - Writer.WL(@" - _value = value;"); - Writer.WL($@" - _unit = firstUnitInfo?.Value ?? throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem)); + _value = value; + _unit = Info.GetDefaultUnit(unitSystem); }} "); + } } private void GenerateStaticProperties() @@ -1000,34 +996,16 @@ public double As({_unitEnumName} unit) }} "); - Writer.WL($@" + Writer.WL( $@" /// public double As(UnitSystem unitSystem) {{ - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem)); - - return As(firstUnitInfo.Value); + return As(Info.GetDefaultUnit(unitSystem)); }} "); Writer.WL($@" - /// - double IQuantity.As(Enum unit) - {{ - if (!(unit is {_unitEnumName} typedUnit)) - throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit)); - - return As(typedUnit); - }} - /// /// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation . /// @@ -1123,29 +1101,33 @@ private bool TryToUnit({_unitEnumName} unit, [NotNullWhen(true)] out {_quantity. converted = convertedOrNull.Value; return true; }} +"); + Writer.WL($@" + /// + public {_quantity.Name} ToUnit(UnitSystem unitSystem) + {{ + return ToUnit(Info.GetDefaultUnit(unitSystem)); + }} +"); - /// - IQuantity IQuantity.ToUnit(Enum unit) + Writer.WL($@" + #region Explicit implementations + + double IQuantity.As(Enum unit) {{ - if (!(unit is {_unitEnumName} typedUnit)) + if (unit is not {_unitEnumName} typedUnit) throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit)); - return ToUnit(typedUnit, DefaultConversionFunctions); + return As(typedUnit); }} - /// - public {_quantity.Name} ToUnit(UnitSystem unitSystem) + /// + IQuantity IQuantity.ToUnit(Enum unit) {{ - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem)); + if (!(unit is {_unitEnumName} typedUnit)) + throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); }} /// @@ -1158,6 +1140,8 @@ IQuantity IQuantity.ToUnit(Enum unit) IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); #endregion + + #endregion "); } diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 64d7775f50..6f8e55be76 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -50,6 +50,14 @@ internal class UnitTestBaseClassGenerator : GeneratorBase /// Example: "LengthUnit.Centimeter". /// private readonly string _otherOrBaseUnitFullName; + + /// + /// Indicates whether the quantity is dimensionless. + /// + /// + /// A dimensionless quantity has all base dimensions (L, M, T, I, Θ, N, J) equal to zero. + /// + private readonly bool _isDimensionless; /// /// Stores a mapping of culture names to their corresponding unique unit abbreviations. @@ -98,6 +106,7 @@ public UnitTestBaseClassGenerator(Quantity quantity) // Try to pick another unit, or fall back to base unit if only a single unit. _otherOrBaseUnit = quantity.Units.Where(u => u != _baseUnit).DefaultIfEmpty(_baseUnit).First(); _otherOrBaseUnitFullName = $"{_unitEnumName}.{_otherOrBaseUnit.SingularName}"; + _isDimensionless = quantity.BaseDimensions is { L: 0, M: 0, T: 0, I: 0, Θ: 0, N: 0, J: 0 }; var abbreviationsForCulture = new Dictionary>>(); foreach (Unit unit in quantity.Units) @@ -257,6 +266,10 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); }} +"); + if (!_isDimensionless) + { + Writer.WL($@" [Fact] public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() @@ -265,20 +278,24 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() }} [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() {{ - 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); - }} + var quantity = new {_quantity.Name}(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); }} + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + {{ + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new {_quantity.Name}(value: 1, unitSystem: unsupportedUnitSystem)); + }} +"); + } + + Writer.WL($@" + [Fact] public void {_quantity.Name}_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() {{ @@ -346,24 +363,193 @@ public void As() AssertEx.EqualTolerance({unit.PluralName}InOne{_baseUnit.SingularName}, {baseUnitVariableName}.As({GetUnitFullName(unit)}), {unit.PluralName}Tolerance);"); Writer.WL($@" }} +"); + if (_isDimensionless) + { + Writer.WL($@" [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName}); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + }} + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() {{ var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + }} - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + {{ + Assert.Multiple(() => {{ - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - }} + var quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName}); + + {_quantity.Name} convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal({_baseUnitFullName}, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }}, () => + {{ + IQuantity<{_unitEnumName}> quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName}); + + IQuantity<{_unitEnumName}> convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal({_baseUnitFullName}, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }}, () => + {{ + IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName}); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal({_baseUnitFullName}, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }}); + }} + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + {{ + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }}, () => + {{ + IQuantity<{_unitEnumName}> quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }}, () => + {{ + IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }}); + }} +"); + } else + { + Writer.WL($@" + + [Fact] + public virtual void BaseUnit_HasSIBase() + {{ + var baseUnitInfo = {_quantity.Name}.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + }} + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + var expectedValue = quantity.As({_quantity.Name}.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + }} + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + }} + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + }} + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + var expectedUnit = {_quantity.Name}.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); + + Assert.Multiple(() => {{ - Assert.Throws(AsWithSIUnitSystem); - }} + {_quantity.Name} quantityToConvert = quantity; + + {_quantity.Name} convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }}, () => + {{ + IQuantity<{_unitEnumName}> quantityToConvert = quantity; + + IQuantity<{_unitEnumName}> convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }}, () => + {{ + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }}); + }} + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + {{ + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }}, () => + {{ + IQuantity<{_unitEnumName}> quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }}, () => + {{ + IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }}); }} + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + {{ + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + {{ + var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }}, () => + {{ + IQuantity<{_unitEnumName}> quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }}, () => + {{ + IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }}); + }} +"); + } + + Writer.WL($@" + [Fact] public void Parse() {{"); diff --git a/Common/UnitDefinitions/BitRate.json b/Common/UnitDefinitions/BitRate.json index 5418065bcc..d5c1b97fa6 100644 --- a/Common/UnitDefinitions/BitRate.json +++ b/Common/UnitDefinitions/BitRate.json @@ -3,11 +3,16 @@ "BaseUnit": "BitPerSecond", "XmlDocSummary": "In telecommunications and computing, bit rate is the number of bits that are conveyed or processed per unit of time.", "XmlDocRemarks": "https://en.wikipedia.org/wiki/Bit_rate", - "BaseDimensions": { "T": -1 }, + "BaseDimensions": { + "T": -1 + }, "Units": [ { "SingularName": "BitPerSecond", "PluralName": "BitsPerSecond", + "BaseUnits": { + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Kibi", "Mebi", "Gibi", "Tebi", "Pebi", "Exbi" ], diff --git a/Common/UnitDefinitions/BrakeSpecificFuelConsumption.json b/Common/UnitDefinitions/BrakeSpecificFuelConsumption.json index ff498144da..d9114ed833 100644 --- a/Common/UnitDefinitions/BrakeSpecificFuelConsumption.json +++ b/Common/UnitDefinitions/BrakeSpecificFuelConsumption.json @@ -22,6 +22,10 @@ { "SingularName": "KilogramPerJoule", "PluralName": "KilogramsPerJoule", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/CoefficientOfThermalExpansion.json b/Common/UnitDefinitions/CoefficientOfThermalExpansion.json index e96737307c..34790d395e 100644 --- a/Common/UnitDefinitions/CoefficientOfThermalExpansion.json +++ b/Common/UnitDefinitions/CoefficientOfThermalExpansion.json @@ -54,9 +54,6 @@ { "SingularName": "PpmPerKelvin", "PluralName": "PpmPerKelvin", - "BaseUnits": { - "Θ": "Kelvin" - }, "FromUnitToBaseFunc": "{x} / 1e6", "FromBaseToUnitFunc": "{x} * 1e6", "Localization": [ @@ -69,9 +66,6 @@ { "SingularName": "PpmPerDegreeCelsius", "PluralName": "PpmPerDegreeCelsius", - "BaseUnits": { - "Θ": "DegreeCelsius" - }, "FromUnitToBaseFunc": "{x} / 1e6", "FromBaseToUnitFunc": "{x} * 1e6", "Localization": [ @@ -84,9 +78,6 @@ { "SingularName": "PpmPerDegreeFahrenheit", "PluralName": "PpmPerDegreeFahrenheit", - "BaseUnits": { - "Θ": "DegreeFahrenheit" - }, "FromUnitToBaseFunc": "{x} * 9 / 5e6", "FromBaseToUnitFunc": "{x} * 5e6 / 9", "Localization": [ diff --git a/Common/UnitDefinitions/Density.json b/Common/UnitDefinitions/Density.json index df417ef08c..9ed8cba6a1 100644 --- a/Common/UnitDefinitions/Density.json +++ b/Common/UnitDefinitions/Density.json @@ -185,6 +185,10 @@ { "SingularName": "GramPerLiter", "PluralName": "GramsPerLiter", + "BaseUnits": { + "L": "Decimeter", + "M": "Gram" + }, "FromUnitToBaseFunc": "{x} / 1", "FromBaseToUnitFunc": "{x} * 1", "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], @@ -211,6 +215,10 @@ { "SingularName": "GramPerMilliliter", "PluralName": "GramsPerMilliliter", + "BaseUnits": { + "L": "Centimeter", + "M": "Gram" + }, "FromUnitToBaseFunc": "{x} / 1e-3", "FromBaseToUnitFunc": "{x} * 1e-3", "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], diff --git a/Common/UnitDefinitions/DynamicViscosity.json b/Common/UnitDefinitions/DynamicViscosity.json index 21af977765..02c7b26d1e 100644 --- a/Common/UnitDefinitions/DynamicViscosity.json +++ b/Common/UnitDefinitions/DynamicViscosity.json @@ -12,6 +12,11 @@ { "SingularName": "NewtonSecondPerMeterSquared", "PluralName": "NewtonSecondsPerMeterSquared", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/ElectricAdmittance.json b/Common/UnitDefinitions/ElectricAdmittance.json index 38c539237b..5f843d752e 100644 --- a/Common/UnitDefinitions/ElectricAdmittance.json +++ b/Common/UnitDefinitions/ElectricAdmittance.json @@ -14,6 +14,12 @@ { "SingularName": "Siemens", "PluralName": "Siemens", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], diff --git a/Common/UnitDefinitions/ElectricApparentPower.json b/Common/UnitDefinitions/ElectricApparentPower.json index 4173ef577b..52be88ac11 100644 --- a/Common/UnitDefinitions/ElectricApparentPower.json +++ b/Common/UnitDefinitions/ElectricApparentPower.json @@ -12,6 +12,11 @@ { "SingularName": "Voltampere", "PluralName": "Voltamperes", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Micro", "Milli", "Kilo", "Mega", "Giga" ], diff --git a/Common/UnitDefinitions/ElectricCharge.json b/Common/UnitDefinitions/ElectricCharge.json index 1488af22db..7f3639e57f 100644 --- a/Common/UnitDefinitions/ElectricCharge.json +++ b/Common/UnitDefinitions/ElectricCharge.json @@ -11,6 +11,10 @@ { "SingularName": "Coulomb", "PluralName": "Coulombs", + "BaseUnits": { + "I": "Ampere", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ], @@ -24,8 +28,12 @@ { "SingularName": "AmpereHour", "PluralName": "AmpereHours", - "FromUnitToBaseFunc": "{x} / 2.77777777777e-4", - "FromBaseToUnitFunc": "{x} * 2.77777777777e-4", + "BaseUnits": { + "I": "Ampere", + "T": "Hour" + }, + "FromUnitToBaseFunc": "{x} * 3600", + "FromBaseToUnitFunc": "{x} / 3600", "Prefixes": [ "Milli", "Kilo", "Mega" ], "Localization": [ { diff --git a/Common/UnitDefinitions/ElectricConductance.json b/Common/UnitDefinitions/ElectricConductance.json index 910062df0d..46129fe556 100644 --- a/Common/UnitDefinitions/ElectricConductance.json +++ b/Common/UnitDefinitions/ElectricConductance.json @@ -13,6 +13,12 @@ { "SingularName": "Siemens", "PluralName": "Siemens", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], diff --git a/Common/UnitDefinitions/ElectricImpedance.json b/Common/UnitDefinitions/ElectricImpedance.json index 26c63c8540..74ce901203 100644 --- a/Common/UnitDefinitions/ElectricImpedance.json +++ b/Common/UnitDefinitions/ElectricImpedance.json @@ -14,6 +14,12 @@ { "SingularName": "Ohm", "PluralName": "Ohms", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], diff --git a/Common/UnitDefinitions/ElectricInductance.json b/Common/UnitDefinitions/ElectricInductance.json index 54f55a2c7a..bd361f6153 100644 --- a/Common/UnitDefinitions/ElectricInductance.json +++ b/Common/UnitDefinitions/ElectricInductance.json @@ -13,6 +13,12 @@ { "SingularName": "Henry", "PluralName": "Henries", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Pico", "Nano", "Micro", "Milli" ], diff --git a/Common/UnitDefinitions/ElectricReactance.json b/Common/UnitDefinitions/ElectricReactance.json index fb18130d88..80de1301eb 100644 --- a/Common/UnitDefinitions/ElectricReactance.json +++ b/Common/UnitDefinitions/ElectricReactance.json @@ -13,6 +13,12 @@ { "SingularName": "Ohm", "PluralName": "Ohms", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], diff --git a/Common/UnitDefinitions/ElectricReactivePower.json b/Common/UnitDefinitions/ElectricReactivePower.json index 8a689161ab..bfcd783412 100644 --- a/Common/UnitDefinitions/ElectricReactivePower.json +++ b/Common/UnitDefinitions/ElectricReactivePower.json @@ -12,6 +12,11 @@ { "SingularName": "VoltampereReactive", "PluralName": "VoltamperesReactive", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega", "Giga" ], diff --git a/Common/UnitDefinitions/ElectricResistance.json b/Common/UnitDefinitions/ElectricResistance.json index edc5c60ece..d705ee2be9 100644 --- a/Common/UnitDefinitions/ElectricResistance.json +++ b/Common/UnitDefinitions/ElectricResistance.json @@ -13,6 +13,12 @@ { "SingularName": "Ohm", "PluralName": "Ohms", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], diff --git a/Common/UnitDefinitions/ElectricResistivity.json b/Common/UnitDefinitions/ElectricResistivity.json index 66a90070fb..4d8f621272 100644 --- a/Common/UnitDefinitions/ElectricResistivity.json +++ b/Common/UnitDefinitions/ElectricResistivity.json @@ -13,6 +13,12 @@ { "SingularName": "OhmMeter", "PluralName": "OhmMeters", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/ElectricSusceptance.json b/Common/UnitDefinitions/ElectricSusceptance.json index 05e8ad37cf..8eeea029e8 100644 --- a/Common/UnitDefinitions/ElectricSusceptance.json +++ b/Common/UnitDefinitions/ElectricSusceptance.json @@ -13,6 +13,12 @@ { "SingularName": "Siemens", "PluralName": "Siemens", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], diff --git a/Common/UnitDefinitions/Entropy.json b/Common/UnitDefinitions/Entropy.json index cf45d4be28..d4263a1af4 100644 --- a/Common/UnitDefinitions/Entropy.json +++ b/Common/UnitDefinitions/Entropy.json @@ -12,6 +12,12 @@ { "SingularName": "JoulePerKelvin", "PluralName": "JoulesPerKelvin", + "BaseUnits": { + "M": "Kilogram", + "L": "Meter", + "T": "Second", + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], @@ -38,6 +44,12 @@ { "SingularName": "JoulePerDegreeCelsius", "PluralName": "JoulesPerDegreeCelsius", + "BaseUnits": { + "M": "Kilogram", + "L": "Meter", + "T": "Second", + "Θ": "DegreeCelsius" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo" ], diff --git a/Common/UnitDefinitions/Force.json b/Common/UnitDefinitions/Force.json index 675b046598..040f7f749b 100644 --- a/Common/UnitDefinitions/Force.json +++ b/Common/UnitDefinitions/Force.json @@ -112,11 +112,6 @@ { "SingularName": "Poundal", "PluralName": "Poundals", - "BaseUnits": { - "L": "Foot", - "M": "Pound", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 0.138254954376", "FromBaseToUnitFunc": "{x} / 0.138254954376", "XmlDocSummary": "The poundal is defined as the force necessary to accelerate 1 pound-mass at 1 foot per second per second. 1 pdl = 0.138254954376 N exactly.", diff --git a/Common/UnitDefinitions/ForceChangeRate.json b/Common/UnitDefinitions/ForceChangeRate.json index 08bb0d754f..f4921d65ba 100644 --- a/Common/UnitDefinitions/ForceChangeRate.json +++ b/Common/UnitDefinitions/ForceChangeRate.json @@ -24,6 +24,11 @@ { "SingularName": "NewtonPerSecond", "PluralName": "NewtonsPerSecond", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Kilo" ], diff --git a/Common/UnitDefinitions/ForcePerLength.json b/Common/UnitDefinitions/ForcePerLength.json index c5fdb2533a..f1a016db3c 100644 --- a/Common/UnitDefinitions/ForcePerLength.json +++ b/Common/UnitDefinitions/ForcePerLength.json @@ -10,6 +10,10 @@ { "SingularName": "NewtonPerMeter", "PluralName": "NewtonsPerMeter", + "BaseUnits": { + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Kilo", "Mega" ], @@ -190,7 +194,7 @@ } ] }, - { + { "SingularName": "KilopoundForcePerInch", "PluralName": "KilopoundsForcePerInch", "FromUnitToBaseFunc": "{x} * 1.75126835e5", diff --git a/Common/UnitDefinitions/Frequency.json b/Common/UnitDefinitions/Frequency.json index 8bbf4f1862..9cfeba9a8a 100644 --- a/Common/UnitDefinitions/Frequency.json +++ b/Common/UnitDefinitions/Frequency.json @@ -9,6 +9,9 @@ { "SingularName": "Hertz", "PluralName": "Hertz", + "BaseUnits": { + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], @@ -43,6 +46,9 @@ { "SingularName": "CyclePerMinute", "PluralName": "CyclesPerMinute", + "BaseUnits": { + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60", "FromBaseToUnitFunc": "{x} * 60", "Localization": [ @@ -55,6 +61,9 @@ { "SingularName": "CyclePerHour", "PluralName": "CyclesPerHour", + "BaseUnits": { + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} / 3600", "FromBaseToUnitFunc": "{x} * 3600", "Localization": [ @@ -67,6 +76,9 @@ { "SingularName": "BeatPerMinute", "PluralName": "BeatsPerMinute", + "BaseUnits": { + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60", "FromBaseToUnitFunc": "{x} * 60", "Localization": [ @@ -79,6 +91,9 @@ { "SingularName": "PerSecond", "PluralName": "PerSecond", + "BaseUnits": { + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/HeatTransferCoefficient.json b/Common/UnitDefinitions/HeatTransferCoefficient.json index 7a13a9ff70..31ba31743e 100644 --- a/Common/UnitDefinitions/HeatTransferCoefficient.json +++ b/Common/UnitDefinitions/HeatTransferCoefficient.json @@ -11,6 +11,11 @@ { "SingularName": "WattPerSquareMeterKelvin", "PluralName": "WattsPerSquareMeterKelvin", + "BaseUnits": { + "M": "Kilogram", + "T": "Second", + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -23,6 +28,11 @@ { "SingularName": "WattPerSquareMeterCelsius", "PluralName": "WattsPerSquareMeterCelsius", + "BaseUnits": { + "M": "Kilogram", + "T": "Second", + "Θ": "DegreeCelsius" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/Illuminance.json b/Common/UnitDefinitions/Illuminance.json index 2c8b07c52f..187b9d1226 100644 --- a/Common/UnitDefinitions/Illuminance.json +++ b/Common/UnitDefinitions/Illuminance.json @@ -11,6 +11,10 @@ { "SingularName": "Lux", "PluralName": "Lux", + "BaseUnits": { + "L": "Meter", + "J": "Candela" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Milli", "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/Impulse.json b/Common/UnitDefinitions/Impulse.json index bc111e0103..ece5a03e74 100644 --- a/Common/UnitDefinitions/Impulse.json +++ b/Common/UnitDefinitions/Impulse.json @@ -11,6 +11,11 @@ { "SingularName": "KilogramMeterPerSecond", "PluralName": "KilogramMetersPerSecond", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -23,6 +28,11 @@ { "SingularName": "NewtonSecond", "PluralName": "NewtonSeconds", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Kilo", "Mega" ], @@ -36,6 +46,11 @@ { "SingularName": "PoundFootPerSecond", "PluralName": "PoundFeetPerSecond", + "BaseUnits": { + "L": "Foot", + "M": "Pound", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} / 7.230657989877", "FromBaseToUnitFunc": "{x} * 7.230657989877", "Localization": [ @@ -60,6 +75,11 @@ { "SingularName": "SlugFootPerSecond", "PluralName": "SlugFeetPerSecond", + "BaseUnits": { + "L": "Foot", + "M": "Slug", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} / 0.224735720691", "FromBaseToUnitFunc": "{x} * 0.224735720691", "Localization": [ diff --git a/Common/UnitDefinitions/Irradiance.json b/Common/UnitDefinitions/Irradiance.json index 6608bdfb98..50d92bb8b9 100644 --- a/Common/UnitDefinitions/Irradiance.json +++ b/Common/UnitDefinitions/Irradiance.json @@ -10,6 +10,10 @@ { "SingularName": "WattPerSquareMeter", "PluralName": "WattsPerSquareMeter", + "BaseUnits": { + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/Irradiation.json b/Common/UnitDefinitions/Irradiation.json index 3689cd0db4..2f8b31e6e2 100644 --- a/Common/UnitDefinitions/Irradiation.json +++ b/Common/UnitDefinitions/Irradiation.json @@ -11,6 +11,10 @@ { "SingularName": "JoulePerSquareMeter", "PluralName": "JoulesPerSquareMeter", + "BaseUnits": { + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo" ], diff --git a/Common/UnitDefinitions/Jerk.json b/Common/UnitDefinitions/Jerk.json index c2cf906e84..99d4855f90 100644 --- a/Common/UnitDefinitions/Jerk.json +++ b/Common/UnitDefinitions/Jerk.json @@ -71,10 +71,6 @@ { "SingularName": "StandardGravitiesPerSecond", "PluralName": "StandardGravitiesPerSecond", - "BaseUnits": { - "L": "Meter", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 9.80665", "FromBaseToUnitFunc": "{x} / 9.80665", "Prefixes": [ "Milli"], diff --git a/Common/UnitDefinitions/KinematicViscosity.json b/Common/UnitDefinitions/KinematicViscosity.json index 5de0e4c458..dd1893f2e9 100644 --- a/Common/UnitDefinitions/KinematicViscosity.json +++ b/Common/UnitDefinitions/KinematicViscosity.json @@ -11,6 +11,10 @@ { "SingularName": "SquareMeterPerSecond", "PluralName": "SquareMetersPerSecond", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -44,6 +48,10 @@ { "SingularName": "SquareFootPerSecond", "PluralName": "SquareFeetPerSecond", + "BaseUnits": { + "L": "Foot", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} / 10.7639", "FromBaseToUnitFunc": "{x} * 10.7639", "Localization": [ diff --git a/Common/UnitDefinitions/LeakRate.json b/Common/UnitDefinitions/LeakRate.json index 14654f3501..eb4f59919b 100644 --- a/Common/UnitDefinitions/LeakRate.json +++ b/Common/UnitDefinitions/LeakRate.json @@ -12,6 +12,11 @@ { "SingularName": "PascalCubicMeterPerSecond", "PluralName": "PascalCubicMetersPerSecond", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/Length.json b/Common/UnitDefinitions/Length.json index 728e38602a..36cc1f82df 100644 --- a/Common/UnitDefinitions/Length.json +++ b/Common/UnitDefinitions/Length.json @@ -410,6 +410,9 @@ { "SingularName": "Angstrom", "PluralName": "Angstroms", + "BaseUnits": { + "L": "Angstrom" + }, "FromUnitToBaseFunc": "{x} * 1e-10", "FromBaseToUnitFunc": "{x} / 1e-10", "XmlDocSummary": "Angstrom is a metric unit of length equal to 1e-10 meter", diff --git a/Common/UnitDefinitions/LinearDensity.json b/Common/UnitDefinitions/LinearDensity.json index 7d08f3b9a8..45d9337bb3 100644 --- a/Common/UnitDefinitions/LinearDensity.json +++ b/Common/UnitDefinitions/LinearDensity.json @@ -11,6 +11,10 @@ { "SingularName": "GramPerMillimeter", "PluralName": "GramsPerMillimeter", + "BaseUnits": { + "M": "Gram", + "L": "Millimeter" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Micro", "Milli", "Kilo" ], @@ -24,6 +28,10 @@ { "SingularName": "GramPerCentimeter", "PluralName": "GramsPerCentimeter", + "BaseUnits": { + "M": "Gram", + "L": "Centimeter" + }, "FromUnitToBaseFunc": "{x} * 1e-1", "FromBaseToUnitFunc": "{x} / 1e-1", "Prefixes": [ "Micro", "Milli", "Kilo" ], @@ -37,6 +45,10 @@ { "SingularName": "GramPerMeter", "PluralName": "GramsPerMeter", + "BaseUnits": { + "M": "Gram", + "L": "Meter" + }, "FromUnitToBaseFunc": "{x} * 1e-3", "FromBaseToUnitFunc": "{x} / 1e-3", "Prefixes": [ "Micro", "Milli", "Kilo" ], @@ -50,6 +62,10 @@ { "SingularName": "PoundPerInch", "PluralName": "PoundsPerInch", + "BaseUnits": { + "M": "Pound", + "L": "Inch" + }, "FromUnitToBaseFunc": "{x} / 5.5997415e-2", "FromBaseToUnitFunc": "{x} * 5.5997415e-2", "Localization": [ @@ -62,6 +78,10 @@ { "SingularName": "PoundPerFoot", "PluralName": "PoundsPerFoot", + "BaseUnits": { + "M": "Pound", + "L": "Foot" + }, "FromUnitToBaseFunc": "{x} * 1.48816394", "FromBaseToUnitFunc": "{x} / 1.48816394", "Localization": [ @@ -74,6 +94,10 @@ { "SingularName": "GramPerFoot", "PluralName": "GramsPerFoot", + "BaseUnits": { + "M": "Gram", + "L": "Foot" + }, "FromUnitToBaseFunc": "{x} * ( 1e-3 / 0.3048 )", "FromBaseToUnitFunc": "{x} / ( 1e-3 / 0.3048 )", "Prefixes": [ "Micro", "Milli", "Kilo" ], diff --git a/Common/UnitDefinitions/LinearPowerDensity.json b/Common/UnitDefinitions/LinearPowerDensity.json index 2802ee7aa1..f4d0f3d158 100644 --- a/Common/UnitDefinitions/LinearPowerDensity.json +++ b/Common/UnitDefinitions/LinearPowerDensity.json @@ -12,9 +12,14 @@ { "SingularName": "WattPerMeter", "PluralName": "WattsPerMeter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], "Localization": [ { "Culture": "en-US", @@ -27,7 +32,7 @@ "PluralName": "WattsPerCentimeter", "FromUnitToBaseFunc": "{x} * 1e2", "FromBaseToUnitFunc": "{x} / 1e2", - "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], "Localization": [ { "Culture": "en-US", @@ -35,12 +40,12 @@ } ] }, - { + { "SingularName": "WattPerMillimeter", "PluralName": "WattsPerMillimeter", "FromUnitToBaseFunc": "{x} * 1e3", "FromBaseToUnitFunc": "{x} / 1e3", - "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], "Localization": [ { "Culture": "en-US", @@ -53,7 +58,7 @@ "PluralName": "WattsPerInch", "FromUnitToBaseFunc": "{x} * 39.37007874", "FromBaseToUnitFunc": "{x} / 39.37007874", - "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], "Localization": [ { "Culture": "en-US", @@ -66,7 +71,7 @@ "PluralName": "WattsPerFoot", "FromUnitToBaseFunc": "{x} * 3.280839895", "FromBaseToUnitFunc": "{x} / 3.280839895", - "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], "Localization": [ { "Culture": "en-US", diff --git a/Common/UnitDefinitions/Luminosity.json b/Common/UnitDefinitions/Luminosity.json index e0caa0eab7..72b7be4a4d 100644 --- a/Common/UnitDefinitions/Luminosity.json +++ b/Common/UnitDefinitions/Luminosity.json @@ -12,6 +12,11 @@ { "SingularName": "Watt", "PluralName": "Watts", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Deci", "Deca", "Kilo", "Mega", "Giga", "Tera", "Peta" ], diff --git a/Common/UnitDefinitions/LuminousFlux.json b/Common/UnitDefinitions/LuminousFlux.json index 844a6f2b69..f0d77ce38c 100644 --- a/Common/UnitDefinitions/LuminousFlux.json +++ b/Common/UnitDefinitions/LuminousFlux.json @@ -10,6 +10,9 @@ { "SingularName": "Lumen", "PluralName": "Lumens", + "BaseUnits": { + "J": "Candela" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/MagneticField.json b/Common/UnitDefinitions/MagneticField.json index 4f356e2650..644e3c32c8 100644 --- a/Common/UnitDefinitions/MagneticField.json +++ b/Common/UnitDefinitions/MagneticField.json @@ -12,6 +12,11 @@ { "SingularName": "Tesla", "PluralName": "Teslas", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli" ], diff --git a/Common/UnitDefinitions/MagneticFlux.json b/Common/UnitDefinitions/MagneticFlux.json index 5307d9fad3..be32c3baf8 100644 --- a/Common/UnitDefinitions/MagneticFlux.json +++ b/Common/UnitDefinitions/MagneticFlux.json @@ -13,6 +13,12 @@ { "SingularName": "Weber", "PluralName": "Webers", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/MassConcentration.json b/Common/UnitDefinitions/MassConcentration.json index 703c2a0c2a..46f40a6a76 100644 --- a/Common/UnitDefinitions/MassConcentration.json +++ b/Common/UnitDefinitions/MassConcentration.json @@ -66,10 +66,6 @@ { "SingularName": "GramPerMicroliter", "PluralName": "GramsPerMicroliter", - "BaseUnits": { - "M": "Gram", - "L": "Centimeter" - }, "FromUnitToBaseFunc": "{x} / 1e-6", "FromBaseToUnitFunc": "{x} * 1e-6", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], @@ -239,7 +235,7 @@ } ] }, - { + { "SingularName": "OuncePerUSGallon", "PluralName": "OuncesPerUSGallon", "FromUnitToBaseFunc": " {x} / 0.1335264711843", @@ -251,7 +247,7 @@ } ] }, - { + { "SingularName": "OuncePerImperialGallon", "PluralName": "OuncesPerImperialGallon", "FromUnitToBaseFunc": " {x} / 0.1603586720609", diff --git a/Common/UnitDefinitions/MassFlow.json b/Common/UnitDefinitions/MassFlow.json index 509abd6a53..720ff15948 100644 --- a/Common/UnitDefinitions/MassFlow.json +++ b/Common/UnitDefinitions/MassFlow.json @@ -10,6 +10,10 @@ { "SingularName": "GramPerSecond", "PluralName": "GramsPerSecond", + "BaseUnits": { + "M": "Gram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], @@ -23,6 +27,10 @@ { "SingularName": "GramPerDay", "PluralName": "GramsPerDay", + "BaseUnits": { + "M": "Gram", + "T": "Day" + }, "FromUnitToBaseFunc": "{x} / 86400", "FromBaseToUnitFunc": "{x} * 86400", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo", "Mega" ], @@ -36,6 +44,10 @@ { "SingularName": "GramPerHour", "PluralName": "GramsPerHour", + "BaseUnits": { + "M": "Gram", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} / 3600", "FromBaseToUnitFunc": "{x} * 3600", "Localization": [ @@ -48,6 +60,10 @@ { "SingularName": "KilogramPerHour", "PluralName": "KilogramsPerHour", + "BaseUnits": { + "M": "Kilogram", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} / 3.6", "FromBaseToUnitFunc": "{x} * 3.6", "Localization": [ @@ -64,6 +80,10 @@ { "SingularName": "KilogramPerMinute", "PluralName": "KilogramsPerMinute", + "BaseUnits": { + "M": "Kilogram", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 0.06", "FromBaseToUnitFunc": "{x} * 0.06", "Localization": [ @@ -80,6 +100,10 @@ { "SingularName": "TonnePerHour", "PluralName": "TonnesPerHour", + "BaseUnits": { + "M": "Tonne", + "T": "Hour" + }, "FromUnitToBaseFunc": "1000 * {x} / 3.6", "FromBaseToUnitFunc": "{x} * 3.6 / 1000", "Localization": [ @@ -92,6 +116,10 @@ { "SingularName": "PoundPerDay", "PluralName": "PoundsPerDay", + "BaseUnits": { + "M": "Pound", + "T": "Day" + }, "FromUnitToBaseFunc": "{x} / 190.47936", "FromBaseToUnitFunc": "{x} * 190.47936", "Prefixes": [ "Mega" ], @@ -105,6 +133,10 @@ { "SingularName": "PoundPerHour", "PluralName": "PoundsPerHour", + "BaseUnits": { + "M": "Pound", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} / 7.93664", "FromBaseToUnitFunc": "{x} * 7.93664", "Prefixes": [ "Mega" ], @@ -118,6 +150,10 @@ { "SingularName": "PoundPerMinute", "PluralName": "PoundsPerMinute", + "BaseUnits": { + "M": "Pound", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 0.132277", "FromBaseToUnitFunc": "{x} * 0.132277", "Prefixes": [ "Mega" ], @@ -131,6 +167,10 @@ { "SingularName": "PoundPerSecond", "PluralName": "PoundsPerSecond", + "BaseUnits": { + "M": "Pound", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} * 453.59237", "FromBaseToUnitFunc": "{x} / 453.59237", "Prefixes": [ "Mega" ], @@ -144,6 +184,10 @@ { "SingularName": "TonnePerDay", "PluralName": "TonnesPerDay", + "BaseUnits": { + "M": "Tonne", + "T": "Day" + }, "FromUnitToBaseFunc": "{x} / 0.0864000", "FromBaseToUnitFunc": "{x} * 0.0864000", "Localization": [ @@ -156,6 +200,10 @@ { "SingularName": "ShortTonPerHour", "PluralName": "ShortTonsPerHour", + "BaseUnits": { + "M": "ShortTon", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} * 251.9957611", "FromBaseToUnitFunc": "{x} / 251.9957611", "Localization": [ diff --git a/Common/UnitDefinitions/MassFlux.json b/Common/UnitDefinitions/MassFlux.json index fe66af7430..c3bcc9bdc0 100644 --- a/Common/UnitDefinitions/MassFlux.json +++ b/Common/UnitDefinitions/MassFlux.json @@ -11,6 +11,11 @@ { "SingularName": "GramPerSecondPerSquareMeter", "PluralName": "GramsPerSecondPerSquareMeter", + "BaseUnits": { + "M": "Gram", + "T": "Second", + "L": "Meter" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Prefixes": [ "Kilo" ], @@ -24,6 +29,11 @@ { "SingularName": "GramPerSecondPerSquareCentimeter", "PluralName": "GramsPerSecondPerSquareCentimeter", + "BaseUnits": { + "M": "Gram", + "T": "Second", + "L": "Centimeter" + }, "FromUnitToBaseFunc": "{x} / 1e-1", "FromBaseToUnitFunc": "{x} * 1e-1", "Prefixes": [ "Kilo" ], @@ -37,6 +47,11 @@ { "SingularName": "GramPerSecondPerSquareMillimeter", "PluralName": "GramsPerSecondPerSquareMillimeter", + "BaseUnits": { + "M": "Gram", + "T": "Second", + "L": "Millimeter" + }, "FromUnitToBaseFunc": "{x} / 1e-3", "FromBaseToUnitFunc": "{x} * 1e-3", "Prefixes": [ "Kilo" ], @@ -50,6 +65,11 @@ { "SingularName": "GramPerHourPerSquareMeter", "PluralName": "GramsPerHourPerSquareMeter", + "BaseUnits": { + "M": "Gram", + "T": "Hour", + "L": "Meter" + }, "FromUnitToBaseFunc": "{x} / 3.6e6", "FromBaseToUnitFunc": "{x} * 3.6e6", "Prefixes": [ "Kilo" ], @@ -63,6 +83,11 @@ { "SingularName": "GramPerHourPerSquareCentimeter", "PluralName": "GramsPerHourPerSquareCentimeter", + "BaseUnits": { + "M": "Gram", + "T": "Hour", + "L": "Centimeter" + }, "FromUnitToBaseFunc": "{x} / 3.6e2", "FromBaseToUnitFunc": "{x} * 3.6e2", "Prefixes": [ "Kilo" ], @@ -76,6 +101,11 @@ { "SingularName": "GramPerHourPerSquareMillimeter", "PluralName": "GramsPerHourPerSquareMillimeter", + "BaseUnits": { + "M": "Gram", + "T": "Hour", + "L": "Millimeter" + }, "FromUnitToBaseFunc": "{x} / 3.6e0", "FromBaseToUnitFunc": "{x} * 3.6e0", "Prefixes": [ "Kilo" ], diff --git a/Common/UnitDefinitions/MassMomentOfInertia.json b/Common/UnitDefinitions/MassMomentOfInertia.json index 87f7a4ee11..cfc7d2d2f8 100644 --- a/Common/UnitDefinitions/MassMomentOfInertia.json +++ b/Common/UnitDefinitions/MassMomentOfInertia.json @@ -10,6 +10,10 @@ { "SingularName": "GramSquareMeter", "PluralName": "GramSquareMeters", + "BaseUnits": { + "L": "Meter", + "M": "Gram" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Prefixes": [ "Milli", "Kilo" ], @@ -23,6 +27,10 @@ { "SingularName": "GramSquareDecimeter", "PluralName": "GramSquareDecimeters", + "BaseUnits": { + "L": "Decimeter", + "M": "Gram" + }, "FromUnitToBaseFunc": "{x} / 1e5", "FromBaseToUnitFunc": "{x} * 1e5", "Prefixes": [ "Milli", "Kilo" ], @@ -36,6 +44,10 @@ { "SingularName": "GramSquareCentimeter", "PluralName": "GramSquareCentimeters", + "BaseUnits": { + "L": "Centimeter", + "M": "Gram" + }, "FromUnitToBaseFunc": "{x} / 1e7", "FromBaseToUnitFunc": "{x} * 1e7", "Prefixes": [ "Milli", "Kilo" ], @@ -49,6 +61,10 @@ { "SingularName": "GramSquareMillimeter", "PluralName": "GramSquareMillimeters", + "BaseUnits": { + "L": "Millimeter", + "M": "Gram" + }, "FromUnitToBaseFunc": "{x} / 1e9", "FromBaseToUnitFunc": "{x} * 1e9", "Prefixes": [ "Milli", "Kilo" ], @@ -62,6 +78,10 @@ { "SingularName": "TonneSquareMeter", "PluralName": "TonneSquareMeters", + "BaseUnits": { + "L": "Meter", + "M": "Tonne" + }, "FromUnitToBaseFunc": "{x} / 1e-3", "FromBaseToUnitFunc": "{x} * 1e-3", "Prefixes": [ "Kilo", "Mega" ], @@ -75,6 +95,10 @@ { "SingularName": "TonneSquareDecimeter", "PluralName": "TonneSquareDecimeters", + "BaseUnits": { + "L": "Decimeter", + "M": "Tonne" + }, "FromUnitToBaseFunc": "{x} / 1e-1", "FromBaseToUnitFunc": "{x} * 1e-1", "Prefixes": [ "Kilo", "Mega" ], @@ -88,6 +112,10 @@ { "SingularName": "TonneSquareCentimeter", "PluralName": "TonneSquareCentimeters", + "BaseUnits": { + "L": "Centimeter", + "M": "Tonne" + }, "FromUnitToBaseFunc": "{x} / 1e1", "FromBaseToUnitFunc": "{x} * 1e1", "Prefixes": [ "Kilo", "Mega" ], @@ -101,6 +129,10 @@ { "SingularName": "TonneSquareMilimeter", "PluralName": "TonneSquareMilimeters", + "BaseUnits": { + "L": "Millimeter", + "M": "Tonne" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Prefixes": [ "Kilo", "Mega" ], @@ -114,6 +146,10 @@ { "SingularName": "PoundSquareFoot", "PluralName": "PoundSquareFeet", + "BaseUnits": { + "L": "Foot", + "M": "Pound" + }, "FromUnitToBaseFunc": "{x} * 4.21401101e-2", "FromBaseToUnitFunc": "{x} / 4.21401101e-2", "Localization": [ @@ -126,6 +162,10 @@ { "SingularName": "PoundSquareInch", "PluralName": "PoundSquareInches", + "BaseUnits": { + "L": "Inch", + "M": "Pound" + }, "FromUnitToBaseFunc": "{x} * 2.9263965e-4", "FromBaseToUnitFunc": "{x} / 2.9263965e-4", "Localization": [ @@ -138,6 +178,10 @@ { "SingularName": "SlugSquareFoot", "PluralName": "SlugSquareFeet", + "BaseUnits": { + "L": "Foot", + "M": "Slug" + }, "FromUnitToBaseFunc": "{x} * 1.3558179619", "FromBaseToUnitFunc": "{x} / 1.3558179619", "Localization": [ @@ -150,6 +194,10 @@ { "SingularName": "SlugSquareInch", "PluralName": "SlugSquareInches", + "BaseUnits": { + "L": "Inch", + "M": "Slug" + }, "FromUnitToBaseFunc": "{x} * 9.41540242e-3", "FromBaseToUnitFunc": "{x} / 9.41540242e-3", "Localization": [ diff --git a/Common/UnitDefinitions/MolarEnergy.json b/Common/UnitDefinitions/MolarEnergy.json index 93add4f13e..2855d507d8 100644 --- a/Common/UnitDefinitions/MolarEnergy.json +++ b/Common/UnitDefinitions/MolarEnergy.json @@ -12,6 +12,12 @@ { "SingularName": "JoulePerMole", "PluralName": "JoulesPerMole", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "N": "Mole" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/MolarEntropy.json b/Common/UnitDefinitions/MolarEntropy.json index 53b6c96bd5..d6410e9d73 100644 --- a/Common/UnitDefinitions/MolarEntropy.json +++ b/Common/UnitDefinitions/MolarEntropy.json @@ -13,6 +13,13 @@ { "SingularName": "JoulePerMoleKelvin", "PluralName": "JoulesPerMoleKelvin", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "Θ": "Kelvin", + "N": "Mole" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/MolarMass.json b/Common/UnitDefinitions/MolarMass.json index 36401297c6..edcda34e72 100644 --- a/Common/UnitDefinitions/MolarMass.json +++ b/Common/UnitDefinitions/MolarMass.json @@ -10,6 +10,10 @@ { "SingularName": "GramPerMole", "PluralName": "GramsPerMole", + "BaseUnits": { + "M": "Gram", + "N": "Mole" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], @@ -27,6 +31,10 @@ { "SingularName": "KilogramPerKilomole", "PluralName": "KilogramsPerKilomole", + "BaseUnits": { + "M": "Kilogram", + "N": "Kilomole" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Localization": [ @@ -39,6 +47,10 @@ { "SingularName": "PoundPerMole", "PluralName": "PoundsPerMole", + "BaseUnits": { + "M": "Pound", + "N": "Mole" + }, "FromUnitToBaseFunc": "{x} * 0.45359237", "FromBaseToUnitFunc": "{x} / 0.45359237", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/Permeability.json b/Common/UnitDefinitions/Permeability.json index cb6c794fe4..3984be7463 100644 --- a/Common/UnitDefinitions/Permeability.json +++ b/Common/UnitDefinitions/Permeability.json @@ -13,6 +13,12 @@ { "SingularName": "HenryPerMeter", "PluralName": "HenriesPerMeter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/Permittivity.json b/Common/UnitDefinitions/Permittivity.json index ebdd6232f1..7ac18b96f6 100644 --- a/Common/UnitDefinitions/Permittivity.json +++ b/Common/UnitDefinitions/Permittivity.json @@ -13,6 +13,12 @@ { "SingularName": "FaradPerMeter", "PluralName": "FaradsPerMeter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/Pressure.json b/Common/UnitDefinitions/Pressure.json index 663b8007fe..c5895550cb 100644 --- a/Common/UnitDefinitions/Pressure.json +++ b/Common/UnitDefinitions/Pressure.json @@ -82,11 +82,6 @@ { "SingularName": "KilogramForcePerSquareCentimeter", "PluralName": "KilogramsForcePerSquareCentimeter", - "BaseUnits": { - "L": "Centimeter", - "M": "Kilogram", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 9.80665e4", "FromBaseToUnitFunc": "{x} / 9.80665e4", "Localization": [ @@ -119,6 +114,11 @@ { "SingularName": "NewtonPerSquareMeter", "PluralName": "NewtonsPerSquareMeter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], @@ -202,11 +202,6 @@ { "SingularName": "PoundForcePerSquareInch", "PluralName": "PoundsForcePerSquareInch", - "BaseUnits": { - "L": "Inch", - "M": "Pound", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 6.894757293168361e3", "FromBaseToUnitFunc": "{x} / 6.894757293168361e3", "Prefixes": [ "Kilo" ], @@ -226,11 +221,6 @@ { "SingularName": "PoundForcePerSquareMil", "PluralName": "PoundsForcePerSquareMil", - "BaseUnits": { - "L": "Mil", - "M": "Pound", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 6.894757293168361e9", "FromBaseToUnitFunc": "{x} / 6.894757293168361e9", "Prefixes": [ "Kilo" ], @@ -245,11 +235,6 @@ { "SingularName": "PoundForcePerSquareFoot", "PluralName": "PoundsForcePerSquareFoot", - "BaseUnits": { - "L": "Foot", - "M": "Pound", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 4.788025898033584e1", "FromBaseToUnitFunc": "{x} / 4.788025898033584e1", "Prefixes": [ "Kilo" ], @@ -264,11 +249,6 @@ { "SingularName": "TonneForcePerSquareMillimeter", "PluralName": "TonnesForcePerSquareMillimeter", - "BaseUnits": { - "L": "Millimeter", - "M": "Tonne", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 9.80665e9", "FromBaseToUnitFunc": "{x} / 9.80665e9", "Localization": [ @@ -281,11 +261,6 @@ { "SingularName": "TonneForcePerSquareMeter", "PluralName": "TonnesForcePerSquareMeter", - "BaseUnits": { - "L": "Meter", - "M": "Tonne", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 9.80665e3", "FromBaseToUnitFunc": "{x} / 9.80665e3", "Localization": [ @@ -310,11 +285,6 @@ { "SingularName": "TonneForcePerSquareCentimeter", "PluralName": "TonnesForcePerSquareCentimeter", - "BaseUnits": { - "L": "Centimeter", - "M": "Tonne", - "T": "Second" - }, "FromUnitToBaseFunc": "{x} * 9.80665e7", "FromBaseToUnitFunc": "{x} / 9.80665e7", "Localization": [ diff --git a/Common/UnitDefinitions/RadiationEquivalentDoseRate.json b/Common/UnitDefinitions/RadiationEquivalentDoseRate.json index e33d3bae8e..8057849e78 100644 --- a/Common/UnitDefinitions/RadiationEquivalentDoseRate.json +++ b/Common/UnitDefinitions/RadiationEquivalentDoseRate.json @@ -28,6 +28,10 @@ { "SingularName": "SievertPerSecond", "PluralName": "SievertsPerSecond", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli" ], diff --git a/Common/UnitDefinitions/RatioChangeRate.json b/Common/UnitDefinitions/RatioChangeRate.json index be72a57bde..572c51513a 100644 --- a/Common/UnitDefinitions/RatioChangeRate.json +++ b/Common/UnitDefinitions/RatioChangeRate.json @@ -2,7 +2,9 @@ "Name": "RatioChangeRate", "BaseUnit": "DecimalFractionPerSecond", "XmlDocSummary": "The change in ratio per unit of time.", - "BaseDimensions": { "T": -1 }, + "BaseDimensions": { + "T": -1 + }, "Units": [ { "SingularName": "PercentPerSecond", @@ -19,6 +21,9 @@ { "SingularName": "DecimalFractionPerSecond", "PluralName": "DecimalFractionsPerSecond", + "BaseUnits": { + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/ReciprocalArea.json b/Common/UnitDefinitions/ReciprocalArea.json index 425302d1cd..f1ca16d012 100644 --- a/Common/UnitDefinitions/ReciprocalArea.json +++ b/Common/UnitDefinitions/ReciprocalArea.json @@ -10,6 +10,9 @@ { "SingularName": "InverseSquareMeter", "PluralName": "InverseSquareMeters", + "BaseUnits": { + "L": "Meter" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -22,6 +25,9 @@ { "SingularName": "InverseSquareKilometer", "PluralName": "InverseSquareKilometers", + "BaseUnits": { + "L": "Kilometer" + }, "FromUnitToBaseFunc": "{x} / 1e6", "FromBaseToUnitFunc": "{x} * 1e6", "Localization": [ @@ -34,6 +40,9 @@ { "SingularName": "InverseSquareDecimeter", "PluralName": "InverseSquareDecimeters", + "BaseUnits": { + "L": "Decimeter" + }, "FromUnitToBaseFunc": "{x} / 1e-2", "FromBaseToUnitFunc": "{x} * 1e-2", "Localization": [ @@ -46,6 +55,9 @@ { "SingularName": "InverseSquareCentimeter", "PluralName": "InverseSquareCentimeters", + "BaseUnits": { + "L": "Centimeter" + }, "FromUnitToBaseFunc": "{x} / 1e-4", "FromBaseToUnitFunc": "{x} * 1e-4", "Localization": [ @@ -58,6 +70,9 @@ { "SingularName": "InverseSquareMillimeter", "PluralName": "InverseSquareMillimeters", + "BaseUnits": { + "L": "Millimeter" + }, "FromUnitToBaseFunc": "{x} / 1e-6", "FromBaseToUnitFunc": "{x} * 1e-6", "Localization": [ @@ -70,6 +85,9 @@ { "SingularName": "InverseSquareMicrometer", "PluralName": "InverseSquareMicrometers", + "BaseUnits": { + "L": "Micrometer" + }, "FromUnitToBaseFunc": "{x} / 1e-12", "FromBaseToUnitFunc": "{x} * 1e-12", "Localization": [ @@ -82,6 +100,9 @@ { "SingularName": "InverseSquareMile", "PluralName": "InverseSquareMiles", + "BaseUnits": { + "L": "Mile" + }, "FromUnitToBaseFunc": "{x} / 2.59e6", "FromBaseToUnitFunc": "{x} * 2.59e6", "Localization": [ @@ -94,6 +115,9 @@ { "SingularName": "InverseSquareYard", "PluralName": "InverseSquareYards", + "BaseUnits": { + "L": "Yard" + }, "FromUnitToBaseFunc": "{x} / 0.836127", "FromBaseToUnitFunc": "{x} * 0.836127", "Localization": [ @@ -106,6 +130,9 @@ { "SingularName": "InverseSquareFoot", "PluralName": "InverseSquareFeet", + "BaseUnits": { + "L": "Foot" + }, "FromUnitToBaseFunc": "{x} / 0.092903", "FromBaseToUnitFunc": "{x} * 0.092903", "Localization": [ @@ -118,6 +145,9 @@ { "SingularName": "InverseUsSurveySquareFoot", "PluralName": "InverseUsSurveySquareFeet", + "BaseUnits": { + "L": "UsSurveyFoot" + }, "FromUnitToBaseFunc": "{x} / 0.09290341161", "FromBaseToUnitFunc": "{x} * 0.09290341161", "Localization": [ @@ -130,6 +160,9 @@ { "SingularName": "InverseSquareInch", "PluralName": "InverseSquareInches", + "BaseUnits": { + "L": "Inch" + }, "FromUnitToBaseFunc": "{x} / 0.00064516", "FromBaseToUnitFunc": "{x} * 0.00064516", "Localization": [ diff --git a/Common/UnitDefinitions/ReciprocalLength.json b/Common/UnitDefinitions/ReciprocalLength.json index 400599c29f..2ea4841425 100644 --- a/Common/UnitDefinitions/ReciprocalLength.json +++ b/Common/UnitDefinitions/ReciprocalLength.json @@ -10,6 +10,9 @@ { "SingularName": "InverseMeter", "PluralName": "InverseMeters", + "BaseUnits": { + "L": "Meter" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -22,6 +25,9 @@ { "SingularName": "InverseCentimeter", "PluralName": "InverseCentimeters", + "BaseUnits": { + "L": "Centimeter" + }, "FromUnitToBaseFunc": "{x} * 1e2", "FromBaseToUnitFunc": "{x} / 1e2", "Localization": [ @@ -34,6 +40,9 @@ { "SingularName": "InverseMillimeter", "PluralName": "InverseMillimeters", + "BaseUnits": { + "L": "Millimeter" + }, "FromUnitToBaseFunc": "{x} * 1e3", "FromBaseToUnitFunc": "{x} / 1e3", "Localization": [ @@ -46,6 +55,9 @@ { "SingularName": "InverseMile", "PluralName": "InverseMiles", + "BaseUnits": { + "L": "Mile" + }, "FromUnitToBaseFunc": "{x} / 1609.344", "FromBaseToUnitFunc": "{x} * 1609.344", "Localization": [ @@ -58,6 +70,9 @@ { "SingularName": "InverseYard", "PluralName": "InverseYards", + "BaseUnits": { + "L": "Yard" + }, "FromUnitToBaseFunc": "{x} / 0.9144", "FromBaseToUnitFunc": "{x} * 0.9144", "Localization": [ @@ -70,6 +85,9 @@ { "SingularName": "InverseFoot", "PluralName": "InverseFeet", + "BaseUnits": { + "L": "Foot" + }, "FromUnitToBaseFunc": "{x} / 0.3048", "FromBaseToUnitFunc": "{x} * 0.3048", "Localization": [ @@ -82,6 +100,9 @@ { "SingularName": "InverseUsSurveyFoot", "PluralName": "InverseUsSurveyFeet", + "BaseUnits": { + "L": "UsSurveyFoot" + }, "FromUnitToBaseFunc": "{x} * 3937 / 1200", "FromBaseToUnitFunc": "{x} * 1200 / 3937", "Localization": [ @@ -94,6 +115,9 @@ { "SingularName": "InverseInch", "PluralName": "InverseInches", + "BaseUnits": { + "L": "Inch" + }, "FromUnitToBaseFunc": "{x} / 2.54e-2", "FromBaseToUnitFunc": "{x} * 2.54e-2", "Localization": [ @@ -106,6 +130,9 @@ { "SingularName": "InverseMil", "PluralName": "InverseMils", + "BaseUnits": { + "L": "Mil" + }, "FromUnitToBaseFunc": "{x} / 2.54e-5", "FromBaseToUnitFunc": "{x} * 2.54e-5", "Localization": [ @@ -118,6 +145,9 @@ { "SingularName": "InverseMicroinch", "PluralName": "InverseMicroinches", + "BaseUnits": { + "L": "Microinch" + }, "FromUnitToBaseFunc": "{x} / 2.54e-8", "FromBaseToUnitFunc": "{x} * 2.54e-8", "Localization": [ diff --git a/Common/UnitDefinitions/RotationalAcceleration.json b/Common/UnitDefinitions/RotationalAcceleration.json index 90e7ce0879..6f6df6f2bd 100644 --- a/Common/UnitDefinitions/RotationalAcceleration.json +++ b/Common/UnitDefinitions/RotationalAcceleration.json @@ -9,6 +9,9 @@ { "SingularName": "RadianPerSecondSquared", "PluralName": "RadiansPerSecondSquared", + "BaseUnits": { + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/RotationalSpeed.json b/Common/UnitDefinitions/RotationalSpeed.json index 0ee2d13ab0..3b72f0ce62 100644 --- a/Common/UnitDefinitions/RotationalSpeed.json +++ b/Common/UnitDefinitions/RotationalSpeed.json @@ -9,6 +9,9 @@ { "SingularName": "RadianPerSecond", "PluralName": "RadiansPerSecond", + "BaseUnits": { + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci" ], diff --git a/Common/UnitDefinitions/RotationalStiffness.json b/Common/UnitDefinitions/RotationalStiffness.json index eeadfe573d..02bf2d6605 100644 --- a/Common/UnitDefinitions/RotationalStiffness.json +++ b/Common/UnitDefinitions/RotationalStiffness.json @@ -11,6 +11,11 @@ { "SingularName": "NewtonMeterPerRadian", "PluralName": "NewtonMetersPerRadian", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/RotationalStiffnessPerLength.json b/Common/UnitDefinitions/RotationalStiffnessPerLength.json index 791ee833a1..8d3e9614a0 100644 --- a/Common/UnitDefinitions/RotationalStiffnessPerLength.json +++ b/Common/UnitDefinitions/RotationalStiffnessPerLength.json @@ -11,6 +11,11 @@ { "SingularName": "NewtonMeterPerRadianPerMeter", "PluralName": "NewtonMetersPerRadianPerMeter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/SpecificEnergy.json b/Common/UnitDefinitions/SpecificEnergy.json index ad8ed862f2..946d38e252 100644 --- a/Common/UnitDefinitions/SpecificEnergy.json +++ b/Common/UnitDefinitions/SpecificEnergy.json @@ -11,6 +11,10 @@ { "SingularName": "JoulePerKilogram", "PluralName": "JoulesPerKilogram", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/SpecificEntropy.json b/Common/UnitDefinitions/SpecificEntropy.json index 225e099c9e..4bfe6040e6 100644 --- a/Common/UnitDefinitions/SpecificEntropy.json +++ b/Common/UnitDefinitions/SpecificEntropy.json @@ -11,6 +11,11 @@ { "SingularName": "JoulePerKilogramKelvin", "PluralName": "JoulesPerKilogramKelvin", + "BaseUnits": { + "L": "Meter", + "T": "Second", + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], @@ -24,6 +29,11 @@ { "SingularName": "JoulePerKilogramDegreeCelsius", "PluralName": "JoulesPerKilogramDegreeCelsius", + "BaseUnits": { + "L": "Meter", + "T": "Second", + "Θ": "DegreeCelsius" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/SpecificFuelConsumption.json b/Common/UnitDefinitions/SpecificFuelConsumption.json index 52516e863d..35d7d5c4ad 100644 --- a/Common/UnitDefinitions/SpecificFuelConsumption.json +++ b/Common/UnitDefinitions/SpecificFuelConsumption.json @@ -3,6 +3,10 @@ "BaseUnit": "GramPerKiloNewtonSecond", "XmlDocSummary": "SFC is the fuel efficiency of an engine design with respect to thrust output", "XmlDocRemarks": "https://en.wikipedia.org/wiki/Thrust-specific_fuel_consumption", + "BaseDimensions": { + "L": -1, + "T": 1 + }, "Units": [ { "SingularName": "PoundMassPerPoundForceHour", @@ -31,6 +35,10 @@ { "SingularName": "GramPerKiloNewtonSecond", "PluralName": "GramsPerKiloNewtonSecond", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo" ], diff --git a/Common/UnitDefinitions/SpecificVolume.json b/Common/UnitDefinitions/SpecificVolume.json index a428f3355d..9595c97ca4 100644 --- a/Common/UnitDefinitions/SpecificVolume.json +++ b/Common/UnitDefinitions/SpecificVolume.json @@ -10,6 +10,10 @@ { "SingularName": "CubicMeterPerKilogram", "PluralName": "CubicMetersPerKilogram", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Milli" ], @@ -23,6 +27,10 @@ { "SingularName": "CubicFootPerPound", "PluralName": "CubicFeetPerPound", + "BaseUnits": { + "L": "Foot", + "M": "Pound" + }, "FromUnitToBaseFunc": "{x} / 16.01846353", "FromBaseToUnitFunc": "{x} * 16.01846353", "Prefixes": [], diff --git a/Common/UnitDefinitions/SpecificWeight.json b/Common/UnitDefinitions/SpecificWeight.json index 3ff8a8f11a..f2e24adb86 100644 --- a/Common/UnitDefinitions/SpecificWeight.json +++ b/Common/UnitDefinitions/SpecificWeight.json @@ -38,6 +38,11 @@ { "SingularName": "NewtonPerCubicMeter", "PluralName": "NewtonsPerCubicMeter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/StandardVolumeFlow.json b/Common/UnitDefinitions/StandardVolumeFlow.json index bf731df37e..3e95680da9 100644 --- a/Common/UnitDefinitions/StandardVolumeFlow.json +++ b/Common/UnitDefinitions/StandardVolumeFlow.json @@ -10,6 +10,10 @@ { "SingularName": "StandardCubicMeterPerSecond", "PluralName": "StandardCubicMetersPerSecond", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -22,6 +26,10 @@ { "SingularName": "StandardCubicMeterPerMinute", "PluralName": "StandardCubicMetersPerMinute", + "BaseUnits": { + "L": "Meter", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60", "FromBaseToUnitFunc": "{x} * 60", "Localization": [ @@ -34,6 +42,10 @@ { "SingularName": "StandardCubicMeterPerHour", "PluralName": "StandardCubicMetersPerHour", + "BaseUnits": { + "L": "Meter", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} / 3600", "FromBaseToUnitFunc": "{x} * 3600", "Localization": [ @@ -46,6 +58,10 @@ { "SingularName": "StandardCubicMeterPerDay", "PluralName": "StandardCubicMetersPerDay", + "BaseUnits": { + "L": "Meter", + "T": "Day" + }, "FromUnitToBaseFunc": "{x} / 86400", "FromBaseToUnitFunc": "{x} * 86400", "Localization": [ @@ -58,6 +74,10 @@ { "SingularName": "StandardCubicCentimeterPerMinute", "PluralName": "StandardCubicCentimetersPerMinute", + "BaseUnits": { + "L": "Centimeter", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 6e7", "FromBaseToUnitFunc": "{x} * 6e7", "Localization": [ @@ -70,6 +90,10 @@ { "SingularName": "StandardLiterPerMinute", "PluralName": "StandardLitersPerMinute", + "BaseUnits": { + "L": "Decimeter", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60000", "FromBaseToUnitFunc": "{x} * 60000", "Localization": [ @@ -82,6 +106,10 @@ { "SingularName": "StandardCubicFootPerSecond", "PluralName": "StandardCubicFeetPerSecond", + "BaseUnits": { + "L": "Foot", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} / 35.314666721", "FromBaseToUnitFunc": "{x} * 35.314666721", "Localization": [ @@ -94,6 +122,10 @@ { "SingularName": "StandardCubicFootPerMinute", "PluralName": "StandardCubicFeetPerMinute", + "BaseUnits": { + "L": "Foot", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 2118.88000326", "FromBaseToUnitFunc": "{x} * 2118.88000326", "Localization": [ @@ -106,6 +138,10 @@ { "SingularName": "StandardCubicFootPerHour", "PluralName": "StandardCubicFeetPerHour", + "BaseUnits": { + "L": "Foot", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} * 7.8657907199999087346816086183876e-6", "FromBaseToUnitFunc": "{x} / 7.8657907199999087346816086183876e-6", "Localization": [ diff --git a/Common/UnitDefinitions/TemperatureChangeRate.json b/Common/UnitDefinitions/TemperatureChangeRate.json index 1a8bc7b534..5bbc63ac89 100644 --- a/Common/UnitDefinitions/TemperatureChangeRate.json +++ b/Common/UnitDefinitions/TemperatureChangeRate.json @@ -10,6 +10,10 @@ { "SingularName": "DegreeCelsiusPerSecond", "PluralName": "DegreesCelsiusPerSecond", + "BaseUnits": { + "Θ": "DegreeCelsius", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], @@ -23,6 +27,10 @@ { "SingularName": "DegreeCelsiusPerMinute", "PluralName": "DegreesCelsiusPerMinute", + "BaseUnits": { + "Θ": "DegreeCelsius", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60", "FromBaseToUnitFunc": "{x} * 60", "Localization": [ diff --git a/Common/UnitDefinitions/TemperatureDelta.json b/Common/UnitDefinitions/TemperatureDelta.json index 9215f4ec24..04ef0a53a9 100644 --- a/Common/UnitDefinitions/TemperatureDelta.json +++ b/Common/UnitDefinitions/TemperatureDelta.json @@ -9,6 +9,9 @@ { "SingularName": "Kelvin", "PluralName": "Kelvins", + "BaseUnits": { + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -21,6 +24,9 @@ { "SingularName": "DegreeCelsius", "PluralName": "DegreesCelsius", + "BaseUnits": { + "Θ": "DegreeCelsius" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Milli" ], @@ -35,6 +41,9 @@ { "SingularName": "DegreeDelisle", "PluralName": "DegreesDelisle", + "BaseUnits": { + "Θ": "DegreeDelisle" + }, "FromUnitToBaseFunc": "{x} * -2 / 3", "FromBaseToUnitFunc": "{x} * -3 / 2", "Localization": [ @@ -47,6 +56,9 @@ { "SingularName": "DegreeFahrenheit", "PluralName": "DegreesFahrenheit", + "BaseUnits": { + "Θ": "DegreeFahrenheit" + }, "FromUnitToBaseFunc": "{x} * 5 / 9", "FromBaseToUnitFunc": "{x} * 9 / 5", "Localization": [ @@ -59,6 +71,9 @@ { "SingularName": "DegreeNewton", "PluralName": "DegreesNewton", + "BaseUnits": { + "Θ": "DegreeNewton" + }, "FromUnitToBaseFunc": "{x} * 100 / 33", "FromBaseToUnitFunc": "{x} * 33 / 100", "Localization": [ @@ -71,6 +86,9 @@ { "SingularName": "DegreeRankine", "PluralName": "DegreesRankine", + "BaseUnits": { + "Θ": "DegreeRankine" + }, "FromUnitToBaseFunc": "{x} * 5 / 9", "FromBaseToUnitFunc": "{x} * 9 / 5", "Localization": [ @@ -83,6 +101,9 @@ { "SingularName": "DegreeReaumur", "PluralName": "DegreesReaumur", + "BaseUnits": { + "Θ": "DegreeReaumur" + }, "FromUnitToBaseFunc": "{x} * 5 / 4", "FromBaseToUnitFunc": "{x} * 4 / 5", "Localization": [ @@ -95,6 +116,9 @@ { "SingularName": "DegreeRoemer", "PluralName": "DegreesRoemer", + "BaseUnits": { + "Θ": "DegreeRoemer" + }, "FromUnitToBaseFunc": "{x} * 40 / 21", "FromBaseToUnitFunc": "{x} * 21 / 40", "Localization": [ diff --git a/Common/UnitDefinitions/ThermalConductivity.json b/Common/UnitDefinitions/ThermalConductivity.json index 978c7122c5..8cbff91577 100644 --- a/Common/UnitDefinitions/ThermalConductivity.json +++ b/Common/UnitDefinitions/ThermalConductivity.json @@ -13,6 +13,12 @@ { "SingularName": "WattPerMeterKelvin", "PluralName": "WattsPerMeterKelvin", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second", + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ diff --git a/Common/UnitDefinitions/ThermalInsulance.json b/Common/UnitDefinitions/ThermalInsulance.json index af042e2c56..a2f9f424ba 100644 --- a/Common/UnitDefinitions/ThermalInsulance.json +++ b/Common/UnitDefinitions/ThermalInsulance.json @@ -23,6 +23,11 @@ { "SingularName": "SquareMeterKelvinPerWatt", "PluralName": "SquareMeterKelvinsPerWatt", + "BaseUnits": { + "M": "Kilogram", + "T": "Second", + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x} * 1000", "FromBaseToUnitFunc": "{x} / 1000", "Localization": [ @@ -35,6 +40,11 @@ { "SingularName": "SquareMeterDegreeCelsiusPerWatt", "PluralName": "SquareMeterDegreesCelsiusPerWatt", + "BaseUnits": { + "M": "Kilogram", + "T": "Second", + "Θ": "DegreeCelsius" + }, "FromUnitToBaseFunc": "{x} * 1000.0", "FromBaseToUnitFunc": "{x} / 1000.0", "Localization": [ diff --git a/Common/UnitDefinitions/Torque.json b/Common/UnitDefinitions/Torque.json index 4567759fe8..53013a31ef 100644 --- a/Common/UnitDefinitions/Torque.json +++ b/Common/UnitDefinitions/Torque.json @@ -37,6 +37,11 @@ { "SingularName": "NewtonMeter", "PluralName": "NewtonMeters", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index 270d3d2275..85666dbf34 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -9,6 +9,9 @@ { "SingularName": "Liter", "PluralName": "Liters", + "BaseUnits": { + "L": "Decimeter" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo", "Mega" ], @@ -46,6 +49,9 @@ { "SingularName": "CubicKilometer", "PluralName": "CubicKilometers", + "BaseUnits": { + "L": "Kilometer" + }, "FromUnitToBaseFunc": "{x} * 1e9", "FromBaseToUnitFunc": "{x} / 1e9", "Localization": [ @@ -81,6 +87,9 @@ { "SingularName": "CubicDecimeter", "PluralName": "CubicDecimeters", + "BaseUnits": { + "L": "Decimeter" + }, "FromUnitToBaseFunc": "{x} / 1e3", "FromBaseToUnitFunc": "{x} * 1e3", "Localization": [ @@ -97,6 +106,9 @@ { "SingularName": "CubicCentimeter", "PluralName": "CubicCentimeters", + "BaseUnits": { + "L": "Centimeter" + }, "FromUnitToBaseFunc": "{x} / 1e6", "FromBaseToUnitFunc": "{x} * 1e6", "Localization": [ @@ -113,6 +125,9 @@ { "SingularName": "CubicMillimeter", "PluralName": "CubicMillimeters", + "BaseUnits": { + "L": "Millimeter" + }, "FromUnitToBaseFunc": "{x} / 1e9", "FromBaseToUnitFunc": "{x} * 1e9", "Localization": [ @@ -129,6 +144,9 @@ { "SingularName": "CubicMicrometer", "PluralName": "CubicMicrometers", + "BaseUnits": { + "L": "Micrometer" + }, "FromUnitToBaseFunc": "{x} / 1e18", "FromBaseToUnitFunc": "{x} * 1e18", "Localization": [ @@ -145,6 +163,9 @@ { "SingularName": "CubicMile", "PluralName": "CubicMiles", + "BaseUnits": { + "L": "Mile" + }, "FromUnitToBaseFunc": "{x} * 4.16818182544058e9", "FromBaseToUnitFunc": "{x} / 4.16818182544058e9", "Localization": [ @@ -161,6 +182,9 @@ { "SingularName": "CubicYard", "PluralName": "CubicYards", + "BaseUnits": { + "L": "Yard" + }, "FromUnitToBaseFunc": "{x} * 0.764554858", "FromBaseToUnitFunc": "{x} / 0.764554858", "Localization": [ @@ -177,6 +201,9 @@ { "SingularName": "CubicFoot", "PluralName": "CubicFeet", + "BaseUnits": { + "L": "Foot" + }, "FromUnitToBaseFunc": "{x} * 2.8316846592e-2", "FromBaseToUnitFunc": "{x} / 2.8316846592e-2", "Prefixes": [ "Hecto", "Kilo", "Mega" ], @@ -194,6 +221,9 @@ { "SingularName": "CubicInch", "PluralName": "CubicInches", + "BaseUnits": { + "L": "Inch" + }, "FromUnitToBaseFunc": "{x} * 1.6387064e-5", "FromBaseToUnitFunc": "{x} / 1.6387064e-5", "Localization": [ @@ -500,9 +530,6 @@ { "SingularName": "ImperialPint", "PluralName": "ImperialPints", - "BaseUnits": { - "L": "Decimeter" - }, "FromUnitToBaseFunc": "{x} * 5.6826125e-4", "FromBaseToUnitFunc": "{x} / 5.6826125e-4", "Localization": [ diff --git a/Common/UnitDefinitions/VolumeFlow.json b/Common/UnitDefinitions/VolumeFlow.json index 5abe12f512..78c99179d8 100644 --- a/Common/UnitDefinitions/VolumeFlow.json +++ b/Common/UnitDefinitions/VolumeFlow.json @@ -10,6 +10,10 @@ { "SingularName": "CubicMeterPerSecond", "PluralName": "CubicMetersPerSecond", + "BaseUnits": { + "L": "Meter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Localization": [ @@ -26,6 +30,10 @@ { "SingularName": "CubicMeterPerMinute", "PluralName": "CubicMetersPerMinute", + "BaseUnits": { + "L": "Meter", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60", "FromBaseToUnitFunc": "{x} * 60", "Localization": [ @@ -42,6 +50,10 @@ { "SingularName": "CubicMeterPerHour", "PluralName": "CubicMetersPerHour", + "BaseUnits": { + "L": "Meter", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} / 3600", "FromBaseToUnitFunc": "{x} * 3600", "Localization": [ @@ -58,6 +70,10 @@ { "SingularName": "CubicMeterPerDay", "PluralName": "CubicMetersPerDay", + "BaseUnits": { + "L": "Meter", + "T": "Day" + }, "FromUnitToBaseFunc": "{x} / 86400", "FromBaseToUnitFunc": "{x} * 86400", "Localization": [ @@ -70,6 +86,10 @@ { "SingularName": "CubicFootPerSecond", "PluralName": "CubicFeetPerSecond", + "BaseUnits": { + "L": "Foot", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} / 35.314666721", "FromBaseToUnitFunc": "{x} * 35.314666721", "Localization": [ @@ -82,6 +102,10 @@ { "SingularName": "CubicFootPerMinute", "PluralName": "CubicFeetPerMinute", + "BaseUnits": { + "L": "Foot", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 2118.88000326", "FromBaseToUnitFunc": "{x} * 2118.88000326", "Localization": [ @@ -94,6 +118,10 @@ { "SingularName": "CubicFootPerHour", "PluralName": "CubicFeetPerHour", + "BaseUnits": { + "L": "Foot", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} * 7.8657907199999087346816086183876e-6", "FromBaseToUnitFunc": "{x} / 7.8657907199999087346816086183876e-6", "Localization": [ @@ -118,6 +146,10 @@ { "SingularName": "CubicYardPerMinute", "PluralName": "CubicYardsPerMinute", + "BaseUnits": { + "L": "Yard", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} * 0.0127425809664", "FromBaseToUnitFunc": "{x} / 0.0127425809664", "Localization": [ @@ -130,6 +162,10 @@ { "SingularName": "CubicYardPerHour", "PluralName": "CubicYardsPerHour", + "BaseUnits": { + "L": "Yard", + "T": "Hour" + }, "FromUnitToBaseFunc": "{x} * 2.1237634944E-4", "FromBaseToUnitFunc": "{x} / 2.1237634944E-4", "Localization": [ @@ -142,6 +178,10 @@ { "SingularName": "CubicYardPerDay", "PluralName": "CubicYardsPerDay", + "BaseUnits": { + "L": "Yard", + "T": "Day" + }, "FromUnitToBaseFunc": "{x} / 113007", "FromBaseToUnitFunc": "{x} * 113007", "Localization": [ @@ -341,6 +381,10 @@ { "SingularName": "CubicDecimeterPerMinute", "PluralName": "CubicDecimetersPerMinute", + "BaseUnits": { + "L": "Decimeter", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} / 60000.00000", "FromBaseToUnitFunc": "{x} * 60000.00000", "Localization": [ @@ -405,6 +449,10 @@ { "SingularName": "CubicMillimeterPerSecond", "PluralName": "CubicMillimetersPerSecond", + "BaseUnits": { + "L": "Millimeter", + "T": "Second" + }, "FromUnitToBaseFunc": "{x} * 1e-9", "FromBaseToUnitFunc": "{x} / 1e-9", "Localization": [ @@ -469,6 +517,10 @@ { "SingularName": "CubicCentimeterPerMinute", "PluralName": "CubicCentimetersPerMinute", + "BaseUnits": { + "L": "Centimeter", + "T": "Minute" + }, "FromUnitToBaseFunc": "{x} * 1.6666666666667e-8", "FromBaseToUnitFunc": "{x} / 1.6666666666667e-8", "Localization": [ diff --git a/Common/UnitDefinitions/VolumetricHeatCapacity.json b/Common/UnitDefinitions/VolumetricHeatCapacity.json index e2352a1595..80dde6906b 100644 --- a/Common/UnitDefinitions/VolumetricHeatCapacity.json +++ b/Common/UnitDefinitions/VolumetricHeatCapacity.json @@ -13,6 +13,12 @@ { "SingularName": "JoulePerCubicMeterKelvin", "PluralName": "JoulesPerCubicMeterKelvin", + "BaseUnits": { + "M": "Kilogram", + "L": "Meter", + "T": "Second", + "Θ": "Kelvin" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], @@ -26,6 +32,12 @@ { "SingularName": "JoulePerCubicMeterDegreeCelsius", "PluralName": "JoulesPerCubicMeterDegreeCelsius", + "BaseUnits": { + "M": "Kilogram", + "L": "Meter", + "T": "Second", + "Θ": "DegreeCelsius" + }, "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", "Prefixes": [ "Kilo", "Mega" ], diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCharge.g.cs index 987068df54..251d26918f 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -235,14 +235,14 @@ private double GetValueInBaseUnit() { return Unit switch { - ElectricChargeUnit.AmpereHour => _value / 2.77777777777e-4, + ElectricChargeUnit.AmpereHour => _value * 3600, ElectricChargeUnit.Coulomb => _value, - ElectricChargeUnit.KiloampereHour => (_value / 2.77777777777e-4) * 1e3d, + ElectricChargeUnit.KiloampereHour => (_value * 3600) * 1e3d, ElectricChargeUnit.Kilocoulomb => (_value) * 1e3d, - ElectricChargeUnit.MegaampereHour => (_value / 2.77777777777e-4) * 1e6d, + ElectricChargeUnit.MegaampereHour => (_value * 3600) * 1e6d, ElectricChargeUnit.Megacoulomb => (_value) * 1e6d, ElectricChargeUnit.Microcoulomb => (_value) * 1e-6d, - ElectricChargeUnit.MilliampereHour => (_value / 2.77777777777e-4) * 1e-3d, + ElectricChargeUnit.MilliampereHour => (_value * 3600) * 1e-3d, ElectricChargeUnit.Millicoulomb => (_value) * 1e-3d, ElectricChargeUnit.Nanocoulomb => (_value) * 1e-9d, ElectricChargeUnit.Picocoulomb => (_value) * 1e-12d, @@ -259,14 +259,14 @@ private double GetValueAs(ElectricChargeUnit unit) return unit switch { - ElectricChargeUnit.AmpereHour => baseUnitValue * 2.77777777777e-4, + ElectricChargeUnit.AmpereHour => baseUnitValue / 3600, ElectricChargeUnit.Coulomb => baseUnitValue, - ElectricChargeUnit.KiloampereHour => (baseUnitValue * 2.77777777777e-4) / 1e3d, + ElectricChargeUnit.KiloampereHour => (baseUnitValue / 3600) / 1e3d, ElectricChargeUnit.Kilocoulomb => (baseUnitValue) / 1e3d, - ElectricChargeUnit.MegaampereHour => (baseUnitValue * 2.77777777777e-4) / 1e6d, + ElectricChargeUnit.MegaampereHour => (baseUnitValue / 3600) / 1e6d, ElectricChargeUnit.Megacoulomb => (baseUnitValue) / 1e6d, ElectricChargeUnit.Microcoulomb => (baseUnitValue) / 1e-6d, - ElectricChargeUnit.MilliampereHour => (baseUnitValue * 2.77777777777e-4) / 1e-3d, + ElectricChargeUnit.MilliampereHour => (baseUnitValue / 3600) / 1e-3d, ElectricChargeUnit.Millicoulomb => (baseUnitValue) / 1e-3d, ElectricChargeUnit.Nanocoulomb => (baseUnitValue) / 1e-9d, ElectricChargeUnit.Picocoulomb => (baseUnitValue) / 1e-12d, diff --git a/UnitsNet.Tests/CustomCode/DensityTests.cs b/UnitsNet.Tests/CustomCode/DensityTests.cs index 70e562d9c1..b0a1930560 100644 --- a/UnitsNet.Tests/CustomCode/DensityTests.cs +++ b/UnitsNet.Tests/CustomCode/DensityTests.cs @@ -121,6 +121,30 @@ public class DensityTests : DensityTestsBase protected override double SlugsPerCubicInchInOneKilogramPerCubicMeter => 1.1228705576569e-6; + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + [Fact] public static void DensityTimesVolumeEqualsMass() { diff --git a/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs b/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs index 919fa27c9b..c1f249132c 100644 --- a/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs @@ -18,6 +18,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -30,5 +31,29 @@ public class ElectricApparentEnergyTests : ElectricApparentEnergyTestsBase protected override double KilovoltampereHoursInOneVoltampereHour => 1E-3; protected override double MegavoltampereHoursInOneVoltampereHour => 1E-6; + + [Fact(Skip = "See about adding an SI unit (VoltampereSecond, Joules?)")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "See about changing the BaseUnit to VoltampereSecond or Joule (adding the unit)")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "See about adding an SI unit (VoltampereSecond, Joules?)")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "See about adding an SI unit (VoltampereSecond, Joules?)")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } } } diff --git a/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs b/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs index fa691f0a7a..3f0ea76660 100644 --- a/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs @@ -18,6 +18,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -29,5 +30,29 @@ public class ElectricReactiveEnergyTests : ElectricReactiveEnergyTestsBase protected override double KilovoltampereReactiveHoursInOneVoltampereReactiveHour => 1E-3; protected override double MegavoltampereReactiveHoursInOneVoltampereReactiveHour => 1E-6; + + [Fact(Skip = "See about adding an SI unit (VoltampereReactiveSecond, Joules?)")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "See about changing the BaseUnit to VoltampereReactiveSecond or Joule (adding the unit)")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "See about adding an SI unit (VoltampereReactiveSecond, Joules?)")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "See about adding an SI unit (VoltampereReactiveSecond, Joules?)")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } } } diff --git a/UnitsNet.Tests/CustomCode/LengthTests.cs b/UnitsNet.Tests/CustomCode/LengthTests.cs index 85779f0271..a086bbd285 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.cs @@ -203,13 +203,6 @@ public void Constructor_UnitSystemSI_AssignsSIUnit() Assert.Equal(LengthUnit.Meter, length.Unit); } - [Fact] - public void Constructor_UnitSystemWithNoMatchingBaseUnits_ThrowsArgumentException() - { - // AmplitudeRatio is unitless. Can't have any matches :) - Assert.Throws(() => new AmplitudeRatio(1.0, UnitSystem.SI)); - } - [Fact] public void As_GivenSIUnitSystem_ReturnsSIValue() { diff --git a/UnitsNet.Tests/CustomCode/LinearDensityTests.cs b/UnitsNet.Tests/CustomCode/LinearDensityTests.cs index 23483d2153..e6f8c9bcb0 100644 --- a/UnitsNet.Tests/CustomCode/LinearDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/LinearDensityTests.cs @@ -55,6 +55,30 @@ public class LinearDensityTests : LinearDensityTestsBase protected override double PoundsPerFootInOneKilogramPerMeter => 6.71968975e-1; + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + [Fact] public void LinearDensityDividedByAreaEqualsDensity() { diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs index 9b7f2432fa..7188938fda 100644 --- a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -85,6 +85,30 @@ public class MassConcentrationTests : MassConcentrationTestsBase protected override double OuncesPerUSGallonInOneKilogramPerCubicMeter => 0.1335264711843; #endregion + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + [Theory] [InlineData(60.02, MassConcentrationUnit.KilogramPerCubicMeter, 58.443, MolarMassUnit.GramPerMole, diff --git a/UnitsNet.Tests/CustomCode/MassFlowTests.cs b/UnitsNet.Tests/CustomCode/MassFlowTests.cs index 19fe286228..1b39b49b56 100644 --- a/UnitsNet.Tests/CustomCode/MassFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFlowTests.cs @@ -76,6 +76,30 @@ public class MassFlowTests : MassFlowTestsBase protected override double GramsPerHourInOneGramPerSecond => 3600; + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "See about changing the BaseUnit to KilogramPerSecond")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + [Fact] public void DurationTimesMassFlowEqualsMass() { diff --git a/UnitsNet.Tests/CustomCode/MassFluxTests.cs b/UnitsNet.Tests/CustomCode/MassFluxTests.cs index 7638abc52e..8be8889443 100644 --- a/UnitsNet.Tests/CustomCode/MassFluxTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFluxTests.cs @@ -43,6 +43,30 @@ public class MassFluxTests : MassFluxTestsBase protected override double KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-1; protected override double KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-3; + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + [Fact] public void MassFluxDividedBySpeedEqualsDensity() { diff --git a/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs b/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs index edc7d56a16..6fbe339704 100644 --- a/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs +++ b/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs @@ -22,6 +22,7 @@ using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -84,5 +85,29 @@ public class MassMomentOfInertiaTests : MassMomentOfInertiaTestsBase protected override double TonneSquareMetersInOneKilogramSquareMeter => 1e-3; protected override double TonneSquareMilimetersInOneKilogramSquareMeter => 1e3; + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } } } diff --git a/UnitsNet.Tests/CustomCode/MassTests.cs b/UnitsNet.Tests/CustomCode/MassTests.cs index 2e5cfd1c5b..7cdb4b9918 100644 --- a/UnitsNet.Tests/CustomCode/MassTests.cs +++ b/UnitsNet.Tests/CustomCode/MassTests.cs @@ -67,7 +67,29 @@ public class MassTests : MassTestsBase protected override double PicogramsInOneKilogram => 1E15; - //protected override double SolarMassesTolerance => 0.1; + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } [Fact] public void AccelerationTimesMassEqualsForce() diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs index e48321fd36..964dccf220 100644 --- a/UnitsNet.Tests/CustomCode/MolarMassTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs @@ -44,6 +44,30 @@ public class MolarMassTests : MolarMassTestsBase protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; protected override double KilogramsPerKilomoleInOneKilogramPerMole => 1e3; + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "The BaseUnits are not yet supported by the prefix-generator")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + [Fact] public void MolarMassTimesAmountOfSubstanceEqualsMass() { diff --git a/UnitsNet.Tests/CustomCode/QuantityInfos/QuantityInfoExtensionsTest.cs b/UnitsNet.Tests/CustomCode/QuantityInfos/QuantityInfoExtensionsTest.cs new file mode 100644 index 0000000000..24085e6b4a --- /dev/null +++ b/UnitsNet.Tests/CustomCode/QuantityInfos/QuantityInfoExtensionsTest.cs @@ -0,0 +1,71 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using UnitsNet.Units; +using Xunit; + +namespace UnitsNet.Tests.QuantityInfos; + +public class QuantityInfoExtensionsTest +{ + [Fact] + public void GetDefaultUnit_ThrowsException_WhenUnitSystemIsNull() + { + Assert.Throws(() => Length.Info.GetDefaultUnit(null!)); + } + + [Fact] + public void GetDefaultUnit_ThrowsArgumentException_WhenNoUnitsFoundForUnitSystem() + { + // simulating a combination of units that won't match anything + var unsupportedUnitSystem = new UnitSystem(new BaseUnits( + (LengthUnit)(-1), + (MassUnit)(-1), + (DurationUnit)(-1), + (ElectricCurrentUnit)(-1), + (TemperatureUnit)(-1), + (AmountOfSubstanceUnit)(-1), + (LuminousIntensityUnit)(-1))); + + Assert.Throws(() => Length.Info.GetDefaultUnit(unsupportedUnitSystem)); + } + + [Fact] + public void GetDefaultUnit_ReturnsCorrectUnit_ForSpecificUnitSystem() + { + LengthUnit defaultUnit = Length.Info.GetDefaultUnit(UnitSystem.SI); + + Assert.Equal(LengthUnit.Meter, defaultUnit); + } + + [Fact] + public void GetDefaultUnit_ReturnsFirstUnit_WhenMultipleUnitsExistForUnitSystem() + { + // Arrange + var unitSystem = new UnitSystem(new BaseUnits( + LengthUnit.Decimeter, + (MassUnit)(-1), + (DurationUnit)(-1), + (ElectricCurrentUnit)(-1), + (TemperatureUnit)(-1), + (AmountOfSubstanceUnit)(-1), + (LuminousIntensityUnit)(-1))); + + // Act + VolumeUnit defaultUnit = Volume.Info.GetDefaultUnit(unitSystem); + + // Assert + Assert.Equal(VolumeUnit.CubicDecimeter, defaultUnit); + } + + [Fact] + public void GetDefaultUnit_ReturnsTheBaseUnit_WhenGivenADimensionlessQuantity() + { + Assert.Multiple( + () => Assert.Equal(RatioUnit.DecimalFraction, Ratio.Info.GetDefaultUnit(UnitSystem.SI)), + () => Assert.Equal(MassFractionUnit.DecimalFraction, MassFraction.Info.GetDefaultUnit(UnitSystem.SI)), + () => Assert.Equal(AngleUnit.Radian, Angle.Info.GetDefaultUnit(UnitSystem.SI)), + () => Assert.Equal(SolidAngleUnit.Steradian, SolidAngle.Info.GetDefaultUnit(UnitSystem.SI))); + } +} diff --git a/UnitsNet.Tests/CustomCode/SpecificFuelConsumptionTests.cs b/UnitsNet.Tests/CustomCode/SpecificFuelConsumptionTests.cs index ee24c7758d..ce22b6eec8 100644 --- a/UnitsNet.Tests/CustomCode/SpecificFuelConsumptionTests.cs +++ b/UnitsNet.Tests/CustomCode/SpecificFuelConsumptionTests.cs @@ -18,6 +18,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -32,6 +33,6 @@ public class SpecificFuelConsumptionTests : SpecificFuelConsumptionTestsBase protected override double PoundsMassPerPoundForceHourInOneGramPerKiloNewtonSecond => 0.03529827; - protected override double KilogramsPerKilogramForceHourInOneGramPerKiloNewtonSecond => 0.03529827; + protected override double KilogramsPerKilogramForceHourInOneGramPerKiloNewtonSecond => 0.03529827; } } diff --git a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs index 72e2e3e455..3b42e7aa9f 100644 --- a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs @@ -42,8 +42,31 @@ public class TemperatureChangeRateTests : TemperatureChangeRateTestsBase protected override double DegreesKelvinPerSecondInOneDegreeCelsiusPerSecond => 1; protected override double DegreesCelsiusPerHourInOneDegreeCelsiusPerSecond => 3600; + - + [Fact(Skip = "Missing the KelvinPerSecond unit")] + public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() + { + base.Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits(); + } + + [Fact(Skip = "See about changing the BaseUnit to KelvinPerSecond")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } + + [Fact(Skip = "Missing the KelvinPerSecond unit")] + public override void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.As_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } + + [Fact(Skip = "Missing the KelvinPerSecond unit")] + public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits(); + } [Fact] public void TemperatureChangeRateMultipliedWithTimeSpanEqualsTemperatureDelta() diff --git a/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs b/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs index ec0d61aa69..cb8b11882c 100644 --- a/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs +++ b/UnitsNet.Tests/CustomCode/TestsBase/QuantityTestsBase.cs @@ -1,4 +1,6 @@ -namespace UnitsNet.Tests.TestsBase +using UnitsNet.Units; + +namespace UnitsNet.Tests.TestsBase { public abstract class QuantityTestsBase { @@ -6,6 +8,24 @@ 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; } + protected virtual bool SupportsSIUnitSystem { get; } = true; + + /// + /// Gets a predefined instance of representing unsupported or invalid base units. + /// + /// + /// This property is initialized with invalid unit values, represented by negative enumerations of + /// , , , , + /// , , and . + /// It is intended for use in scenarios where base units are not supported or need to be explicitly marked as invalid. + /// + protected static BaseUnits UnsupportedBaseUnits { get; } = new( + (LengthUnit)(-1), + (MassUnit)(-1), + (DurationUnit)(-1), + (ElectricCurrentUnit)(-1), + (TemperatureUnit)(-1), + (AmountOfSubstanceUnit)(-1), + (LuminousIntensityUnit)(-1)); } } diff --git a/UnitsNet.Tests/CustomCode/ThermalInsulanceTests.cs b/UnitsNet.Tests/CustomCode/ThermalInsulanceTests.cs index 8ef94686e4..04ad2d5c2c 100644 --- a/UnitsNet.Tests/CustomCode/ThermalInsulanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ThermalInsulanceTests.cs @@ -18,6 +18,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -30,5 +31,11 @@ public class ThermalInsulanceTests : ThermalInsulanceTestsBase protected override double SquareMeterDegreesCelsiusPerWattInOneSquareMeterKelvinPerKilowatt => 1e-3; protected override double SquareMeterKelvinsPerKilowattInOneSquareMeterKelvinPerKilowatt => 1; protected override double SquareMeterKelvinsPerWattInOneSquareMeterKelvinPerKilowatt => 0.001; + + [Fact(Skip = "See about changing the BaseUnit to SquareMeterKelvinPerWatt")] + public override void BaseUnit_HasSIBase() + { + base.BaseUnit_HasSIBase(); + } } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs index c73f176c92..18ed31d7f7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs @@ -152,18 +152,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new AbsorbedDoseOfIonizingRadiation(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (AbsorbedDoseOfIonizingRadiation) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new AbsorbedDoseOfIonizingRadiation(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -312,20 +312,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = AbsorbedDoseOfIonizingRadiation.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + var expectedValue = quantity.As(AbsorbedDoseOfIonizingRadiation.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = AbsorbedDoseOfIonizingRadiation.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + AbsorbedDoseOfIonizingRadiation quantityToConvert = quantity; + + AbsorbedDoseOfIonizingRadiation convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index d8477708b6..0879a6b214 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -144,18 +144,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Acceleration(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Acceleration) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Acceleration(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Acceleration(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -292,20 +292,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Acceleration.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + var expectedValue = quantity.As(Acceleration.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Acceleration.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Acceleration quantityToConvert = quantity; + + Acceleration convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index 4803afa163..49e464382a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -156,18 +156,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new AmountOfSubstance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (AmountOfSubstance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new AmountOfSubstance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new AmountOfSubstance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -322,20 +322,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = AmountOfSubstance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + var expectedValue = quantity.As(AmountOfSubstance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = AmountOfSubstance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + AmountOfSubstance quantityToConvert = quantity; + + AmountOfSubstance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index 4f81f7b51e..f5f8083341 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -97,27 +97,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void AmplitudeRatio_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -192,20 +171,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatioUnit.DecibelVolt); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatioUnit.DecibelVolt); + + AmplitudeRatio convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(AmplitudeRatioUnit.DecibelVolt, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatioUnit.DecibelVolt); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(AmplitudeRatioUnit.DecibelVolt, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatioUnit.DecibelVolt); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(AmplitudeRatioUnit.DecibelVolt, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index c4ff8b2806..e7055d0a73 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -141,27 +141,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void Angle_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -302,20 +281,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new Angle(value: 1, unit: AngleUnit.Radian); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new Angle(value: 1, unit: Angle.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new Angle(value: 1, unit: AngleUnit.Radian); + + Angle convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(AngleUnit.Radian, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new Angle(value: 1, unit: AngleUnit.Radian); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(AngleUnit.Radian, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new Angle(value: 1, unit: AngleUnit.Radian); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(AngleUnit.Radian, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Angle(value: 1, unit: Angle.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Angle(value: 1, unit: Angle.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Angle(value: 1, unit: Angle.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index 206a8179d2..05d1bb83d4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new AreaDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (AreaDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new AreaDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new AreaDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = AreaDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + var expectedValue = quantity.As(AreaDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = AreaDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + AreaDensity quantityToConvert = quantity; + + AreaDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 38e613c388..9df6f7ac70 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new AreaMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (AreaMomentOfInertia) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new AreaMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new AreaMomentOfInertia(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = AreaMomentOfInertia.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + var expectedValue = quantity.As(AreaMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = AreaMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + AreaMomentOfInertia quantityToConvert = quantity; + + AreaMomentOfInertia convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index 64659ab0b7..b89886adb6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -144,18 +144,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Area(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Area) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Area(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Area(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -292,20 +292,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Area.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Area(value: 1, unit: Area.BaseUnit); + var expectedValue = quantity.As(Area.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Area(value: 1, unit: Area.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Area(value: 1, unit: Area.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Area(value: 1, unit: Area.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Area.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Area quantityToConvert = quantity; + + Area convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Area(value: 1, unit: Area.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Area(value: 1, unit: Area.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Area(value: 1, unit: Area.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Area(value: 1, unit: Area.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Area(value: 1, unit: Area.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Area(value: 1, unit: Area.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index 39871640de..576192179b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -192,18 +192,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new BitRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (BitRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new BitRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new BitRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -412,20 +412,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = BitRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + var expectedValue = quantity.As(BitRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = BitRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + BitRate quantityToConvert = quantity; + + BitRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new BitRate(value: 1, unit: BitRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index 6043b6179f..13df892898 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new BrakeSpecificFuelConsumption(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (BrakeSpecificFuelConsumption) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new BrakeSpecificFuelConsumption(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new BrakeSpecificFuelConsumption(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = BrakeSpecificFuelConsumption.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + var expectedValue = quantity.As(BrakeSpecificFuelConsumption.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = BrakeSpecificFuelConsumption.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + BrakeSpecificFuelConsumption quantityToConvert = quantity; + + BrakeSpecificFuelConsumption convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index 2fc84d591a..79bc06a406 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new CoefficientOfThermalExpansion(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (CoefficientOfThermalExpansion) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new CoefficientOfThermalExpansion(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new CoefficientOfThermalExpansion(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = CoefficientOfThermalExpansion.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + var expectedValue = quantity.As(CoefficientOfThermalExpansion.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = CoefficientOfThermalExpansion.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + CoefficientOfThermalExpansion quantityToConvert = quantity; + + CoefficientOfThermalExpansion convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs index 741d895284..0f79896816 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -116,18 +116,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Compressibility(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Compressibility) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Compressibility(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Compressibility(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -222,20 +222,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Compressibility.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + var expectedValue = quantity.As(Compressibility.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Compressibility.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Compressibility quantityToConvert = quantity; + + Compressibility convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index 71a688e659..2693b0e659 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -312,18 +312,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Density(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Density) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Density(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Density(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -712,20 +712,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Density.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Density(value: 1, unit: Density.BaseUnit); + var expectedValue = quantity.As(Density.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Density(value: 1, unit: Density.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Density(value: 1, unit: Density.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Density(value: 1, unit: Density.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Density.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Density quantityToConvert = quantity; + + Density convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Density(value: 1, unit: Density.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Density(value: 1, unit: Density.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Density(value: 1, unit: Density.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Density(value: 1, unit: Density.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Density(value: 1, unit: Density.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Density(value: 1, unit: Density.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs index 3d117b22c9..31da791da1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs @@ -168,18 +168,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new DoseAreaProduct(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (DoseAreaProduct) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new DoseAreaProduct(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new DoseAreaProduct(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -352,20 +352,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = DoseAreaProduct.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + var expectedValue = quantity.As(DoseAreaProduct.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = DoseAreaProduct.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + DoseAreaProduct quantityToConvert = quantity; + + DoseAreaProduct convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index 9cf6c4fd45..716638d9a6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -136,18 +136,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Duration(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Duration) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Duration(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Duration(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -272,20 +272,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Duration.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Duration(value: 1, unit: Duration.BaseUnit); + var expectedValue = quantity.As(Duration.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Duration(value: 1, unit: Duration.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Duration(value: 1, unit: Duration.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Duration(value: 1, unit: Duration.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Duration.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Duration quantityToConvert = quantity; + + Duration convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Duration(value: 1, unit: Duration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index fe420c3483..4d1eaa3e17 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -128,18 +128,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new DynamicViscosity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (DynamicViscosity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new DynamicViscosity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new DynamicViscosity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -252,20 +252,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = DynamicViscosity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + var expectedValue = quantity.As(DynamicViscosity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = DynamicViscosity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + DynamicViscosity quantityToConvert = quantity; + + DynamicViscosity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index b85b90f30f..b6665ba49a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -152,18 +152,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricAdmittance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricAdmittance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricAdmittance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricAdmittance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -312,20 +312,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricAdmittance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + var expectedValue = quantity.As(ElectricAdmittance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricAdmittance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricAdmittance quantityToConvert = quantity; + + ElectricAdmittance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs index 1a6b467e96..7a1acab441 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricApparentEnergy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricApparentEnergy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricApparentEnergy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricApparentEnergy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricApparentEnergy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + var expectedValue = quantity.As(ElectricApparentEnergy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricApparentEnergy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricApparentEnergy quantityToConvert = quantity; + + ElectricApparentEnergy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs index c66938b9cb..0714ffefe0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricApparentPower(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricApparentPower) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricApparentPower(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricApparentPower(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricApparentPower.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + var expectedValue = quantity.As(ElectricApparentPower.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricApparentPower.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricApparentPower quantityToConvert = quantity; + + ElectricApparentPower convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs index 792adb21dc..11124fa66d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs @@ -116,18 +116,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricCapacitance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricCapacitance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricCapacitance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricCapacitance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -222,20 +222,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricCapacitance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + var expectedValue = quantity.As(ElectricCapacitance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricCapacitance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricCapacitance quantityToConvert = quantity; + + ElectricCapacitance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index cf609f8a1a..0d8fac37a3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricChargeDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricChargeDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricChargeDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricChargeDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricChargeDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + var expectedValue = quantity.As(ElectricChargeDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricChargeDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricChargeDensity quantityToConvert = quantity; + + ElectricChargeDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index 42959b0a7d..36bda2b288 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -132,18 +132,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricCharge(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricCharge) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricCharge(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricCharge(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -262,20 +262,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricCharge.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + var expectedValue = quantity.As(ElectricCharge.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricCharge.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricCharge quantityToConvert = quantity; + + ElectricCharge convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index a70607c9fe..8752f829bd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -152,18 +152,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricConductance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricConductance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricConductance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricConductance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -312,20 +312,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricConductance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + var expectedValue = quantity.As(ElectricConductance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricConductance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricConductance quantityToConvert = quantity; + + ElectricConductance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index 911caa16b1..cd8f3f8dc8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricConductivity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricConductivity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricConductivity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricConductivity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricConductivity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + var expectedValue = quantity.As(ElectricConductivity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricConductivity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricConductivity quantityToConvert = quantity; + + ElectricConductivity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index 074f27cbbd..085b357359 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricCurrentDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricCurrentDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricCurrentDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricCurrentDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricCurrentDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + var expectedValue = quantity.As(ElectricCurrentDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricCurrentDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricCurrentDensity quantityToConvert = quantity; + + ElectricCurrentDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index b415946424..f722cfd9b8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -116,18 +116,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricCurrentGradient(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricCurrentGradient) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricCurrentGradient(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricCurrentGradient(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -222,20 +222,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricCurrentGradient.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + var expectedValue = quantity.As(ElectricCurrentGradient.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricCurrentGradient.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricCurrentGradient quantityToConvert = quantity; + + ElectricCurrentGradient convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index de7c630470..1f81368431 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricCurrent(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricCurrent) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricCurrent(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricCurrent(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricCurrent.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + var expectedValue = quantity.As(ElectricCurrent.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricCurrent.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricCurrent quantityToConvert = quantity; + + ElectricCurrent convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index 92fe7dddfb..86ec0c7c66 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricField(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricField) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricField(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricField(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricField.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + var expectedValue = quantity.As(ElectricField.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricField.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricField quantityToConvert = quantity; + + ElectricField convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs index 6cd293bf1e..06d2f0b8bc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs @@ -120,18 +120,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricImpedance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricImpedance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricImpedance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricImpedance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -232,20 +232,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricImpedance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + var expectedValue = quantity.As(ElectricImpedance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricImpedance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricImpedance quantityToConvert = quantity; + + ElectricImpedance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index f81cf019f8..caadf35b50 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -108,18 +108,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricInductance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricInductance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricInductance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricInductance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -202,20 +202,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricInductance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + var expectedValue = quantity.As(ElectricInductance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricInductance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricInductance quantityToConvert = quantity; + + ElectricInductance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index a5f9d5e30a..6ce145dfa3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -168,18 +168,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricPotentialChangeRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricPotentialChangeRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricPotentialChangeRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricPotentialChangeRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -352,20 +352,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricPotentialChangeRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + var expectedValue = quantity.As(ElectricPotentialChangeRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricPotentialChangeRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricPotentialChangeRate quantityToConvert = quantity; + + ElectricPotentialChangeRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index 951bc53d64..247c00c671 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricPotential(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricPotential) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricPotential(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricPotential(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricPotential.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + var expectedValue = quantity.As(ElectricPotential.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricPotential.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricPotential quantityToConvert = quantity; + + ElectricPotential convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricPotential(value: 1, unit: ElectricPotential.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs index 35b5a7a520..d1b3e5d740 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs @@ -120,18 +120,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricReactance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricReactance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricReactance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricReactance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -232,20 +232,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricReactance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + var expectedValue = quantity.As(ElectricReactance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricReactance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricReactance quantityToConvert = quantity; + + ElectricReactance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactance(value: 1, unit: ElectricReactance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs index 2ba0083fed..435d5a4787 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricReactiveEnergy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricReactiveEnergy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricReactiveEnergy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricReactiveEnergy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricReactiveEnergy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + var expectedValue = quantity.As(ElectricReactiveEnergy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricReactiveEnergy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricReactiveEnergy quantityToConvert = quantity; + + ElectricReactiveEnergy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs index 40b9f901b7..04e6e8d630 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs @@ -104,18 +104,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricReactivePower(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricReactivePower) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricReactivePower(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricReactivePower(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -192,20 +192,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricReactivePower.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + var expectedValue = quantity.As(ElectricReactivePower.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricReactivePower.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricReactivePower quantityToConvert = quantity; + + ElectricReactivePower convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index c02dd4a055..2d5014b75b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -120,18 +120,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricResistance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricResistance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricResistance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricResistance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -232,20 +232,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricResistance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + var expectedValue = quantity.As(ElectricResistance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricResistance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricResistance quantityToConvert = quantity; + + ElectricResistance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistance(value: 1, unit: ElectricResistance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index bb733b6b10..7265586455 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -144,18 +144,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricResistivity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricResistivity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricResistivity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricResistivity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -292,20 +292,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricResistivity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + var expectedValue = quantity.As(ElectricResistivity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricResistivity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricResistivity quantityToConvert = quantity; + + ElectricResistivity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricResistivity(value: 1, unit: ElectricResistivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index 3fa5007e8c..7594f699c0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricSurfaceChargeDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricSurfaceChargeDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricSurfaceChargeDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricSurfaceChargeDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricSurfaceChargeDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + var expectedValue = quantity.As(ElectricSurfaceChargeDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricSurfaceChargeDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricSurfaceChargeDensity quantityToConvert = quantity; + + ElectricSurfaceChargeDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSurfaceChargeDensity(value: 1, unit: ElectricSurfaceChargeDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs index de7f063994..ccf47c9069 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs @@ -152,18 +152,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ElectricSusceptance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricSusceptance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ElectricSusceptance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ElectricSusceptance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -312,20 +312,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ElectricSusceptance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + var expectedValue = quantity.As(ElectricSusceptance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ElectricSusceptance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ElectricSusceptance quantityToConvert = quantity; + + ElectricSusceptance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs index 7661cac5dd..7fb67c62a8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs @@ -136,18 +136,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new EnergyDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (EnergyDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new EnergyDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new EnergyDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -272,20 +272,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = EnergyDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + var expectedValue = quantity.As(EnergyDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = EnergyDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + EnergyDensity quantityToConvert = quantity; + + EnergyDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new EnergyDensity(value: 1, unit: EnergyDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index 602e60824e..909a56c123 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -248,18 +248,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Energy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Energy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Energy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Energy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -552,20 +552,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Energy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Energy(value: 1, unit: Energy.BaseUnit); + var expectedValue = quantity.As(Energy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Energy(value: 1, unit: Energy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Energy(value: 1, unit: Energy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Energy(value: 1, unit: Energy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Energy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Energy quantityToConvert = quantity; + + Energy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Energy(value: 1, unit: Energy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index 72efc1b1fb..f5fbfe9cca 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -116,18 +116,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Entropy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Entropy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Entropy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Entropy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -222,20 +222,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Entropy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + var expectedValue = quantity.As(Entropy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Entropy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Entropy quantityToConvert = quantity; + + Entropy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Entropy(value: 1, unit: Entropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index 1865f7f3d5..ebbb0144a3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -148,18 +148,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ForceChangeRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ForceChangeRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ForceChangeRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ForceChangeRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -302,20 +302,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ForceChangeRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + var expectedValue = quantity.As(ForceChangeRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ForceChangeRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ForceChangeRate quantityToConvert = quantity; + + ForceChangeRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ForceChangeRate(value: 1, unit: ForceChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index b1beb9f917..4cdb03a3e8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -240,18 +240,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ForcePerLength(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ForcePerLength) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ForcePerLength(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ForcePerLength(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -532,20 +532,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ForcePerLength.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + var expectedValue = quantity.As(ForcePerLength.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ForcePerLength.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ForcePerLength quantityToConvert = quantity; + + ForcePerLength convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ForcePerLength(value: 1, unit: ForcePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 3572efe181..42b2a3ddde 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -148,18 +148,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Force(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Force) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Force(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Force(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -302,20 +302,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Force.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Force(value: 1, unit: Force.BaseUnit); + var expectedValue = quantity.As(Force.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Force(value: 1, unit: Force.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Force(value: 1, unit: Force.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Force(value: 1, unit: Force.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Force.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Force quantityToConvert = quantity; + + Force convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Force(value: 1, unit: Force.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Force(value: 1, unit: Force.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Force(value: 1, unit: Force.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Force(value: 1, unit: Force.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Force(value: 1, unit: Force.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Force(value: 1, unit: Force.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index 7f9d74731a..0df2755195 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -140,18 +140,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Frequency(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Frequency) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Frequency(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Frequency(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -282,20 +282,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Frequency.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + var expectedValue = quantity.As(Frequency.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Frequency.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Frequency quantityToConvert = quantity; + + Frequency convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Frequency(value: 1, unit: Frequency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 2759b777a3..57340bb920 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -97,27 +97,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void FuelEfficiency_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -192,20 +171,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new FuelEfficiency(value: 1, unit: FuelEfficiencyUnit.LiterPer100Kilometers); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new FuelEfficiency(value: 1, unit: FuelEfficiency.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new FuelEfficiency(value: 1, unit: FuelEfficiencyUnit.LiterPer100Kilometers); + + FuelEfficiency convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new FuelEfficiency(value: 1, unit: FuelEfficiencyUnit.LiterPer100Kilometers); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new FuelEfficiency(value: 1, unit: FuelEfficiencyUnit.LiterPer100Kilometers); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new FuelEfficiency(value: 1, unit: FuelEfficiency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new FuelEfficiency(value: 1, unit: FuelEfficiency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new FuelEfficiency(value: 1, unit: FuelEfficiency.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index 88c29e9f6f..5b8d16e0c8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -160,18 +160,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new HeatFlux(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (HeatFlux) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new HeatFlux(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new HeatFlux(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -332,20 +332,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = HeatFlux.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + var expectedValue = quantity.As(HeatFlux.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = HeatFlux.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + HeatFlux quantityToConvert = quantity; + + HeatFlux convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new HeatFlux(value: 1, unit: HeatFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index ff29458203..5575bdb86c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -108,18 +108,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new HeatTransferCoefficient(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (HeatTransferCoefficient) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new HeatTransferCoefficient(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new HeatTransferCoefficient(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -202,20 +202,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = HeatTransferCoefficient.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + var expectedValue = quantity.As(HeatTransferCoefficient.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = HeatTransferCoefficient.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + HeatTransferCoefficient quantityToConvert = quantity; + + HeatTransferCoefficient convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new HeatTransferCoefficient(value: 1, unit: HeatTransferCoefficient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index 0bee304f9e..5f754f77c7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -104,18 +104,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Illuminance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Illuminance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Illuminance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Illuminance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -192,20 +192,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Illuminance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + var expectedValue = quantity.As(Illuminance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Illuminance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Illuminance quantityToConvert = quantity; + + Illuminance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Illuminance(value: 1, unit: Illuminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs index e4c2700492..99f5cc80b4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs @@ -140,18 +140,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Impulse(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Impulse) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Impulse(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Impulse(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -282,20 +282,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Impulse.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + var expectedValue = quantity.As(Impulse.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Impulse.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Impulse quantityToConvert = quantity; + + Impulse convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Impulse(value: 1, unit: Impulse.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index d67b5e0a58..9f7b01ec00 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -185,27 +185,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [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() { @@ -412,20 +391,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new Information(value: 1, unit: InformationUnit.Bit); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new Information(value: 1, unit: Information.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new Information(value: 1, unit: InformationUnit.Bit); + + Information convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(InformationUnit.Bit, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new Information(value: 1, unit: InformationUnit.Bit); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(InformationUnit.Bit, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new Information(value: 1, unit: InformationUnit.Bit); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(InformationUnit.Bit, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Information(value: 1, unit: Information.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Information(value: 1, unit: Information.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Information(value: 1, unit: Information.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index 49fb3c1f00..e90ca6d017 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -144,18 +144,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Irradiance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Irradiance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Irradiance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Irradiance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -292,20 +292,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Irradiance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + var expectedValue = quantity.As(Irradiance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Irradiance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Irradiance quantityToConvert = quantity; + + Irradiance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiance(value: 1, unit: Irradiance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index 85e34b8e17..d3af297d7f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Irradiation(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Irradiation) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Irradiation(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Irradiation(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Irradiation.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + var expectedValue = quantity.As(Irradiation.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Irradiation.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Irradiation quantityToConvert = quantity; + + Irradiation convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Irradiation(value: 1, unit: Irradiation.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs index 557ba2c468..ea7d46d355 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs @@ -132,18 +132,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Jerk(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Jerk) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Jerk(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Jerk(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -262,20 +262,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Jerk.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + var expectedValue = quantity.As(Jerk.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Jerk.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Jerk quantityToConvert = quantity; + + Jerk convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Jerk(value: 1, unit: Jerk.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index 3846fdb570..faef046540 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new KinematicViscosity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (KinematicViscosity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new KinematicViscosity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new KinematicViscosity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = KinematicViscosity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + var expectedValue = quantity.As(KinematicViscosity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = KinematicViscosity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + KinematicViscosity quantityToConvert = quantity; + + KinematicViscosity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new KinematicViscosity(value: 1, unit: KinematicViscosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs index 111aa13fcc..750d465020 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new LeakRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (LeakRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new LeakRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new LeakRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = LeakRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + var expectedValue = quantity.As(LeakRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = LeakRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + LeakRate quantityToConvert = quantity; + + LeakRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LeakRate(value: 1, unit: LeakRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 1873a2ce3a..0f44ebdec5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -256,18 +256,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Length(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Length) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Length(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Length(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -572,20 +572,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Length.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Length(value: 1, unit: Length.BaseUnit); + var expectedValue = quantity.As(Length.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Length(value: 1, unit: Length.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Length(value: 1, unit: Length.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Length(value: 1, unit: Length.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Length.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Length quantityToConvert = quantity; + + Length convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Length(value: 1, unit: Length.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Length(value: 1, unit: Length.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Length(value: 1, unit: Length.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Length(value: 1, unit: Length.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Length(value: 1, unit: Length.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Length(value: 1, unit: Length.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index dd5c1bea6a..ba3772249d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -89,27 +89,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void Level_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -172,20 +151,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new Level(value: 1, unit: LevelUnit.Decibel); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new Level(value: 1, unit: Level.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new Level(value: 1, unit: LevelUnit.Decibel); + + Level convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(LevelUnit.Decibel, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new Level(value: 1, unit: LevelUnit.Decibel); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(LevelUnit.Decibel, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new Level(value: 1, unit: LevelUnit.Decibel); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(LevelUnit.Decibel, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Level(value: 1, unit: Level.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Level(value: 1, unit: Level.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Level(value: 1, unit: Level.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index a0e1b52e9e..5566e59997 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -160,18 +160,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new LinearDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (LinearDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new LinearDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new LinearDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -332,20 +332,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = LinearDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + var expectedValue = quantity.As(LinearDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = LinearDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + LinearDensity quantityToConvert = quantity; + + LinearDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LinearDensity(value: 1, unit: LinearDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index 78678950e4..a375280eca 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -188,18 +188,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new LinearPowerDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (LinearPowerDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new LinearPowerDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new LinearPowerDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -402,20 +402,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = LinearPowerDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + var expectedValue = quantity.As(LinearPowerDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = LinearPowerDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + LinearPowerDensity quantityToConvert = quantity; + + LinearPowerDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LinearPowerDensity(value: 1, unit: LinearPowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs index 721efd462b..bfc81d20ce 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs @@ -128,18 +128,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Luminance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Luminance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Luminance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Luminance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -252,20 +252,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Luminance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + var expectedValue = quantity.As(Luminance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Luminance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Luminance quantityToConvert = quantity; + + Luminance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Luminance(value: 1, unit: Luminance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index 6b898701b1..714c2a0d25 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -144,18 +144,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Luminosity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Luminosity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Luminosity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Luminosity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -292,20 +292,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Luminosity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + var expectedValue = quantity.As(Luminosity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Luminosity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Luminosity quantityToConvert = quantity; + + Luminosity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Luminosity(value: 1, unit: Luminosity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index ef7615c083..8776daf591 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new LuminousFlux(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (LuminousFlux) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new LuminousFlux(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new LuminousFlux(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = LuminousFlux.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + var expectedValue = quantity.As(LuminousFlux.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = LuminousFlux.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + LuminousFlux quantityToConvert = quantity; + + LuminousFlux convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousFlux(value: 1, unit: LuminousFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index 3d10070cf6..42c3f1146b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new LuminousIntensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (LuminousIntensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new LuminousIntensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new LuminousIntensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = LuminousIntensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + var expectedValue = quantity.As(LuminousIntensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = LuminousIntensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + LuminousIntensity quantityToConvert = quantity; + + LuminousIntensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new LuminousIntensity(value: 1, unit: LuminousIntensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index a346ba0002..6ad548b2da 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MagneticField(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MagneticField) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MagneticField(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MagneticField(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MagneticField.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + var expectedValue = quantity.As(MagneticField.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MagneticField.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MagneticField quantityToConvert = quantity; + + MagneticField convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticField(value: 1, unit: MagneticField.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index 5109ef42a5..ffac86b182 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MagneticFlux(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MagneticFlux) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MagneticFlux(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MagneticFlux(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MagneticFlux.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + var expectedValue = quantity.As(MagneticFlux.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MagneticFlux.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MagneticFlux quantityToConvert = quantity; + + MagneticFlux convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MagneticFlux(value: 1, unit: MagneticFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index 3332bf3441..8936bda651 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Magnetization(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Magnetization) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Magnetization(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Magnetization(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Magnetization.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + var expectedValue = quantity.As(Magnetization.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Magnetization.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Magnetization quantityToConvert = quantity; + + Magnetization convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Magnetization(value: 1, unit: Magnetization.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index cc07258b28..d4c743e9f9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -284,18 +284,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MassConcentration(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MassConcentration) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MassConcentration(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MassConcentration(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -642,20 +642,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MassConcentration.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + var expectedValue = quantity.As(MassConcentration.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MassConcentration.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MassConcentration quantityToConvert = quantity; + + MassConcentration convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassConcentration(value: 1, unit: MassConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index 00eaee0c61..97c190f13e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -220,18 +220,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MassFlow(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MassFlow) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MassFlow(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MassFlow(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -482,20 +482,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MassFlow.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + var expectedValue = quantity.As(MassFlow.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MassFlow.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MassFlow quantityToConvert = quantity; + + MassFlow convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlow(value: 1, unit: MassFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 54ca14ebbe..6d3c806b5e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -136,18 +136,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MassFlux(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MassFlux) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MassFlux(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MassFlux(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -272,20 +272,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MassFlux.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + var expectedValue = quantity.As(MassFlux.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MassFlux.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MassFlux quantityToConvert = quantity; + + MassFlux convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassFlux(value: 1, unit: MassFlux.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index a28eb20228..914e7128ac 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -177,27 +177,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void MassFraction_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -392,20 +371,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new MassFraction(value: 1, unit: MassFractionUnit.DecimalFraction); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new MassFraction(value: 1, unit: MassFraction.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new MassFraction(value: 1, unit: MassFractionUnit.DecimalFraction); + + MassFraction convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(MassFractionUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new MassFraction(value: 1, unit: MassFractionUnit.DecimalFraction); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(MassFractionUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new MassFraction(value: 1, unit: MassFractionUnit.DecimalFraction); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(MassFractionUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MassFraction(value: 1, unit: MassFraction.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassFraction(value: 1, unit: MassFraction.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassFraction(value: 1, unit: MassFraction.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index 5f7c96aa4e..79bd5ec378 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -200,18 +200,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MassMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MassMomentOfInertia) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MassMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MassMomentOfInertia(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -432,20 +432,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MassMomentOfInertia.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + var expectedValue = quantity.As(MassMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MassMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MassMomentOfInertia quantityToConvert = quantity; + + MassMomentOfInertia convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MassMomentOfInertia(value: 1, unit: MassMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index 47482d8fae..b7932ac98d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -196,18 +196,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Mass(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Mass) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Mass(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Mass(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -422,20 +422,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Mass.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Mass(value: 1, unit: Mass.BaseUnit); + var expectedValue = quantity.As(Mass.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Mass(value: 1, unit: Mass.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Mass(value: 1, unit: Mass.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Mass(value: 1, unit: Mass.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Mass.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Mass quantityToConvert = quantity; + + Mass convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Mass(value: 1, unit: Mass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs index 682596fcbd..395c13d8a8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Molality(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Molality) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Molality(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Molality(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Molality.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Molality(value: 1, unit: Molality.BaseUnit); + var expectedValue = quantity.As(Molality.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Molality(value: 1, unit: Molality.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Molality(value: 1, unit: Molality.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Molality(value: 1, unit: Molality.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Molality.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Molality quantityToConvert = quantity; + + Molality convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Molality(value: 1, unit: Molality.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Molality(value: 1, unit: Molality.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Molality(value: 1, unit: Molality.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Molality(value: 1, unit: Molality.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Molality(value: 1, unit: Molality.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Molality(value: 1, unit: Molality.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 9974c7bffd..67cc78086e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MolarEnergy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MolarEnergy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MolarEnergy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MolarEnergy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MolarEnergy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + var expectedValue = quantity.As(MolarEnergy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MolarEnergy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MolarEnergy quantityToConvert = quantity; + + MolarEnergy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEnergy(value: 1, unit: MolarEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index ae969db053..787d39027d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MolarEntropy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MolarEntropy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MolarEntropy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MolarEntropy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MolarEntropy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + var expectedValue = quantity.As(MolarEntropy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MolarEntropy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MolarEntropy quantityToConvert = quantity; + + MolarEntropy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarEntropy(value: 1, unit: MolarEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs index 9d8694b623..dc38c81c86 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MolarFlow(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MolarFlow) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MolarFlow(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MolarFlow(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MolarFlow.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + var expectedValue = quantity.As(MolarFlow.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MolarFlow.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MolarFlow quantityToConvert = quantity; + + MolarFlow convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarFlow(value: 1, unit: MolarFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index 35c6b69a65..925dfbc2a0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -140,18 +140,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new MolarMass(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (MolarMass) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new MolarMass(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new MolarMass(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -282,20 +282,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = MolarMass.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + var expectedValue = quantity.As(MolarMass.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = MolarMass.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + MolarMass quantityToConvert = quantity; + + MolarMass convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new MolarMass(value: 1, unit: MolarMass.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index e6144e3a0b..cf9549b954 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -132,18 +132,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Molarity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Molarity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Molarity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Molarity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -262,20 +262,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Molarity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + var expectedValue = quantity.As(Molarity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Molarity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Molarity quantityToConvert = quantity; + + Molarity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Molarity(value: 1, unit: Molarity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index 67fffbbbfc..58002953dd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Permeability(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Permeability) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Permeability(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Permeability(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Permeability.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + var expectedValue = quantity.As(Permeability.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Permeability.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Permeability quantityToConvert = quantity; + + Permeability convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Permeability(value: 1, unit: Permeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index acf01b2b8e..4f69102829 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -92,18 +92,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Permittivity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Permittivity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Permittivity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Permittivity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -162,20 +162,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Permittivity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + var expectedValue = quantity.As(Permittivity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Permittivity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Permittivity quantityToConvert = quantity; + + Permittivity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Permittivity(value: 1, unit: Permittivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs index dd5f62af2b..5d1b7daf2a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs @@ -108,18 +108,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new PorousMediumPermeability(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (PorousMediumPermeability) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new PorousMediumPermeability(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new PorousMediumPermeability(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -202,20 +202,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = PorousMediumPermeability.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + var expectedValue = quantity.As(PorousMediumPermeability.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = PorousMediumPermeability.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + PorousMediumPermeability quantityToConvert = quantity; + + PorousMediumPermeability convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new PorousMediumPermeability(value: 1, unit: PorousMediumPermeability.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index d6c7cd31be..335817ec18 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -264,18 +264,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new PowerDensity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (PowerDensity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new PowerDensity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new PowerDensity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -592,20 +592,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = PowerDensity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + var expectedValue = quantity.As(PowerDensity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = PowerDensity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + PowerDensity quantityToConvert = quantity; + + PowerDensity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new PowerDensity(value: 1, unit: PowerDensity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index cdca0f1a40..35fefce68a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -89,27 +89,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void PowerRatio_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -172,20 +151,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new PowerRatio(value: 1, unit: PowerRatioUnit.DecibelWatt); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new PowerRatio(value: 1, unit: PowerRatio.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new PowerRatio(value: 1, unit: PowerRatioUnit.DecibelWatt); + + PowerRatio convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(PowerRatioUnit.DecibelWatt, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new PowerRatio(value: 1, unit: PowerRatioUnit.DecibelWatt); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(PowerRatioUnit.DecibelWatt, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new PowerRatio(value: 1, unit: PowerRatioUnit.DecibelWatt); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(PowerRatioUnit.DecibelWatt, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new PowerRatio(value: 1, unit: PowerRatio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PowerRatio(value: 1, unit: PowerRatio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PowerRatio(value: 1, unit: PowerRatio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index 75500d845a..134ea0d6a5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -196,18 +196,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Power(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Power) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Power(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Power(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -422,20 +422,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Power.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Power(value: 1, unit: Power.BaseUnit); + var expectedValue = quantity.As(Power.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Power(value: 1, unit: Power.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Power(value: 1, unit: Power.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Power(value: 1, unit: Power.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Power.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Power quantityToConvert = quantity; + + Power convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Power(value: 1, unit: Power.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Power(value: 1, unit: Power.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Power(value: 1, unit: Power.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Power(value: 1, unit: Power.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Power(value: 1, unit: Power.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Power(value: 1, unit: Power.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index 40edfceb18..4e153fa08c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -160,18 +160,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new PressureChangeRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (PressureChangeRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new PressureChangeRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new PressureChangeRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -332,20 +332,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = PressureChangeRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + var expectedValue = quantity.As(PressureChangeRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = PressureChangeRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + PressureChangeRate quantityToConvert = quantity; + + PressureChangeRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new PressureChangeRate(value: 1, unit: PressureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index 82348adb87..e2d0aa3289 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -284,18 +284,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Pressure(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Pressure) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Pressure(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Pressure(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -642,20 +642,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Pressure.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + var expectedValue = quantity.As(Pressure.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Pressure.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Pressure quantityToConvert = quantity; + + Pressure convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Pressure(value: 1, unit: Pressure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs index ef79b641a7..08ca343322 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseRateTestsBase.g.cs @@ -128,18 +128,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RadiationEquivalentDoseRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RadiationEquivalentDoseRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RadiationEquivalentDoseRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RadiationEquivalentDoseRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -252,20 +252,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RadiationEquivalentDoseRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + var expectedValue = quantity.As(RadiationEquivalentDoseRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RadiationEquivalentDoseRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RadiationEquivalentDoseRate quantityToConvert = quantity; + + RadiationEquivalentDoseRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDoseRate(value: 1, unit: RadiationEquivalentDoseRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs index df0f89cd39..144daed19e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RadiationEquivalentDose(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RadiationEquivalentDose) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RadiationEquivalentDose(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RadiationEquivalentDose(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RadiationEquivalentDose.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + var expectedValue = quantity.As(RadiationEquivalentDose.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RadiationEquivalentDose.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RadiationEquivalentDose quantityToConvert = quantity; + + RadiationEquivalentDose convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationEquivalentDose(value: 1, unit: RadiationEquivalentDose.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs index 968f1d04ce..b3108a9e1e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -120,18 +120,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RadiationExposure(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RadiationExposure) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RadiationExposure(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RadiationExposure(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -232,20 +232,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RadiationExposure.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + var expectedValue = quantity.As(RadiationExposure.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RadiationExposure.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RadiationExposure quantityToConvert = quantity; + + RadiationExposure convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs index ff940692d6..bdee5211d1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs @@ -204,18 +204,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Radioactivity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Radioactivity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Radioactivity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Radioactivity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -442,20 +442,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Radioactivity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + var expectedValue = quantity.As(Radioactivity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Radioactivity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Radioactivity quantityToConvert = quantity; + + Radioactivity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Radioactivity(value: 1, unit: Radioactivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index 2eac500455..4756b19f1d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -96,18 +96,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RatioChangeRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RatioChangeRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RatioChangeRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RatioChangeRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -172,20 +172,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RatioChangeRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + var expectedValue = quantity.As(RatioChangeRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RatioChangeRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RatioChangeRate quantityToConvert = quantity; + + RatioChangeRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index f25c7b5fdd..92ea840ee5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -105,27 +105,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void Ratio_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -212,20 +191,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new Ratio(value: 1, unit: RatioUnit.DecimalFraction); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new Ratio(value: 1, unit: Ratio.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new Ratio(value: 1, unit: RatioUnit.DecimalFraction); + + Ratio convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(RatioUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new Ratio(value: 1, unit: RatioUnit.DecimalFraction); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(RatioUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new Ratio(value: 1, unit: RatioUnit.DecimalFraction); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(RatioUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Ratio(value: 1, unit: Ratio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Ratio(value: 1, unit: Ratio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Ratio(value: 1, unit: Ratio.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs index 1de9ed20c4..12c066f81c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs @@ -132,18 +132,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ReciprocalArea(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ReciprocalArea) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ReciprocalArea(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ReciprocalArea(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -262,20 +262,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ReciprocalArea.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + var expectedValue = quantity.As(ReciprocalArea.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ReciprocalArea.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ReciprocalArea quantityToConvert = quantity; + + ReciprocalArea convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalArea(value: 1, unit: ReciprocalArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index f5220d7208..5a3fb5ee57 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -128,18 +128,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ReciprocalLength(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ReciprocalLength) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ReciprocalLength(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ReciprocalLength(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -252,20 +252,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ReciprocalLength.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + var expectedValue = quantity.As(ReciprocalLength.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ReciprocalLength.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ReciprocalLength quantityToConvert = quantity; + + ReciprocalLength convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ReciprocalLength(value: 1, unit: ReciprocalLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs index d306dfd73e..9bcf4ef2e7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs @@ -85,27 +85,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new RelativeHumidity(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new RelativeHumidity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RelativeHumidity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - [Fact] public void RelativeHumidity_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -162,20 +141,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new RelativeHumidity(value: 1, unit: RelativeHumidityUnit.Percent); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new RelativeHumidity(value: 1, unit: RelativeHumidity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new RelativeHumidity(value: 1, unit: RelativeHumidityUnit.Percent); + + RelativeHumidity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(RelativeHumidityUnit.Percent, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new RelativeHumidity(value: 1, unit: RelativeHumidityUnit.Percent); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(RelativeHumidityUnit.Percent, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new RelativeHumidity(value: 1, unit: RelativeHumidityUnit.Percent); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(RelativeHumidityUnit.Percent, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RelativeHumidity(value: 1, unit: RelativeHumidity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RelativeHumidity(value: 1, unit: RelativeHumidity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RelativeHumidity(value: 1, unit: RelativeHumidity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index 60ad438ef4..c9c8f051ce 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -104,18 +104,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RotationalAcceleration(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RotationalAcceleration) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RotationalAcceleration(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RotationalAcceleration(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -192,20 +192,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RotationalAcceleration.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + var expectedValue = quantity.As(RotationalAcceleration.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RotationalAcceleration.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RotationalAcceleration quantityToConvert = quantity; + + RotationalAcceleration convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalAcceleration(value: 1, unit: RotationalAcceleration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index 1710080edc..7f173f30f9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -140,18 +140,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RotationalSpeed(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RotationalSpeed) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RotationalSpeed(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RotationalSpeed(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -282,20 +282,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RotationalSpeed.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + var expectedValue = quantity.As(RotationalSpeed.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RotationalSpeed.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RotationalSpeed quantityToConvert = quantity; + + RotationalSpeed convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalSpeed(value: 1, unit: RotationalSpeed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index 1433a297d2..9975daba52 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -108,18 +108,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RotationalStiffnessPerLength(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RotationalStiffnessPerLength) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RotationalStiffnessPerLength(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RotationalStiffnessPerLength(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -202,20 +202,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RotationalStiffnessPerLength.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + var expectedValue = quantity.As(RotationalStiffnessPerLength.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RotationalStiffnessPerLength.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RotationalStiffnessPerLength quantityToConvert = quantity; + + RotationalStiffnessPerLength convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffnessPerLength(value: 1, unit: RotationalStiffnessPerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index 2b2e24433c..7bf44c4393 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -220,18 +220,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new RotationalStiffness(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (RotationalStiffness) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new RotationalStiffness(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new RotationalStiffness(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -482,20 +482,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = RotationalStiffness.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + var expectedValue = quantity.As(RotationalStiffness.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = RotationalStiffness.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + RotationalStiffness quantityToConvert = quantity; + + RotationalStiffness convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new RotationalStiffness(value: 1, unit: RotationalStiffness.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs index aacec85d32..b1e837c211 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs @@ -85,27 +85,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new Scalar(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new Scalar(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Scalar) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - [Fact] public void Scalar_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -162,20 +141,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new Scalar(value: 1, unit: ScalarUnit.Amount); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new Scalar(value: 1, unit: Scalar.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new Scalar(value: 1, unit: ScalarUnit.Amount); + + Scalar convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(ScalarUnit.Amount, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new Scalar(value: 1, unit: ScalarUnit.Amount); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(ScalarUnit.Amount, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new Scalar(value: 1, unit: ScalarUnit.Amount); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(ScalarUnit.Amount, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Scalar(value: 1, unit: Scalar.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Scalar(value: 1, unit: Scalar.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Scalar(value: 1, unit: Scalar.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index be8c8acf7e..333db9f033 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -85,27 +85,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void SolidAngle_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -162,20 +141,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new SolidAngle(value: 1, unit: SolidAngleUnit.Steradian); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new SolidAngle(value: 1, unit: SolidAngle.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new SolidAngle(value: 1, unit: SolidAngleUnit.Steradian); + + SolidAngle convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(SolidAngleUnit.Steradian, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new SolidAngle(value: 1, unit: SolidAngleUnit.Steradian); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(SolidAngleUnit.Steradian, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new SolidAngle(value: 1, unit: SolidAngleUnit.Steradian); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(SolidAngleUnit.Steradian, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new SolidAngle(value: 1, unit: SolidAngle.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SolidAngle(value: 1, unit: SolidAngle.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SolidAngle(value: 1, unit: SolidAngle.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index ce0be9b1b4..8abda52a8d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -208,18 +208,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new SpecificEnergy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (SpecificEnergy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new SpecificEnergy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new SpecificEnergy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -452,20 +452,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = SpecificEnergy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + var expectedValue = quantity.As(SpecificEnergy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = SpecificEnergy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + SpecificEnergy quantityToConvert = quantity; + + SpecificEnergy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEnergy(value: 1, unit: SpecificEnergy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index 8645e8bbe7..019da990ac 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new SpecificEntropy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (SpecificEntropy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new SpecificEntropy(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new SpecificEntropy(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = SpecificEntropy.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + var expectedValue = quantity.As(SpecificEntropy.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = SpecificEntropy.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + SpecificEntropy quantityToConvert = quantity; + + SpecificEntropy convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificEntropy(value: 1, unit: SpecificEntropy.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs index adbbe73393..07723809cf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs @@ -104,18 +104,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new SpecificFuelConsumption(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (SpecificFuelConsumption) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new SpecificFuelConsumption(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new SpecificFuelConsumption(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -192,20 +192,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = SpecificFuelConsumption.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + var expectedValue = quantity.As(SpecificFuelConsumption.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = SpecificFuelConsumption.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + SpecificFuelConsumption quantityToConvert = quantity; + + SpecificFuelConsumption convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificFuelConsumption(value: 1, unit: SpecificFuelConsumption.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 8c37cccc9b..10bbe39265 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -100,18 +100,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new SpecificVolume(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (SpecificVolume) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new SpecificVolume(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new SpecificVolume(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -182,20 +182,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = SpecificVolume.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + var expectedValue = quantity.As(SpecificVolume.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = SpecificVolume.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + SpecificVolume quantityToConvert = quantity; + + SpecificVolume convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificVolume(value: 1, unit: SpecificVolume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index bd82e77a44..75d53c9b09 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -156,18 +156,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new SpecificWeight(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (SpecificWeight) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new SpecificWeight(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new SpecificWeight(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -322,20 +322,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = SpecificWeight.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + var expectedValue = quantity.As(SpecificWeight.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = SpecificWeight.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + SpecificWeight quantityToConvert = quantity; + + SpecificWeight convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new SpecificWeight(value: 1, unit: SpecificWeight.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index ce384ff214..4dc68814e8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -220,18 +220,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Speed(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Speed) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Speed(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Speed(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -482,20 +482,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Speed.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Speed(value: 1, unit: Speed.BaseUnit); + var expectedValue = quantity.As(Speed.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Speed(value: 1, unit: Speed.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Speed(value: 1, unit: Speed.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Speed(value: 1, unit: Speed.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Speed.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Speed quantityToConvert = quantity; + + Speed convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Speed(value: 1, unit: Speed.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs index 347b547ef0..5200239e9e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new StandardVolumeFlow(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (StandardVolumeFlow) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new StandardVolumeFlow(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new StandardVolumeFlow(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = StandardVolumeFlow.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + var expectedValue = quantity.As(StandardVolumeFlow.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = StandardVolumeFlow.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + StandardVolumeFlow quantityToConvert = quantity; + + StandardVolumeFlow convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new StandardVolumeFlow(value: 1, unit: StandardVolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index 75b1712bec..f91f758f28 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -156,18 +156,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new TemperatureChangeRate(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (TemperatureChangeRate) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new TemperatureChangeRate(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new TemperatureChangeRate(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -322,20 +322,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = TemperatureChangeRate.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + var expectedValue = quantity.As(TemperatureChangeRate.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = TemperatureChangeRate.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + TemperatureChangeRate quantityToConvert = quantity; + + TemperatureChangeRate convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureChangeRate(value: 1, unit: TemperatureChangeRate.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index 6ed7cf0dd0..b18d19b48e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new TemperatureDelta(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (TemperatureDelta) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new TemperatureDelta(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new TemperatureDelta(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = TemperatureDelta.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + var expectedValue = quantity.As(TemperatureDelta.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = TemperatureDelta.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + TemperatureDelta quantityToConvert = quantity; + + TemperatureDelta convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureDelta(value: 1, unit: TemperatureDelta.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs index 187274a686..8e640f8f0b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs @@ -104,18 +104,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new TemperatureGradient(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (TemperatureGradient) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new TemperatureGradient(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new TemperatureGradient(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -192,20 +192,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = TemperatureGradient.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + var expectedValue = quantity.As(TemperatureGradient.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = TemperatureGradient.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + TemperatureGradient quantityToConvert = quantity; + + TemperatureGradient convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new TemperatureGradient(value: 1, unit: TemperatureGradient.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index 8c1e251e9a..3e408325f9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -128,18 +128,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Temperature(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Temperature) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Temperature(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Temperature(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -252,20 +252,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Temperature.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + var expectedValue = quantity.As(Temperature.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Temperature.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Temperature quantityToConvert = quantity; + + Temperature convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Temperature(value: 1, unit: Temperature.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index c45ecb15ae..8fb089a06a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -96,18 +96,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ThermalConductivity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ThermalConductivity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ThermalConductivity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ThermalConductivity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -172,20 +172,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ThermalConductivity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + var expectedValue = quantity.As(ThermalConductivity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ThermalConductivity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ThermalConductivity quantityToConvert = quantity; + + ThermalConductivity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalConductivity(value: 1, unit: ThermalConductivity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs index fa4c1998fc..1a7a46f52b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new ThermalInsulance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ThermalInsulance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new ThermalInsulance(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new ThermalInsulance(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = ThermalInsulance.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + var expectedValue = quantity.As(ThermalInsulance.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = ThermalInsulance.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + ThermalInsulance quantityToConvert = quantity; + + ThermalInsulance convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new ThermalInsulance(value: 1, unit: ThermalInsulance.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index 312827af97..4a350eb1ef 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -188,18 +188,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Torque(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Torque) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Torque(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Torque(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -402,20 +402,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Torque.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Torque(value: 1, unit: Torque.BaseUnit); + var expectedValue = quantity.As(Torque.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Torque(value: 1, unit: Torque.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Torque(value: 1, unit: Torque.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Torque(value: 1, unit: Torque.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Torque.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Torque quantityToConvert = quantity; + + Torque convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Torque(value: 1, unit: Torque.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index 1460d7c3f3..4dd519b457 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -85,27 +85,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void Turbidity_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -162,20 +141,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new Turbidity(value: 1, unit: TurbidityUnit.NTU); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new Turbidity(value: 1, unit: Turbidity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new Turbidity(value: 1, unit: TurbidityUnit.NTU); + + Turbidity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(TurbidityUnit.NTU, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new Turbidity(value: 1, unit: TurbidityUnit.NTU); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(TurbidityUnit.NTU, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new Turbidity(value: 1, unit: TurbidityUnit.NTU); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(TurbidityUnit.NTU, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Turbidity(value: 1, unit: Turbidity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Turbidity(value: 1, unit: Turbidity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Turbidity(value: 1, unit: Turbidity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index d992e2f51a..e47ac77147 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -85,27 +85,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void VitaminA_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -162,20 +141,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new VitaminA(value: 1, unit: VitaminAUnit.InternationalUnit); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new VitaminA(value: 1, unit: VitaminA.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new VitaminA(value: 1, unit: VitaminAUnit.InternationalUnit); + + VitaminA convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(VitaminAUnit.InternationalUnit, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new VitaminA(value: 1, unit: VitaminAUnit.InternationalUnit); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(VitaminAUnit.InternationalUnit, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new VitaminA(value: 1, unit: VitaminAUnit.InternationalUnit); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(VitaminAUnit.InternationalUnit, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new VitaminA(value: 1, unit: VitaminA.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VitaminA(value: 1, unit: VitaminA.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VitaminA(value: 1, unit: VitaminA.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index 0015b963db..c17e4e3f90 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -161,27 +161,6 @@ public void Ctor_WithNaNValue_DoNotThrowsArgumentException() Assert.Null(exception); } - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - 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] public void VolumeConcentration_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { @@ -352,20 +331,70 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public void As_UnitSystem_ReturnsValueInDimensionlessUnit() + { + var quantity = new VolumeConcentration(value: 1, unit: VolumeConcentrationUnit.DecimalFraction); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(quantity.Value, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() { var quantity = new VolumeConcentration(value: 1, unit: VolumeConcentration.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } - if (SupportsSIUnitSystem) + [Fact] + public void ToUnitSystem_ReturnsValueInDimensionlessUnit() + { + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + var quantity = new VolumeConcentration(value: 1, unit: VolumeConcentrationUnit.DecimalFraction); + + VolumeConcentration convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(VolumeConcentrationUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantity = new VolumeConcentration(value: 1, unit: VolumeConcentrationUnit.DecimalFraction); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(VolumeConcentrationUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }, () => + { + IQuantity quantity = new VolumeConcentration(value: 1, unit: VolumeConcentrationUnit.DecimalFraction); + + IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI); + + Assert.Equal(VolumeConcentrationUnit.DecimalFraction, convertedQuantity.Unit); + Assert.Equal(quantity.Value, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new VolumeConcentration(value: 1, unit: VolumeConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeConcentration(value: 1, unit: VolumeConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeConcentration(value: 1, unit: VolumeConcentration.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs index 7a6adac84e..58d023b5ae 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs @@ -96,18 +96,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new VolumeFlowPerArea(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (VolumeFlowPerArea) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new VolumeFlowPerArea(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new VolumeFlowPerArea(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -172,20 +172,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = VolumeFlowPerArea.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + var expectedValue = quantity.As(VolumeFlowPerArea.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = VolumeFlowPerArea.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + VolumeFlowPerArea quantityToConvert = quantity; + + VolumeFlowPerArea convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlowPerArea(value: 1, unit: VolumeFlowPerArea.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index 1e58d5346e..fcb28b7025 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -388,18 +388,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new VolumeFlow(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (VolumeFlow) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new VolumeFlow(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new VolumeFlow(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -902,20 +902,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = VolumeFlow.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + var expectedValue = quantity.As(VolumeFlow.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = VolumeFlow.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + VolumeFlow quantityToConvert = quantity; + + VolumeFlow convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumeFlow(value: 1, unit: VolumeFlow.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index 239290e423..ace8967bba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new VolumePerLength(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (VolumePerLength) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new VolumePerLength(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new VolumePerLength(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = VolumePerLength.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + var expectedValue = quantity.As(VolumePerLength.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = VolumePerLength.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + VolumePerLength quantityToConvert = quantity; + + VolumePerLength convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumePerLength(value: 1, unit: VolumePerLength.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index 893e8fe457..9796f56b63 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -304,18 +304,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new Volume(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Volume) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new Volume(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new Volume(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -692,20 +692,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = Volume.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new Volume(value: 1, unit: Volume.BaseUnit); + var expectedValue = quantity.As(Volume.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new Volume(value: 1, unit: Volume.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Volume(value: 1, unit: Volume.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new Volume(value: 1, unit: Volume.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = Volume.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + Volume quantityToConvert = quantity; + + Volume convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new Volume(value: 1, unit: Volume.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs index 4931eef98f..b5a3618a11 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs @@ -124,18 +124,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new VolumetricHeatCapacity(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (VolumetricHeatCapacity) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new VolumetricHeatCapacity(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new VolumetricHeatCapacity(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -242,20 +242,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = VolumetricHeatCapacity.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + var expectedValue = quantity.As(VolumetricHeatCapacity.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = VolumetricHeatCapacity.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + VolumetricHeatCapacity quantityToConvert = quantity; + + VolumetricHeatCapacity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new VolumetricHeatCapacity(value: 1, unit: VolumetricHeatCapacity.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index 369bf729ee..4e1617327f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -112,18 +112,18 @@ public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() } [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits() { - Func TestCode = () => new WarpingMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (WarpingMomentOfInertia) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } + var quantity = new WarpingMomentOfInertia(value: 1, unitSystem: UnitSystem.SI); + Assert.Equal(1, quantity.Value); + Assert.True(quantity.QuantityInfo.UnitInfos.First(x => x.Value == quantity.Unit).BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public void Ctor_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => new WarpingMomentOfInertia(value: 1, unitSystem: unsupportedUnitSystem)); } [Fact] @@ -212,20 +212,109 @@ public void As() } [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + public virtual void BaseUnit_HasSIBase() + { + var baseUnitInfo = WarpingMomentOfInertia.Info.BaseUnitInfo; + Assert.True(baseUnitInfo.BaseUnits.IsSubsetOf(UnitSystem.SI.BaseUnits)); + } + + [Fact] + public virtual void As_UnitSystem_SI_ReturnsQuantityInSIUnits() + { + var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + var expectedValue = quantity.As(WarpingMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI)); + + var convertedValue = quantity.As(UnitSystem.SI); + + Assert.Equal(expectedValue, convertedValue); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + UnitSystem nullUnitSystem = null!; + Assert.Throws(() => quantity.As(nullUnitSystem)); + } + + [Fact] + public void As_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Throws(() => quantity.As(unsupportedUnitSystem)); + } + + [Fact] + public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits() { var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + var expectedUnit = WarpingMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI); + var expectedValue = quantity.As(expectedUnit); - if (SupportsSIUnitSystem) + Assert.Multiple(() => { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else + WarpingMomentOfInertia quantityToConvert = quantity; + + WarpingMomentOfInertia convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => { - Assert.Throws(AsWithSIUnitSystem); - } + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }, () => + { + IQuantity quantityToConvert = quantity; + + IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI); + + Assert.Equal(expectedUnit, convertedQuantity.Unit); + Assert.Equal(expectedValue, convertedQuantity.Value); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull() + { + UnitSystem nullUnitSystem = null!; + Assert.Multiple(() => + { + var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }, () => + { + IQuantity quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(nullUnitSystem)); + }); + } + + [Fact] + public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits); + Assert.Multiple(() => + { + var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }, () => + { + IQuantity quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); + Assert.Throws(() => quantity.ToUnit(unsupportedUnitSystem)); + }); } [Fact] diff --git a/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs b/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs new file mode 100644 index 0000000000..06b09a5878 --- /dev/null +++ b/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace UnitsNet; + +/// +/// Provides extension methods for filtering and retrieving unit information based on base units. +/// +internal static class QuantityInfoExtensions +{ + /// + /// Retrieves the default unit for a specified quantity and unit system. + /// + /// The type of the unit, which is a value type and an enumeration. + /// + /// The instance containing information about the + /// quantity. + /// + /// The for which the default unit is to be retrieved. + /// The default unit of type for the specified quantity and unit system. + /// Thrown when is null. + /// Thrown when no units are found for the given . + /// + /// Length.Info.GetDefaultUnit(UnitSystem.SI) + /// + internal static TUnit GetDefaultUnit(this QuantityInfo quantityInfo, UnitSystem unitSystem) + where TUnit : struct, Enum + { + if (unitSystem is null) + { + throw new ArgumentNullException(nameof(unitSystem)); + } + + if (quantityInfo.BaseDimensions.IsDimensionless()) + { + return quantityInfo.BaseUnitInfo.Value; + } + + IEnumerable> unitInfos = quantityInfo.GetUnitInfosFor(unitSystem.BaseUnits); + + UnitInfo? firstUnitInfo = unitInfos.FirstOrDefault(); + if (firstUnitInfo == null) + { + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + return firstUnitInfo.Value; + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs b/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs index 8e746cda2b..dab2e7311f 100644 --- a/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs @@ -120,13 +120,8 @@ public AbsorbedDoseOfIonizingRadiation(double value, AbsorbedDoseOfIonizingRadia /// No unit was found for the given . public AbsorbedDoseOfIonizingRadiation(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -880,25 +875,7 @@ public double As(AbsorbedDoseOfIonizingRadiationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AbsorbedDoseOfIonizingRadiationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AbsorbedDoseOfIonizingRadiationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1005,28 +982,29 @@ private bool TryToUnit(AbsorbedDoseOfIonizingRadiationUnit unit, [NotNullWhen(tr return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public AbsorbedDoseOfIonizingRadiation ToUnit(UnitSystem unitSystem) { - if (!(unit is AbsorbedDoseOfIonizingRadiationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AbsorbedDoseOfIonizingRadiationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public AbsorbedDoseOfIonizingRadiation ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AbsorbedDoseOfIonizingRadiationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AbsorbedDoseOfIonizingRadiationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AbsorbedDoseOfIonizingRadiationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AbsorbedDoseOfIonizingRadiationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1040,6 +1018,8 @@ public AbsorbedDoseOfIonizingRadiation ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 356a23ab7d..95d11a0367 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -122,13 +122,8 @@ public Acceleration(double value, AccelerationUnit unit) /// No unit was found for the given . public Acceleration(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -886,25 +881,7 @@ public double As(AccelerationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AccelerationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AccelerationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1007,28 +984,29 @@ private bool TryToUnit(AccelerationUnit unit, [NotNullWhen(true)] out Accelerati return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Acceleration ToUnit(UnitSystem unitSystem) { - if (!(unit is AccelerationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AccelerationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Acceleration ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AccelerationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AccelerationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AccelerationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AccelerationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1042,6 +1020,8 @@ public Acceleration ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs index 85d97c6004..397deaaa79 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs @@ -126,13 +126,8 @@ public AmountOfSubstance(double value, AmountOfSubstanceUnit unit) /// No unit was found for the given . public AmountOfSubstance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -941,25 +936,7 @@ public double As(AmountOfSubstanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AmountOfSubstanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmountOfSubstanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1068,28 +1045,29 @@ private bool TryToUnit(AmountOfSubstanceUnit unit, [NotNullWhen(true)] out Amoun return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public AmountOfSubstance ToUnit(UnitSystem unitSystem) { - if (!(unit is AmountOfSubstanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmountOfSubstanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public AmountOfSubstance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AmountOfSubstanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmountOfSubstanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AmountOfSubstanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmountOfSubstanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1103,6 +1081,8 @@ public AmountOfSubstance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs index 32b3a51bd1..824ccb8c40 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs @@ -95,25 +95,6 @@ public AmplitudeRatio(double value, AmplitudeRatioUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public AmplitudeRatio(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -693,25 +674,7 @@ public double As(AmplitudeRatioUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AmplitudeRatioUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmplitudeRatioUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -794,28 +757,29 @@ private bool TryToUnit(AmplitudeRatioUnit unit, [NotNullWhen(true)] out Amplitud return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public AmplitudeRatio ToUnit(UnitSystem unitSystem) { - if (!(unit is AmplitudeRatioUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmplitudeRatioUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public AmplitudeRatio ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AmplitudeRatioUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmplitudeRatioUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AmplitudeRatioUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmplitudeRatioUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -829,6 +793,8 @@ public AmplitudeRatio ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index 558cd76621..20072f8797 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -111,25 +111,6 @@ public Angle(double value, AngleUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public Angle(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -888,25 +869,7 @@ public double As(AngleUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AngleUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AngleUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1011,28 +974,29 @@ private bool TryToUnit(AngleUnit unit, [NotNullWhen(true)] out Angle? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Angle ToUnit(UnitSystem unitSystem) { - if (!(unit is AngleUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AngleUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Angle ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AngleUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AngleUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AngleUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AngleUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1046,6 +1010,8 @@ public Angle ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index d616dd4398..8fa6f89213 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -133,13 +133,8 @@ public Area(double value, AreaUnit unit) /// No unit was found for the given . public Area(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -970,25 +965,7 @@ public double As(AreaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AreaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1091,28 +1068,29 @@ private bool TryToUnit(AreaUnit unit, [NotNullWhen(true)] out Area? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Area ToUnit(UnitSystem unitSystem) { - if (!(unit is AreaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Area ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AreaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AreaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1126,6 +1104,8 @@ public Area ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs index a489866de2..0092dc509e 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs @@ -107,13 +107,8 @@ public AreaDensity(double value, AreaDensityUnit unit) /// No unit was found for the given . public AreaDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -682,25 +677,7 @@ public double As(AreaDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AreaDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -781,28 +758,29 @@ private bool TryToUnit(AreaDensityUnit unit, [NotNullWhen(true)] out AreaDensity return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public AreaDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is AreaDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public AreaDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AreaDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AreaDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -816,6 +794,8 @@ public AreaDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs index d9bee52bfd..73682d30b4 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs @@ -111,13 +111,8 @@ public AreaMomentOfInertia(double value, AreaMomentOfInertiaUnit unit) /// No unit was found for the given . public AreaMomentOfInertia(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -737,25 +732,7 @@ public double As(AreaMomentOfInertiaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is AreaMomentOfInertiaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaMomentOfInertiaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -842,28 +819,29 @@ private bool TryToUnit(AreaMomentOfInertiaUnit unit, [NotNullWhen(true)] out Are return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public AreaMomentOfInertia ToUnit(UnitSystem unitSystem) { - if (!(unit is AreaMomentOfInertiaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaMomentOfInertiaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public AreaMomentOfInertia ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not AreaMomentOfInertiaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaMomentOfInertiaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is AreaMomentOfInertiaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaMomentOfInertiaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -877,6 +855,8 @@ public AreaMomentOfInertia ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs index dbc08ae296..8fc235a9ee 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs @@ -76,7 +76,7 @@ static BitRate() Info = new QuantityInfo("BitRate", new UnitInfo[] { - new UnitInfo(BitRateUnit.BitPerSecond, "BitsPerSecond", BaseUnits.Undefined, "BitRate"), + new UnitInfo(BitRateUnit.BitPerSecond, "BitsPerSecond", new BaseUnits(time: DurationUnit.Second), "BitRate"), new UnitInfo(BitRateUnit.BytePerSecond, "BytesPerSecond", BaseUnits.Undefined, "BitRate"), new UnitInfo(BitRateUnit.ExabitPerSecond, "ExabitsPerSecond", BaseUnits.Undefined, "BitRate"), new UnitInfo(BitRateUnit.ExabytePerSecond, "ExabytesPerSecond", BaseUnits.Undefined, "BitRate"), @@ -130,13 +130,8 @@ public BitRate(double value, BitRateUnit unit) /// No unit was found for the given . public BitRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1040,25 +1035,7 @@ public double As(BitRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is BitRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BitRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1185,28 +1162,29 @@ private bool TryToUnit(BitRateUnit unit, [NotNullWhen(true)] out BitRate? conver return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public BitRate ToUnit(UnitSystem unitSystem) { - if (!(unit is BitRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BitRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public BitRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not BitRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BitRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is BitRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BitRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1220,6 +1198,8 @@ public BitRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs index 24e3369175..4753f34f13 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs @@ -78,7 +78,7 @@ static BrakeSpecificFuelConsumption() new UnitInfo[] { new UnitInfo(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, "GramsPerKiloWattHour", BaseUnits.Undefined, "BrakeSpecificFuelConsumption"), - new UnitInfo(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, "KilogramsPerJoule", BaseUnits.Undefined, "BrakeSpecificFuelConsumption"), + new UnitInfo(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, "KilogramsPerJoule", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "BrakeSpecificFuelConsumption"), new UnitInfo(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, "PoundsPerMechanicalHorsepowerHour", BaseUnits.Undefined, "BrakeSpecificFuelConsumption"), }, BaseUnit, Zero, BaseDimensions); @@ -108,13 +108,8 @@ public BrakeSpecificFuelConsumption(double value, BrakeSpecificFuelConsumptionUn /// No unit was found for the given . public BrakeSpecificFuelConsumption(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -695,25 +690,7 @@ public double As(BrakeSpecificFuelConsumptionUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is BrakeSpecificFuelConsumptionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BrakeSpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -794,28 +771,29 @@ private bool TryToUnit(BrakeSpecificFuelConsumptionUnit unit, [NotNullWhen(true) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public BrakeSpecificFuelConsumption ToUnit(UnitSystem unitSystem) { - if (!(unit is BrakeSpecificFuelConsumptionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BrakeSpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public BrakeSpecificFuelConsumption ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not BrakeSpecificFuelConsumptionUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BrakeSpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is BrakeSpecificFuelConsumptionUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BrakeSpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -829,6 +807,8 @@ public BrakeSpecificFuelConsumption ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs index 5587f38ecc..ac827c70b0 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs @@ -79,9 +79,9 @@ static CoefficientOfThermalExpansion() new UnitInfo(CoefficientOfThermalExpansionUnit.PerDegreeCelsius, "PerDegreeCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius), "CoefficientOfThermalExpansion"), new UnitInfo(CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, "PerDegreeFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit), "CoefficientOfThermalExpansion"), new UnitInfo(CoefficientOfThermalExpansionUnit.PerKelvin, "PerKelvin", new BaseUnits(temperature: TemperatureUnit.Kelvin), "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, "PpmPerDegreeCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius), "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, "PpmPerDegreeFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit), "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerKelvin, "PpmPerKelvin", new BaseUnits(temperature: TemperatureUnit.Kelvin), "CoefficientOfThermalExpansion"), + new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, "PpmPerDegreeCelsius", BaseUnits.Undefined, "CoefficientOfThermalExpansion"), + new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, "PpmPerDegreeFahrenheit", BaseUnits.Undefined, "CoefficientOfThermalExpansion"), + new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerKelvin, "PpmPerKelvin", BaseUnits.Undefined, "CoefficientOfThermalExpansion"), }, BaseUnit, Zero, BaseDimensions); @@ -110,13 +110,8 @@ public CoefficientOfThermalExpansion(double value, CoefficientOfThermalExpansion /// No unit was found for the given . public CoefficientOfThermalExpansion(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -730,25 +725,7 @@ public double As(CoefficientOfThermalExpansionUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is CoefficientOfThermalExpansionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CoefficientOfThermalExpansionUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -835,28 +812,29 @@ private bool TryToUnit(CoefficientOfThermalExpansionUnit unit, [NotNullWhen(true return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public CoefficientOfThermalExpansion ToUnit(UnitSystem unitSystem) { - if (!(unit is CoefficientOfThermalExpansionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CoefficientOfThermalExpansionUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public CoefficientOfThermalExpansion ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not CoefficientOfThermalExpansionUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CoefficientOfThermalExpansionUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is CoefficientOfThermalExpansionUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CoefficientOfThermalExpansionUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -870,6 +848,8 @@ public CoefficientOfThermalExpansion ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs index a95f9331df..4c83b57d46 100644 --- a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs @@ -108,13 +108,8 @@ public Compressibility(double value, CompressibilityUnit unit) /// No unit was found for the given . public Compressibility(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -733,25 +728,7 @@ public double As(CompressibilityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is CompressibilityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CompressibilityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -840,28 +817,29 @@ private bool TryToUnit(CompressibilityUnit unit, [NotNullWhen(true)] out Compres return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Compressibility ToUnit(UnitSystem unitSystem) { - if (!(unit is CompressibilityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CompressibilityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Compressibility ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not CompressibilityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CompressibilityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is CompressibilityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CompressibilityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -875,6 +853,8 @@ public Compressibility ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs index db5e0f8a91..cb0a35ea54 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs @@ -100,8 +100,8 @@ static Density() new UnitInfo(DensityUnit.GramPerCubicMeter, "GramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "Density"), new UnitInfo(DensityUnit.GramPerCubicMillimeter, "GramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "Density"), new UnitInfo(DensityUnit.GramPerDeciliter, "GramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.GramPerLiter, "GramsPerLiter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.GramPerMilliliter, "GramsPerMilliliter", BaseUnits.Undefined, "Density"), + new UnitInfo(DensityUnit.GramPerLiter, "GramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram), "Density"), + new UnitInfo(DensityUnit.GramPerMilliliter, "GramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "Density"), new UnitInfo(DensityUnit.KilogramPerCubicCentimeter, "KilogramsPerCubicCentimeter", BaseUnits.Undefined, "Density"), new UnitInfo(DensityUnit.KilogramPerCubicMeter, "KilogramsPerCubicMeter", BaseUnits.Undefined, "Density"), new UnitInfo(DensityUnit.KilogramPerCubicMillimeter, "KilogramsPerCubicMillimeter", BaseUnits.Undefined, "Density"), @@ -169,13 +169,8 @@ public Density(double value, DensityUnit unit) /// No unit was found for the given . public Density(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1582,25 +1577,7 @@ public double As(DensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is DensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1787,28 +1764,29 @@ private bool TryToUnit(DensityUnit unit, [NotNullWhen(true)] out Density? conver return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Density ToUnit(UnitSystem unitSystem) { - if (!(unit is DensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Density ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not DensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is DensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1822,6 +1800,8 @@ public Density ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs b/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs index 4ce77bdf11..abeb8f0ed7 100644 --- a/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs @@ -124,13 +124,8 @@ public DoseAreaProduct(double value, DoseAreaProductUnit unit) /// No unit was found for the given . public DoseAreaProduct(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -944,25 +939,7 @@ public double As(DoseAreaProductUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is DoseAreaProductUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DoseAreaProductUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1077,28 +1054,29 @@ private bool TryToUnit(DoseAreaProductUnit unit, [NotNullWhen(true)] out DoseAre return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public DoseAreaProduct ToUnit(UnitSystem unitSystem) { - if (!(unit is DoseAreaProductUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DoseAreaProductUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public DoseAreaProduct ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not DoseAreaProductUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DoseAreaProductUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is DoseAreaProductUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DoseAreaProductUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1112,6 +1090,8 @@ public DoseAreaProduct ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs index 611bafd512..7294093924 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs @@ -130,13 +130,8 @@ public Duration(double value, DurationUnit unit) /// No unit was found for the given . public Duration(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -924,25 +919,7 @@ public double As(DurationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is DurationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DurationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1041,28 +1018,29 @@ private bool TryToUnit(DurationUnit unit, [NotNullWhen(true)] out Duration? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Duration ToUnit(UnitSystem unitSystem) { - if (!(unit is DurationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DurationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Duration ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not DurationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DurationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is DurationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DurationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1076,6 +1054,8 @@ public Duration ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs index cf600b9aef..01c6a6de14 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs @@ -83,7 +83,7 @@ static DynamicViscosity() new UnitInfo(DynamicViscosityUnit.Centipoise, "Centipoise", BaseUnits.Undefined, "DynamicViscosity"), new UnitInfo(DynamicViscosityUnit.MicropascalSecond, "MicropascalSeconds", BaseUnits.Undefined, "DynamicViscosity"), new UnitInfo(DynamicViscosityUnit.MillipascalSecond, "MillipascalSeconds", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.NewtonSecondPerMeterSquared, "NewtonSecondsPerMeterSquared", BaseUnits.Undefined, "DynamicViscosity"), + new UnitInfo(DynamicViscosityUnit.NewtonSecondPerMeterSquared, "NewtonSecondsPerMeterSquared", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "DynamicViscosity"), new UnitInfo(DynamicViscosityUnit.PascalSecond, "PascalSeconds", BaseUnits.Undefined, "DynamicViscosity"), new UnitInfo(DynamicViscosityUnit.Poise, "Poise", BaseUnits.Undefined, "DynamicViscosity"), new UnitInfo(DynamicViscosityUnit.PoundForceSecondPerSquareFoot, "PoundsForceSecondPerSquareFoot", BaseUnits.Undefined, "DynamicViscosity"), @@ -118,13 +118,8 @@ public DynamicViscosity(double value, DynamicViscosityUnit unit) /// No unit was found for the given . public DynamicViscosity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -804,25 +799,7 @@ public double As(DynamicViscosityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is DynamicViscosityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DynamicViscosityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -917,28 +894,29 @@ private bool TryToUnit(DynamicViscosityUnit unit, [NotNullWhen(true)] out Dynami return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public DynamicViscosity ToUnit(UnitSystem unitSystem) { - if (!(unit is DynamicViscosityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DynamicViscosityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public DynamicViscosity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not DynamicViscosityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DynamicViscosityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is DynamicViscosityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DynamicViscosityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -952,6 +930,8 @@ public DynamicViscosity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs index 57e8e9ea5d..2123352cc3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -90,7 +90,7 @@ static ElectricAdmittance() new UnitInfo(ElectricAdmittanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Nanosiemens, "Nanosiemens", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Siemens, "Siemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Siemens, "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Terasiemens, "Terasiemens", BaseUnits.Undefined, "ElectricAdmittance"), }, @@ -121,13 +121,8 @@ public ElectricAdmittance(double value, ElectricAdmittanceUnit unit) /// No unit was found for the given . public ElectricAdmittance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -881,25 +876,7 @@ public double As(ElectricAdmittanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricAdmittanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricAdmittanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1006,28 +983,29 @@ private bool TryToUnit(ElectricAdmittanceUnit unit, [NotNullWhen(true)] out Elec return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricAdmittance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricAdmittanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricAdmittanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricAdmittance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricAdmittanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricAdmittanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricAdmittanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricAdmittanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1041,6 +1019,8 @@ public ElectricAdmittance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs index b63d3e2046..9145550d66 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs @@ -104,13 +104,8 @@ public ElectricApparentEnergy(double value, ElectricApparentEnergyUnit unit) /// No unit was found for the given . public ElectricApparentEnergy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -669,25 +664,7 @@ public double As(ElectricApparentEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricApparentEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentEnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -768,28 +745,29 @@ private bool TryToUnit(ElectricApparentEnergyUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricApparentEnergy ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricApparentEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentEnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricApparentEnergy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricApparentEnergyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentEnergyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricApparentEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentEnergyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -803,6 +781,8 @@ public ElectricApparentEnergy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs index 0cd1ef3123..3279c88039 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs @@ -81,7 +81,7 @@ static ElectricApparentPower() new UnitInfo(ElectricApparentPowerUnit.Megavoltampere, "Megavoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), new UnitInfo(ElectricApparentPowerUnit.Microvoltampere, "Microvoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), new UnitInfo(ElectricApparentPowerUnit.Millivoltampere, "Millivoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), - new UnitInfo(ElectricApparentPowerUnit.Voltampere, "Voltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + new UnitInfo(ElectricApparentPowerUnit.Voltampere, "Voltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ElectricApparentPower"), }, BaseUnit, Zero, BaseDimensions); @@ -110,13 +110,8 @@ public ElectricApparentPower(double value, ElectricApparentPowerUnit unit) /// No unit was found for the given . public ElectricApparentPower(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -720,25 +715,7 @@ public double As(ElectricApparentPowerUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricApparentPowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentPowerUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -825,28 +802,29 @@ private bool TryToUnit(ElectricApparentPowerUnit unit, [NotNullWhen(true)] out E return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricApparentPower ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricApparentPowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentPowerUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricApparentPower ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricApparentPowerUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentPowerUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricApparentPowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentPowerUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -860,6 +838,8 @@ public ElectricApparentPower ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs index 5f6689a432..fa52acf1dd 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs @@ -111,13 +111,8 @@ public ElectricCapacitance(double value, ElectricCapacitanceUnit unit) /// No unit was found for the given . public ElectricCapacitance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -736,25 +731,7 @@ public double As(ElectricCapacitanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricCapacitanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCapacitanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -843,28 +820,29 @@ private bool TryToUnit(ElectricCapacitanceUnit unit, [NotNullWhen(true)] out Ele return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricCapacitance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricCapacitanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCapacitanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricCapacitance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricCapacitanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCapacitanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricCapacitanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCapacitanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -878,6 +856,8 @@ public ElectricCapacitance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs index 5378127cd9..0b60cac8bf 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -81,8 +81,8 @@ static ElectricCharge() Info = new QuantityInfo("ElectricCharge", new UnitInfo[] { - new UnitInfo(ElectricChargeUnit.AmpereHour, "AmpereHours", BaseUnits.Undefined, "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Coulomb, "Coulombs", BaseUnits.Undefined, "ElectricCharge"), + new UnitInfo(ElectricChargeUnit.AmpereHour, "AmpereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere), "ElectricCharge"), + new UnitInfo(ElectricChargeUnit.Coulomb, "Coulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCharge"), new UnitInfo(ElectricChargeUnit.KiloampereHour, "KiloampereHours", BaseUnits.Undefined, "ElectricCharge"), new UnitInfo(ElectricChargeUnit.Kilocoulomb, "Kilocoulombs", BaseUnits.Undefined, "ElectricCharge"), new UnitInfo(ElectricChargeUnit.MegaampereHour, "MegaampereHours", BaseUnits.Undefined, "ElectricCharge"), @@ -120,13 +120,8 @@ public ElectricCharge(double value, ElectricChargeUnit unit) /// No unit was found for the given . public ElectricCharge(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -827,25 +822,7 @@ public double As(ElectricChargeUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricChargeUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -906,25 +883,25 @@ private bool TryToUnit(ElectricChargeUnit unit, [NotNullWhen(true)] out Electric ElectricCharge? convertedOrNull = (Unit, unit) switch { // ElectricChargeUnit -> BaseUnit - (ElectricChargeUnit.AmpereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge(_value / 2.77777777777e-4, ElectricChargeUnit.Coulomb), - (ElectricChargeUnit.KiloampereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value / 2.77777777777e-4) * 1e3d, ElectricChargeUnit.Coulomb), + (ElectricChargeUnit.AmpereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge(_value * 3600, ElectricChargeUnit.Coulomb), + (ElectricChargeUnit.KiloampereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value * 3600) * 1e3d, ElectricChargeUnit.Coulomb), (ElectricChargeUnit.Kilocoulomb, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value) * 1e3d, ElectricChargeUnit.Coulomb), - (ElectricChargeUnit.MegaampereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value / 2.77777777777e-4) * 1e6d, ElectricChargeUnit.Coulomb), + (ElectricChargeUnit.MegaampereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value * 3600) * 1e6d, ElectricChargeUnit.Coulomb), (ElectricChargeUnit.Megacoulomb, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value) * 1e6d, ElectricChargeUnit.Coulomb), (ElectricChargeUnit.Microcoulomb, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value) * 1e-6d, ElectricChargeUnit.Coulomb), - (ElectricChargeUnit.MilliampereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value / 2.77777777777e-4) * 1e-3d, ElectricChargeUnit.Coulomb), + (ElectricChargeUnit.MilliampereHour, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value * 3600) * 1e-3d, ElectricChargeUnit.Coulomb), (ElectricChargeUnit.Millicoulomb, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value) * 1e-3d, ElectricChargeUnit.Coulomb), (ElectricChargeUnit.Nanocoulomb, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value) * 1e-9d, ElectricChargeUnit.Coulomb), (ElectricChargeUnit.Picocoulomb, ElectricChargeUnit.Coulomb) => new ElectricCharge((_value) * 1e-12d, ElectricChargeUnit.Coulomb), // BaseUnit -> ElectricChargeUnit - (ElectricChargeUnit.Coulomb, ElectricChargeUnit.AmpereHour) => new ElectricCharge(_value * 2.77777777777e-4, ElectricChargeUnit.AmpereHour), - (ElectricChargeUnit.Coulomb, ElectricChargeUnit.KiloampereHour) => new ElectricCharge((_value * 2.77777777777e-4) / 1e3d, ElectricChargeUnit.KiloampereHour), + (ElectricChargeUnit.Coulomb, ElectricChargeUnit.AmpereHour) => new ElectricCharge(_value / 3600, ElectricChargeUnit.AmpereHour), + (ElectricChargeUnit.Coulomb, ElectricChargeUnit.KiloampereHour) => new ElectricCharge((_value / 3600) / 1e3d, ElectricChargeUnit.KiloampereHour), (ElectricChargeUnit.Coulomb, ElectricChargeUnit.Kilocoulomb) => new ElectricCharge((_value) / 1e3d, ElectricChargeUnit.Kilocoulomb), - (ElectricChargeUnit.Coulomb, ElectricChargeUnit.MegaampereHour) => new ElectricCharge((_value * 2.77777777777e-4) / 1e6d, ElectricChargeUnit.MegaampereHour), + (ElectricChargeUnit.Coulomb, ElectricChargeUnit.MegaampereHour) => new ElectricCharge((_value / 3600) / 1e6d, ElectricChargeUnit.MegaampereHour), (ElectricChargeUnit.Coulomb, ElectricChargeUnit.Megacoulomb) => new ElectricCharge((_value) / 1e6d, ElectricChargeUnit.Megacoulomb), (ElectricChargeUnit.Coulomb, ElectricChargeUnit.Microcoulomb) => new ElectricCharge((_value) / 1e-6d, ElectricChargeUnit.Microcoulomb), - (ElectricChargeUnit.Coulomb, ElectricChargeUnit.MilliampereHour) => new ElectricCharge((_value * 2.77777777777e-4) / 1e-3d, ElectricChargeUnit.MilliampereHour), + (ElectricChargeUnit.Coulomb, ElectricChargeUnit.MilliampereHour) => new ElectricCharge((_value / 3600) / 1e-3d, ElectricChargeUnit.MilliampereHour), (ElectricChargeUnit.Coulomb, ElectricChargeUnit.Millicoulomb) => new ElectricCharge((_value) / 1e-3d, ElectricChargeUnit.Millicoulomb), (ElectricChargeUnit.Coulomb, ElectricChargeUnit.Nanocoulomb) => new ElectricCharge((_value) / 1e-9d, ElectricChargeUnit.Nanocoulomb), (ElectricChargeUnit.Coulomb, ElectricChargeUnit.Picocoulomb) => new ElectricCharge((_value) / 1e-12d, ElectricChargeUnit.Picocoulomb), @@ -942,28 +919,29 @@ private bool TryToUnit(ElectricChargeUnit unit, [NotNullWhen(true)] out Electric return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricCharge ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricChargeUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricCharge ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricChargeUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricChargeUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -977,6 +955,8 @@ public ElectricCharge ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs index 4289cc3b3d..b80f4482d0 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs @@ -105,13 +105,8 @@ public ElectricChargeDensity(double value, ElectricChargeDensityUnit unit) /// No unit was found for the given . public ElectricChargeDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -640,25 +635,7 @@ public double As(ElectricChargeDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricChargeDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +712,29 @@ private bool TryToUnit(ElectricChargeDensityUnit unit, [NotNullWhen(true)] out E return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricChargeDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricChargeDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricChargeDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricChargeDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricChargeDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +748,8 @@ public ElectricChargeDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs index 6cd5447c77..193bc8edb2 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -89,7 +89,7 @@ static ElectricConductance() new UnitInfo(ElectricConductanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Nanosiemens, "Nanosiemens", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Siemens, "Siemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Siemens, "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Terasiemens, "Terasiemens", BaseUnits.Undefined, "ElectricConductance"), }, @@ -120,13 +120,8 @@ public ElectricConductance(double value, ElectricConductanceUnit unit) /// No unit was found for the given . public ElectricConductance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -880,25 +875,7 @@ public double As(ElectricConductanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricConductanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1005,28 +982,29 @@ private bool TryToUnit(ElectricConductanceUnit unit, [NotNullWhen(true)] out Ele return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricConductance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricConductanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricConductance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricConductanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricConductanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1040,6 +1018,8 @@ public ElectricConductance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs index 3e64316c3d..f2b4c53439 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs @@ -110,13 +110,8 @@ public ElectricConductivity(double value, ElectricConductivityUnit unit) /// No unit was found for the given . public ElectricConductivity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -731,25 +726,7 @@ public double As(ElectricConductivityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricConductivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductivityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -836,28 +813,29 @@ private bool TryToUnit(ElectricConductivityUnit unit, [NotNullWhen(true)] out El return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricConductivity ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricConductivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductivityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricConductivity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricConductivityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductivityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricConductivityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductivityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -871,6 +849,8 @@ public ElectricConductivity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 4eea5d8da6..ac9b4da7e4 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -120,13 +120,8 @@ public ElectricCurrent(double value, ElectricCurrentUnit unit) /// No unit was found for the given . public ElectricCurrent(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -809,25 +804,7 @@ public double As(ElectricCurrentUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricCurrentUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -920,28 +897,29 @@ private bool TryToUnit(ElectricCurrentUnit unit, [NotNullWhen(true)] out Electri return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricCurrent ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricCurrentUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricCurrent ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricCurrentUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricCurrentUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -955,6 +933,8 @@ public ElectricCurrent ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs index 2b3939be1a..606da32777 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs @@ -107,13 +107,8 @@ public ElectricCurrentDensity(double value, ElectricCurrentDensityUnit unit) /// No unit was found for the given . public ElectricCurrentDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -672,25 +667,7 @@ public double As(ElectricCurrentDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricCurrentDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -771,28 +748,29 @@ private bool TryToUnit(ElectricCurrentDensityUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricCurrentDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricCurrentDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricCurrentDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricCurrentDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricCurrentDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -806,6 +784,8 @@ public ElectricCurrentDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs index 794f1591ee..2319fca405 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -111,13 +111,8 @@ public ElectricCurrentGradient(double value, ElectricCurrentGradientUnit unit) /// No unit was found for the given . public ElectricCurrentGradient(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -746,25 +741,7 @@ public double As(ElectricCurrentGradientUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricCurrentGradientUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentGradientUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -853,28 +830,29 @@ private bool TryToUnit(ElectricCurrentGradientUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricCurrentGradient ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricCurrentGradientUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentGradientUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricCurrentGradient ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricCurrentGradientUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentGradientUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricCurrentGradientUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentGradientUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -888,6 +866,8 @@ public ElectricCurrentGradient ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs index 8cefe870b4..7a0282e459 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs @@ -105,13 +105,8 @@ public ElectricField(double value, ElectricFieldUnit unit) /// No unit was found for the given . public ElectricField(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -640,25 +635,7 @@ public double As(ElectricFieldUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricFieldUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricFieldUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +712,29 @@ private bool TryToUnit(ElectricFieldUnit unit, [NotNullWhen(true)] out ElectricF return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricField ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricFieldUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricFieldUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricField ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricFieldUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricFieldUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricFieldUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricFieldUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +748,8 @@ public ElectricField ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs index 38d620c487..3bff29eaec 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs @@ -83,7 +83,7 @@ static ElectricImpedance() new UnitInfo(ElectricImpedanceUnit.Microohm, "Microohms", BaseUnits.Undefined, "ElectricImpedance"), new UnitInfo(ElectricImpedanceUnit.Milliohm, "Milliohms", BaseUnits.Undefined, "ElectricImpedance"), new UnitInfo(ElectricImpedanceUnit.Nanoohm, "Nanoohms", BaseUnits.Undefined, "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Ohm, "Ohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Ohm, "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), new UnitInfo(ElectricImpedanceUnit.Teraohm, "Teraohms", BaseUnits.Undefined, "ElectricImpedance"), }, BaseUnit, Zero, BaseDimensions); @@ -113,13 +113,8 @@ public ElectricImpedance(double value, ElectricImpedanceUnit unit) /// No unit was found for the given . public ElectricImpedance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -753,25 +748,7 @@ public double As(ElectricImpedanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricImpedanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricImpedanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -862,28 +839,29 @@ private bool TryToUnit(ElectricImpedanceUnit unit, [NotNullWhen(true)] out Elect return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricImpedance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricImpedanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricImpedanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricImpedance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricImpedanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricImpedanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricImpedanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricImpedanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -897,6 +875,8 @@ public ElectricImpedance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs index cb5a25ec03..d0f98ce050 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs @@ -76,7 +76,7 @@ static ElectricInductance() Info = new QuantityInfo("ElectricInductance", new UnitInfo[] { - new UnitInfo(ElectricInductanceUnit.Henry, "Henries", BaseUnits.Undefined, "ElectricInductance"), + new UnitInfo(ElectricInductanceUnit.Henry, "Henries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricInductance"), new UnitInfo(ElectricInductanceUnit.Microhenry, "Microhenries", BaseUnits.Undefined, "ElectricInductance"), new UnitInfo(ElectricInductanceUnit.Millihenry, "Millihenries", BaseUnits.Undefined, "ElectricInductance"), new UnitInfo(ElectricInductanceUnit.Nanohenry, "Nanohenries", BaseUnits.Undefined, "ElectricInductance"), @@ -109,13 +109,8 @@ public ElectricInductance(double value, ElectricInductanceUnit unit) /// No unit was found for the given . public ElectricInductance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -704,25 +699,7 @@ public double As(ElectricInductanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricInductanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricInductanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -807,28 +784,29 @@ private bool TryToUnit(ElectricInductanceUnit unit, [NotNullWhen(true)] out Elec return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricInductance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricInductanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricInductanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricInductance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricInductanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricInductanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricInductanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricInductanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -842,6 +820,8 @@ public ElectricInductance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs index 095648bcf9..57bb8f7b91 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -116,13 +116,8 @@ public ElectricPotential(double value, ElectricPotentialUnit unit) /// No unit was found for the given . public ElectricPotential(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -754,25 +749,7 @@ public double As(ElectricPotentialUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricPotentialUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -859,28 +836,29 @@ private bool TryToUnit(ElectricPotentialUnit unit, [NotNullWhen(true)] out Elect return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricPotential ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricPotentialUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricPotential ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricPotentialUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricPotentialUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -894,6 +872,8 @@ public ElectricPotential ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs index a83ad4a9e0..a89d2a3c29 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -121,13 +121,8 @@ public ElectricPotentialChangeRate(double value, ElectricPotentialChangeRateUnit /// No unit was found for the given . public ElectricPotentialChangeRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -941,25 +936,7 @@ public double As(ElectricPotentialChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricPotentialChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialChangeRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1074,28 +1051,29 @@ private bool TryToUnit(ElectricPotentialChangeRateUnit unit, [NotNullWhen(true)] return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricPotentialChangeRate ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricPotentialChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialChangeRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricPotentialChangeRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricPotentialChangeRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialChangeRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricPotentialChangeRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1109,6 +1087,8 @@ public ElectricPotentialChangeRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs index 3be28e407e..e1e270f10c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs @@ -82,7 +82,7 @@ static ElectricReactance() new UnitInfo(ElectricReactanceUnit.Microohm, "Microohms", BaseUnits.Undefined, "ElectricReactance"), new UnitInfo(ElectricReactanceUnit.Milliohm, "Milliohms", BaseUnits.Undefined, "ElectricReactance"), new UnitInfo(ElectricReactanceUnit.Nanoohm, "Nanoohms", BaseUnits.Undefined, "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Ohm, "Ohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Ohm, "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), new UnitInfo(ElectricReactanceUnit.Teraohm, "Teraohms", BaseUnits.Undefined, "ElectricReactance"), }, BaseUnit, Zero, BaseDimensions); @@ -112,13 +112,8 @@ public ElectricReactance(double value, ElectricReactanceUnit unit) /// No unit was found for the given . public ElectricReactance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -752,25 +747,7 @@ public double As(ElectricReactanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricReactanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -861,28 +838,29 @@ private bool TryToUnit(ElectricReactanceUnit unit, [NotNullWhen(true)] out Elect return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricReactance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricReactanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricReactance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricReactanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricReactanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -896,6 +874,8 @@ public ElectricReactance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs index add0703afe..1e6ce1b120 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs @@ -104,13 +104,8 @@ public ElectricReactiveEnergy(double value, ElectricReactiveEnergyUnit unit) /// No unit was found for the given . public ElectricReactiveEnergy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -669,25 +664,7 @@ public double As(ElectricReactiveEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricReactiveEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactiveEnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -768,28 +745,29 @@ private bool TryToUnit(ElectricReactiveEnergyUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricReactiveEnergy ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricReactiveEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactiveEnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricReactiveEnergy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricReactiveEnergyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactiveEnergyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricReactiveEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactiveEnergyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -803,6 +781,8 @@ public ElectricReactiveEnergy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs index 083baa8371..374b1975f0 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs @@ -79,7 +79,7 @@ static ElectricReactivePower() new UnitInfo(ElectricReactivePowerUnit.GigavoltampereReactive, "GigavoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), new UnitInfo(ElectricReactivePowerUnit.KilovoltampereReactive, "KilovoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), new UnitInfo(ElectricReactivePowerUnit.MegavoltampereReactive, "MegavoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), - new UnitInfo(ElectricReactivePowerUnit.VoltampereReactive, "VoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), + new UnitInfo(ElectricReactivePowerUnit.VoltampereReactive, "VoltamperesReactive", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ElectricReactivePower"), }, BaseUnit, Zero, BaseDimensions); @@ -108,13 +108,8 @@ public ElectricReactivePower(double value, ElectricReactivePowerUnit unit) /// No unit was found for the given . public ElectricReactivePower(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -688,25 +683,7 @@ public double As(ElectricReactivePowerUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricReactivePowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactivePowerUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -789,28 +766,29 @@ private bool TryToUnit(ElectricReactivePowerUnit unit, [NotNullWhen(true)] out E return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricReactivePower ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricReactivePowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactivePowerUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricReactivePower ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricReactivePowerUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactivePowerUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricReactivePowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactivePowerUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -824,6 +802,8 @@ public ElectricReactivePower ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs index 210a19c681..c7555e98a4 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -85,7 +85,7 @@ static ElectricResistance() new UnitInfo(ElectricResistanceUnit.Microohm, "Microohms", BaseUnits.Undefined, "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Milliohm, "Milliohms", BaseUnits.Undefined, "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Nanoohm, "Nanoohms", BaseUnits.Undefined, "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Ohm, "Ohms", BaseUnits.Undefined, "ElectricResistance"), + new UnitInfo(ElectricResistanceUnit.Ohm, "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Teraohm, "Teraohms", BaseUnits.Undefined, "ElectricResistance"), }, BaseUnit, Zero, BaseDimensions); @@ -115,13 +115,8 @@ public ElectricResistance(double value, ElectricResistanceUnit unit) /// No unit was found for the given . public ElectricResistance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -765,25 +760,7 @@ public double As(ElectricResistanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricResistanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -874,28 +851,29 @@ private bool TryToUnit(ElectricResistanceUnit unit, [NotNullWhen(true)] out Elec return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricResistance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricResistanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricResistance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricResistanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricResistanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -909,6 +887,8 @@ public ElectricResistance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs index a97abe6293..2d78b73cae 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs @@ -87,7 +87,7 @@ static ElectricResistivity() new UnitInfo(ElectricResistivityUnit.NanoohmCentimeter, "NanoohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), new UnitInfo(ElectricResistivityUnit.NanoohmMeter, "NanoohmMeters", BaseUnits.Undefined, "ElectricResistivity"), new UnitInfo(ElectricResistivityUnit.OhmCentimeter, "OhmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.OhmMeter, "OhmMeters", BaseUnits.Undefined, "ElectricResistivity"), + new UnitInfo(ElectricResistivityUnit.OhmMeter, "OhmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), new UnitInfo(ElectricResistivityUnit.PicoohmCentimeter, "PicoohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), new UnitInfo(ElectricResistivityUnit.PicoohmMeter, "PicoohmMeters", BaseUnits.Undefined, "ElectricResistivity"), }, @@ -118,13 +118,8 @@ public ElectricResistivity(double value, ElectricResistivityUnit unit) /// No unit was found for the given . public ElectricResistivity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -859,25 +854,7 @@ public double As(ElectricResistivityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricResistivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistivityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -980,28 +957,29 @@ private bool TryToUnit(ElectricResistivityUnit unit, [NotNullWhen(true)] out Ele return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricResistivity ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricResistivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistivityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricResistivity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricResistivityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistivityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricResistivityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistivityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1015,6 +993,8 @@ public ElectricResistivity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs index fb60922b25..5fc4c68371 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs @@ -107,13 +107,8 @@ public ElectricSurfaceChargeDensity(double value, ElectricSurfaceChargeDensityUn /// No unit was found for the given . public ElectricSurfaceChargeDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -672,25 +667,7 @@ public double As(ElectricSurfaceChargeDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricSurfaceChargeDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSurfaceChargeDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -771,28 +748,29 @@ private bool TryToUnit(ElectricSurfaceChargeDensityUnit unit, [NotNullWhen(true) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricSurfaceChargeDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricSurfaceChargeDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSurfaceChargeDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricSurfaceChargeDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricSurfaceChargeDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSurfaceChargeDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricSurfaceChargeDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSurfaceChargeDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -806,6 +784,8 @@ public ElectricSurfaceChargeDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs index c3902a8db0..28643f7bad 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs @@ -89,7 +89,7 @@ static ElectricSusceptance() new UnitInfo(ElectricSusceptanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricSusceptance"), new UnitInfo(ElectricSusceptanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricSusceptance"), new UnitInfo(ElectricSusceptanceUnit.Nanosiemens, "Nanosiemens", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Siemens, "Siemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Siemens, "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), new UnitInfo(ElectricSusceptanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricSusceptance"), new UnitInfo(ElectricSusceptanceUnit.Terasiemens, "Terasiemens", BaseUnits.Undefined, "ElectricSusceptance"), }, @@ -120,13 +120,8 @@ public ElectricSusceptance(double value, ElectricSusceptanceUnit unit) /// No unit was found for the given . public ElectricSusceptance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -880,25 +875,7 @@ public double As(ElectricSusceptanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricSusceptanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSusceptanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1005,28 +982,29 @@ private bool TryToUnit(ElectricSusceptanceUnit unit, [NotNullWhen(true)] out Ele return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ElectricSusceptance ToUnit(UnitSystem unitSystem) { - if (!(unit is ElectricSusceptanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSusceptanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ElectricSusceptance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ElectricSusceptanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSusceptanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricSusceptanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSusceptanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1040,6 +1018,8 @@ public ElectricSusceptance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index 3856db8f3b..d82d3e4e1b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -156,13 +156,8 @@ public Energy(double value, EnergyUnit unit) /// No unit was found for the given . public Energy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1358,25 +1353,7 @@ public double As(EnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is EnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1531,28 +1508,29 @@ private bool TryToUnit(EnergyUnit unit, [NotNullWhen(true)] out Energy? converte return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Energy ToUnit(UnitSystem unitSystem) { - if (!(unit is EnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Energy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not EnergyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is EnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1566,6 +1544,8 @@ public Energy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs index 6781060701..050efb7458 100644 --- a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs @@ -116,13 +116,8 @@ public EnergyDensity(double value, EnergyDensityUnit unit) /// No unit was found for the given . public EnergyDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -826,25 +821,7 @@ public double As(EnergyDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is EnergyDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -943,28 +920,29 @@ private bool TryToUnit(EnergyDensityUnit unit, [NotNullWhen(true)] out EnergyDen return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public EnergyDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is EnergyDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public EnergyDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not EnergyDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is EnergyDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -978,6 +956,8 @@ public EnergyDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs index 6229ac2f6b..a4b51d48a7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs @@ -79,8 +79,8 @@ static Entropy() new UnitInfo[] { new UnitInfo(EntropyUnit.CaloriePerKelvin, "CaloriesPerKelvin", BaseUnits.Undefined, "Entropy"), - new UnitInfo(EntropyUnit.JoulePerDegreeCelsius, "JoulesPerDegreeCelsius", BaseUnits.Undefined, "Entropy"), - new UnitInfo(EntropyUnit.JoulePerKelvin, "JoulesPerKelvin", BaseUnits.Undefined, "Entropy"), + new UnitInfo(EntropyUnit.JoulePerDegreeCelsius, "JoulesPerDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "Entropy"), + new UnitInfo(EntropyUnit.JoulePerKelvin, "JoulesPerKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "Entropy"), new UnitInfo(EntropyUnit.KilocaloriePerKelvin, "KilocaloriesPerKelvin", BaseUnits.Undefined, "Entropy"), new UnitInfo(EntropyUnit.KilojoulePerDegreeCelsius, "KilojoulesPerDegreeCelsius", BaseUnits.Undefined, "Entropy"), new UnitInfo(EntropyUnit.KilojoulePerKelvin, "KilojoulesPerKelvin", BaseUnits.Undefined, "Entropy"), @@ -113,13 +113,8 @@ public Entropy(double value, EntropyUnit unit) /// No unit was found for the given . public Entropy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -760,25 +755,7 @@ public double As(EntropyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is EntropyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EntropyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -867,28 +844,29 @@ private bool TryToUnit(EntropyUnit unit, [NotNullWhen(true)] out Entropy? conver return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Entropy ToUnit(UnitSystem unitSystem) { - if (!(unit is EntropyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EntropyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Entropy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not EntropyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EntropyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is EntropyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EntropyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -902,6 +880,8 @@ public Entropy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs index bfda9e0812..9de6741fc9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs @@ -98,7 +98,7 @@ static Force() new UnitInfo(ForceUnit.Millinewton, "Millinewtons", BaseUnits.Undefined, "Force"), new UnitInfo(ForceUnit.Newton, "Newtons", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), new UnitInfo(ForceUnit.OunceForce, "OunceForce", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.Poundal, "Poundals", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound, time: DurationUnit.Second), "Force"), + new UnitInfo(ForceUnit.Poundal, "Poundals", BaseUnits.Undefined, "Force"), new UnitInfo(ForceUnit.PoundForce, "PoundsForce", BaseUnits.Undefined, "Force"), new UnitInfo(ForceUnit.ShortTonForce, "ShortTonsForce", BaseUnits.Undefined, "Force"), new UnitInfo(ForceUnit.TonneForce, "TonnesForce", BaseUnits.Undefined, "Force"), @@ -130,13 +130,8 @@ public Force(double value, ForceUnit unit) /// No unit was found for the given . public Force(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -951,25 +946,7 @@ public double As(ForceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ForceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1074,28 +1051,29 @@ private bool TryToUnit(ForceUnit unit, [NotNullWhen(true)] out Force? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Force ToUnit(UnitSystem unitSystem) { - if (!(unit is ForceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Force ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ForceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ForceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1109,6 +1087,8 @@ public Force ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs index 18765dcc65..4bd00061b6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs @@ -88,7 +88,7 @@ static ForceChangeRate() new UnitInfo(ForceChangeRateUnit.MillinewtonPerSecond, "MillinewtonsPerSecond", BaseUnits.Undefined, "ForceChangeRate"), new UnitInfo(ForceChangeRateUnit.NanonewtonPerSecond, "NanonewtonsPerSecond", BaseUnits.Undefined, "ForceChangeRate"), new UnitInfo(ForceChangeRateUnit.NewtonPerMinute, "NewtonsPerMinute", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.NewtonPerSecond, "NewtonsPerSecond", BaseUnits.Undefined, "ForceChangeRate"), + new UnitInfo(ForceChangeRateUnit.NewtonPerSecond, "NewtonsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), new UnitInfo(ForceChangeRateUnit.PoundForcePerMinute, "PoundsForcePerMinute", BaseUnits.Undefined, "ForceChangeRate"), new UnitInfo(ForceChangeRateUnit.PoundForcePerSecond, "PoundsForcePerSecond", BaseUnits.Undefined, "ForceChangeRate"), }, @@ -119,13 +119,8 @@ public ForceChangeRate(double value, ForceChangeRateUnit unit) /// No unit was found for the given . public ForceChangeRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -874,25 +869,7 @@ public double As(ForceChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ForceChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceChangeRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -997,28 +974,29 @@ private bool TryToUnit(ForceChangeRateUnit unit, [NotNullWhen(true)] out ForceCh return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ForceChangeRate ToUnit(UnitSystem unitSystem) { - if (!(unit is ForceChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceChangeRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ForceChangeRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ForceChangeRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceChangeRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ForceChangeRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1032,6 +1010,8 @@ public ForceChangeRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs index d81933e14b..ad25e05514 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs @@ -114,7 +114,7 @@ static ForcePerLength() new UnitInfo(ForcePerLengthUnit.NanonewtonPerMeter, "NanonewtonsPerMeter", BaseUnits.Undefined, "ForcePerLength"), new UnitInfo(ForcePerLengthUnit.NanonewtonPerMillimeter, "NanonewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), new UnitInfo(ForcePerLengthUnit.NewtonPerCentimeter, "NewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NewtonPerMeter, "NewtonsPerMeter", BaseUnits.Undefined, "ForcePerLength"), + new UnitInfo(ForcePerLengthUnit.NewtonPerMeter, "NewtonsPerMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForcePerLength"), new UnitInfo(ForcePerLengthUnit.NewtonPerMillimeter, "NewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), new UnitInfo(ForcePerLengthUnit.PoundForcePerFoot, "PoundsForcePerFoot", BaseUnits.Undefined, "ForcePerLength"), new UnitInfo(ForcePerLengthUnit.PoundForcePerInch, "PoundsForcePerInch", BaseUnits.Undefined, "ForcePerLength"), @@ -150,13 +150,8 @@ public ForcePerLength(double value, ForcePerLengthUnit unit) /// No unit was found for the given . public ForcePerLength(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1298,25 +1293,7 @@ public double As(ForcePerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ForcePerLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForcePerLengthUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1467,28 +1444,29 @@ private bool TryToUnit(ForcePerLengthUnit unit, [NotNullWhen(true)] out ForcePer return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ForcePerLength ToUnit(UnitSystem unitSystem) { - if (!(unit is ForcePerLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForcePerLengthUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ForcePerLength ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ForcePerLengthUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForcePerLengthUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ForcePerLengthUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForcePerLengthUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1502,6 +1480,8 @@ public ForcePerLength ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs index 2c27c18eb4..046ba34eaf 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs @@ -76,17 +76,17 @@ static Frequency() Info = new QuantityInfo("Frequency", new UnitInfo[] { - new UnitInfo(FrequencyUnit.BeatPerMinute, "BeatsPerMinute", BaseUnits.Undefined, "Frequency"), + new UnitInfo(FrequencyUnit.BeatPerMinute, "BeatsPerMinute", new BaseUnits(time: DurationUnit.Minute), "Frequency"), new UnitInfo(FrequencyUnit.BUnit, "BUnits", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.CyclePerHour, "CyclesPerHour", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.CyclePerMinute, "CyclesPerMinute", BaseUnits.Undefined, "Frequency"), + new UnitInfo(FrequencyUnit.CyclePerHour, "CyclesPerHour", new BaseUnits(time: DurationUnit.Hour), "Frequency"), + new UnitInfo(FrequencyUnit.CyclePerMinute, "CyclesPerMinute", new BaseUnits(time: DurationUnit.Minute), "Frequency"), new UnitInfo(FrequencyUnit.Gigahertz, "Gigahertz", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.Hertz, "Hertz", BaseUnits.Undefined, "Frequency"), + new UnitInfo(FrequencyUnit.Hertz, "Hertz", new BaseUnits(time: DurationUnit.Second), "Frequency"), new UnitInfo(FrequencyUnit.Kilohertz, "Kilohertz", BaseUnits.Undefined, "Frequency"), new UnitInfo(FrequencyUnit.Megahertz, "Megahertz", BaseUnits.Undefined, "Frequency"), new UnitInfo(FrequencyUnit.Microhertz, "Microhertz", BaseUnits.Undefined, "Frequency"), new UnitInfo(FrequencyUnit.Millihertz, "Millihertz", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.PerSecond, "PerSecond", BaseUnits.Undefined, "Frequency"), + new UnitInfo(FrequencyUnit.PerSecond, "PerSecond", new BaseUnits(time: DurationUnit.Second), "Frequency"), new UnitInfo(FrequencyUnit.RadianPerSecond, "RadiansPerSecond", BaseUnits.Undefined, "Frequency"), new UnitInfo(FrequencyUnit.Terahertz, "Terahertz", BaseUnits.Undefined, "Frequency"), }, @@ -117,13 +117,8 @@ public Frequency(double value, FrequencyUnit unit) /// No unit was found for the given . public Frequency(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -842,25 +837,7 @@ public double As(FrequencyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is FrequencyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FrequencyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -961,28 +938,29 @@ private bool TryToUnit(FrequencyUnit unit, [NotNullWhen(true)] out Frequency? co return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Frequency ToUnit(UnitSystem unitSystem) { - if (!(unit is FrequencyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FrequencyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Frequency ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not FrequencyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FrequencyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is FrequencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FrequencyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -996,6 +974,8 @@ public Frequency ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs index c2f4408a3a..ac329b68d0 100644 --- a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs @@ -98,25 +98,6 @@ public FuelEfficiency(double value, FuelEfficiencyUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public FuelEfficiency(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -688,25 +669,7 @@ public double As(FuelEfficiencyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is FuelEfficiencyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FuelEfficiencyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -789,28 +752,29 @@ private bool TryToUnit(FuelEfficiencyUnit unit, [NotNullWhen(true)] out FuelEffi return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public FuelEfficiency ToUnit(UnitSystem unitSystem) { - if (!(unit is FuelEfficiencyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FuelEfficiencyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public FuelEfficiency ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not FuelEfficiencyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FuelEfficiencyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is FuelEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FuelEfficiencyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -824,6 +788,8 @@ public FuelEfficiency ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs index cfb84f6dd7..0419986765 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs @@ -122,13 +122,8 @@ public HeatFlux(double value, HeatFluxUnit unit) /// No unit was found for the given . public HeatFlux(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -922,25 +917,7 @@ public double As(HeatFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is HeatFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatFluxUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1051,28 +1028,29 @@ private bool TryToUnit(HeatFluxUnit unit, [NotNullWhen(true)] out HeatFlux? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public HeatFlux ToUnit(UnitSystem unitSystem) { - if (!(unit is HeatFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatFluxUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public HeatFlux ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not HeatFluxUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatFluxUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is HeatFluxUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatFluxUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1086,6 +1064,8 @@ public HeatFlux ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index e2fc3cb444..ddc7f7adeb 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -76,8 +76,8 @@ static HeatTransferCoefficient() new UnitInfo(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, "BtusPerHourSquareFootDegreeFahrenheit", BaseUnits.Undefined, "HeatTransferCoefficient"), new UnitInfo(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, "CaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined, "HeatTransferCoefficient"), new UnitInfo(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, "KilocaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined, "HeatTransferCoefficient"), - new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "WattsPerSquareMeterCelsius", BaseUnits.Undefined, "HeatTransferCoefficient"), - new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "WattsPerSquareMeterKelvin", BaseUnits.Undefined, "HeatTransferCoefficient"), + new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "WattsPerSquareMeterCelsius", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "HeatTransferCoefficient"), + new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "WattsPerSquareMeterKelvin", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "HeatTransferCoefficient"), }, BaseUnit, Zero, BaseDimensions); @@ -106,13 +106,8 @@ public HeatTransferCoefficient(double value, HeatTransferCoefficientUnit unit) /// No unit was found for the given . public HeatTransferCoefficient(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -701,25 +696,7 @@ public double As(HeatTransferCoefficientUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is HeatTransferCoefficientUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatTransferCoefficientUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -804,28 +781,29 @@ private bool TryToUnit(HeatTransferCoefficientUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public HeatTransferCoefficient ToUnit(UnitSystem unitSystem) { - if (!(unit is HeatTransferCoefficientUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatTransferCoefficientUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public HeatTransferCoefficient ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not HeatTransferCoefficientUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatTransferCoefficientUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is HeatTransferCoefficientUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatTransferCoefficientUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -839,6 +817,8 @@ public HeatTransferCoefficient ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs index 38f2968a65..cb13f3bdf4 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs @@ -80,7 +80,7 @@ static Illuminance() new UnitInfo[] { new UnitInfo(IlluminanceUnit.Kilolux, "Kilolux", BaseUnits.Undefined, "Illuminance"), - new UnitInfo(IlluminanceUnit.Lux, "Lux", BaseUnits.Undefined, "Illuminance"), + new UnitInfo(IlluminanceUnit.Lux, "Lux", new BaseUnits(length: LengthUnit.Meter, luminousIntensity: LuminousIntensityUnit.Candela), "Illuminance"), new UnitInfo(IlluminanceUnit.Megalux, "Megalux", BaseUnits.Undefined, "Illuminance"), new UnitInfo(IlluminanceUnit.Millilux, "Millilux", BaseUnits.Undefined, "Illuminance"), }, @@ -111,13 +111,8 @@ public Illuminance(double value, IlluminanceUnit unit) /// No unit was found for the given . public Illuminance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -701,25 +696,7 @@ public double As(IlluminanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is IlluminanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IlluminanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -802,28 +779,29 @@ private bool TryToUnit(IlluminanceUnit unit, [NotNullWhen(true)] out Illuminance return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Illuminance ToUnit(UnitSystem unitSystem) { - if (!(unit is IlluminanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IlluminanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Illuminance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not IlluminanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IlluminanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is IlluminanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IlluminanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -837,6 +815,8 @@ public Illuminance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs index 9e5c5a7fe9..110b7ba714 100644 --- a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs @@ -76,16 +76,16 @@ static Impulse() new UnitInfo(ImpulseUnit.CentinewtonSecond, "CentinewtonSeconds", BaseUnits.Undefined, "Impulse"), new UnitInfo(ImpulseUnit.DecanewtonSecond, "DecanewtonSeconds", BaseUnits.Undefined, "Impulse"), new UnitInfo(ImpulseUnit.DecinewtonSecond, "DecinewtonSeconds", BaseUnits.Undefined, "Impulse"), - new UnitInfo(ImpulseUnit.KilogramMeterPerSecond, "KilogramMetersPerSecond", BaseUnits.Undefined, "Impulse"), + new UnitInfo(ImpulseUnit.KilogramMeterPerSecond, "KilogramMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), new UnitInfo(ImpulseUnit.KilonewtonSecond, "KilonewtonSeconds", BaseUnits.Undefined, "Impulse"), new UnitInfo(ImpulseUnit.MeganewtonSecond, "MeganewtonSeconds", BaseUnits.Undefined, "Impulse"), new UnitInfo(ImpulseUnit.MicronewtonSecond, "MicronewtonSeconds", BaseUnits.Undefined, "Impulse"), new UnitInfo(ImpulseUnit.MillinewtonSecond, "MillinewtonSeconds", BaseUnits.Undefined, "Impulse"), new UnitInfo(ImpulseUnit.NanonewtonSecond, "NanonewtonSeconds", BaseUnits.Undefined, "Impulse"), - new UnitInfo(ImpulseUnit.NewtonSecond, "NewtonSeconds", BaseUnits.Undefined, "Impulse"), - new UnitInfo(ImpulseUnit.PoundFootPerSecond, "PoundFeetPerSecond", BaseUnits.Undefined, "Impulse"), + new UnitInfo(ImpulseUnit.NewtonSecond, "NewtonSeconds", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), + new UnitInfo(ImpulseUnit.PoundFootPerSecond, "PoundFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound, time: DurationUnit.Second), "Impulse"), new UnitInfo(ImpulseUnit.PoundForceSecond, "PoundForceSeconds", BaseUnits.Undefined, "Impulse"), - new UnitInfo(ImpulseUnit.SlugFootPerSecond, "SlugFeetPerSecond", BaseUnits.Undefined, "Impulse"), + new UnitInfo(ImpulseUnit.SlugFootPerSecond, "SlugFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug, time: DurationUnit.Second), "Impulse"), }, BaseUnit, Zero, BaseDimensions); @@ -114,13 +114,8 @@ public Impulse(double value, ImpulseUnit unit) /// No unit was found for the given . public Impulse(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -829,25 +824,7 @@ public double As(ImpulseUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ImpulseUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ImpulseUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -948,28 +925,29 @@ private bool TryToUnit(ImpulseUnit unit, [NotNullWhen(true)] out Impulse? conver return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Impulse ToUnit(UnitSystem unitSystem) { - if (!(unit is ImpulseUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ImpulseUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Impulse ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ImpulseUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ImpulseUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ImpulseUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ImpulseUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -983,6 +961,8 @@ public Impulse ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Information.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.g.cs index 8eecdee5a3..bca77601ae 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.g.cs @@ -117,25 +117,6 @@ public Information(double value, InformationUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public Information(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -1037,25 +1018,7 @@ public double As(InformationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is InformationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(InformationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1182,28 +1145,29 @@ private bool TryToUnit(InformationUnit unit, [NotNullWhen(true)] out Information return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Information ToUnit(UnitSystem unitSystem) { - if (!(unit is InformationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(InformationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Information ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not InformationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(InformationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is InformationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(InformationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1217,6 +1181,8 @@ public Information ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs index f9a9d737e3..89ee4baf69 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs @@ -86,7 +86,7 @@ static Irradiance() new UnitInfo(IrradianceUnit.PicowattPerSquareCentimeter, "PicowattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), new UnitInfo(IrradianceUnit.PicowattPerSquareMeter, "PicowattsPerSquareMeter", BaseUnits.Undefined, "Irradiance"), new UnitInfo(IrradianceUnit.WattPerSquareCentimeter, "WattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.WattPerSquareMeter, "WattsPerSquareMeter", BaseUnits.Undefined, "Irradiance"), + new UnitInfo(IrradianceUnit.WattPerSquareMeter, "WattsPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "Irradiance"), }, BaseUnit, Zero, BaseDimensions); @@ -115,13 +115,8 @@ public Irradiance(double value, IrradianceUnit unit) /// No unit was found for the given . public Irradiance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -845,25 +840,7 @@ public double As(IrradianceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is IrradianceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradianceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -966,28 +943,29 @@ private bool TryToUnit(IrradianceUnit unit, [NotNullWhen(true)] out Irradiance? return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Irradiance ToUnit(UnitSystem unitSystem) { - if (!(unit is IrradianceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradianceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Irradiance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not IrradianceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradianceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is IrradianceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradianceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1001,6 +979,8 @@ public Irradiance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs index f048b4f21c..d144ddba97 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs @@ -78,7 +78,7 @@ static Irradiation() { new UnitInfo(IrradiationUnit.BtuPerSquareFoot, "BtusPerSquareFoot", BaseUnits.Undefined, "Irradiation"), new UnitInfo(IrradiationUnit.JoulePerSquareCentimeter, "JoulesPerSquareCentimeter", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.JoulePerSquareMeter, "JoulesPerSquareMeter", BaseUnits.Undefined, "Irradiation"), + new UnitInfo(IrradiationUnit.JoulePerSquareMeter, "JoulesPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "Irradiation"), new UnitInfo(IrradiationUnit.JoulePerSquareMillimeter, "JoulesPerSquareMillimeter", BaseUnits.Undefined, "Irradiation"), new UnitInfo(IrradiationUnit.KilobtuPerSquareFoot, "KilobtusPerSquareFoot", BaseUnits.Undefined, "Irradiation"), new UnitInfo(IrradiationUnit.KilojoulePerSquareMeter, "KilojoulesPerSquareMeter", BaseUnits.Undefined, "Irradiation"), @@ -113,13 +113,8 @@ public Irradiation(double value, IrradiationUnit unit) /// No unit was found for the given . public Irradiation(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -768,25 +763,7 @@ public double As(IrradiationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is IrradiationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradiationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -879,28 +856,29 @@ private bool TryToUnit(IrradiationUnit unit, [NotNullWhen(true)] out Irradiation return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Irradiation ToUnit(UnitSystem unitSystem) { - if (!(unit is IrradiationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradiationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Irradiation ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not IrradiationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradiationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is IrradiationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradiationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -914,6 +892,8 @@ public Irradiation ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs index b5fa98f98b..c98fd931ba 100644 --- a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs @@ -86,7 +86,7 @@ static Jerk() new UnitInfo(JerkUnit.MillimeterPerSecondCubed, "MillimetersPerSecondCubed", BaseUnits.Undefined, "Jerk"), new UnitInfo(JerkUnit.MillistandardGravitiesPerSecond, "MillistandardGravitiesPerSecond", BaseUnits.Undefined, "Jerk"), new UnitInfo(JerkUnit.NanometerPerSecondCubed, "NanometersPerSecondCubed", BaseUnits.Undefined, "Jerk"), - new UnitInfo(JerkUnit.StandardGravitiesPerSecond, "StandardGravitiesPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "Jerk"), + new UnitInfo(JerkUnit.StandardGravitiesPerSecond, "StandardGravitiesPerSecond", BaseUnits.Undefined, "Jerk"), }, BaseUnit, Zero, BaseDimensions); @@ -115,13 +115,8 @@ public Jerk(double value, JerkUnit unit) /// No unit was found for the given . public Jerk(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -810,25 +805,7 @@ public double As(JerkUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is JerkUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(JerkUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -925,28 +902,29 @@ private bool TryToUnit(JerkUnit unit, [NotNullWhen(true)] out Jerk? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Jerk ToUnit(UnitSystem unitSystem) { - if (!(unit is JerkUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(JerkUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Jerk ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not JerkUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(JerkUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is JerkUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(JerkUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -960,6 +938,8 @@ public Jerk ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index 53348c761e..098afe51b6 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -88,8 +88,8 @@ static KinematicViscosity() new UnitInfo(KinematicViscosityUnit.Microstokes, "Microstokes", BaseUnits.Undefined, "KinematicViscosity"), new UnitInfo(KinematicViscosityUnit.Millistokes, "Millistokes", BaseUnits.Undefined, "KinematicViscosity"), new UnitInfo(KinematicViscosityUnit.Nanostokes, "Nanostokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.SquareFootPerSecond, "SquareFeetPerSecond", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.SquareMeterPerSecond, "SquareMetersPerSecond", BaseUnits.Undefined, "KinematicViscosity"), + new UnitInfo(KinematicViscosityUnit.SquareFootPerSecond, "SquareFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "KinematicViscosity"), + new UnitInfo(KinematicViscosityUnit.SquareMeterPerSecond, "SquareMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "KinematicViscosity"), new UnitInfo(KinematicViscosityUnit.Stokes, "Stokes", BaseUnits.Undefined, "KinematicViscosity"), }, BaseUnit, Zero, BaseDimensions); @@ -119,13 +119,8 @@ public KinematicViscosity(double value, KinematicViscosityUnit unit) /// No unit was found for the given . public KinematicViscosity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -802,25 +797,7 @@ public double As(KinematicViscosityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is KinematicViscosityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(KinematicViscosityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -913,28 +890,29 @@ private bool TryToUnit(KinematicViscosityUnit unit, [NotNullWhen(true)] out Kine return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public KinematicViscosity ToUnit(UnitSystem unitSystem) { - if (!(unit is KinematicViscosityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(KinematicViscosityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public KinematicViscosity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not KinematicViscosityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(KinematicViscosityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is KinematicViscosityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(KinematicViscosityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -948,6 +926,8 @@ public KinematicViscosity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs index 72a1dccb76..8cf019115c 100644 --- a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs @@ -77,7 +77,7 @@ static LeakRate() new UnitInfo[] { new UnitInfo(LeakRateUnit.MillibarLiterPerSecond, "MillibarLitersPerSecond", BaseUnits.Undefined, "LeakRate"), - new UnitInfo(LeakRateUnit.PascalCubicMeterPerSecond, "PascalCubicMetersPerSecond", BaseUnits.Undefined, "LeakRate"), + new UnitInfo(LeakRateUnit.PascalCubicMeterPerSecond, "PascalCubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LeakRate"), new UnitInfo(LeakRateUnit.TorrLiterPerSecond, "TorrLitersPerSecond", BaseUnits.Undefined, "LeakRate"), }, BaseUnit, Zero, BaseDimensions); @@ -107,13 +107,8 @@ public LeakRate(double value, LeakRateUnit unit) /// No unit was found for the given . public LeakRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -672,25 +667,7 @@ public double As(LeakRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LeakRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LeakRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -771,28 +748,29 @@ private bool TryToUnit(LeakRateUnit unit, [NotNullWhen(true)] out LeakRate? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public LeakRate ToUnit(UnitSystem unitSystem) { - if (!(unit is LeakRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LeakRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public LeakRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LeakRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LeakRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LeakRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LeakRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -806,6 +784,8 @@ public LeakRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index 5395dde6f2..4b04210b0a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -93,7 +93,7 @@ static Length() Info = new QuantityInfo("Length", new UnitInfo[] { - new UnitInfo(LengthUnit.Angstrom, "Angstroms", BaseUnits.Undefined, "Length"), + new UnitInfo(LengthUnit.Angstrom, "Angstroms", new BaseUnits(length: LengthUnit.Angstrom), "Length"), new UnitInfo(LengthUnit.AstronomicalUnit, "AstronomicalUnits", BaseUnits.Undefined, "Length"), new UnitInfo(LengthUnit.Centimeter, "Centimeters", BaseUnits.Undefined, "Length"), new UnitInfo(LengthUnit.Chain, "Chains", new BaseUnits(length: LengthUnit.Chain), "Length"), @@ -163,13 +163,8 @@ public Length(double value, LengthUnit unit) /// No unit was found for the given . public Length(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1432,25 +1427,7 @@ public double As(LengthUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LengthUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1609,28 +1586,29 @@ private bool TryToUnit(LengthUnit unit, [NotNullWhen(true)] out Length? converte return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Length ToUnit(UnitSystem unitSystem) { - if (!(unit is LengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LengthUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Length ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LengthUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LengthUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LengthUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LengthUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1644,6 +1622,8 @@ public Length ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Level.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.g.cs index aa6b0bbad1..a3471b0356 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.g.cs @@ -93,25 +93,6 @@ public Level(double value, LevelUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public Level(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -661,25 +642,7 @@ public double As(LevelUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LevelUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LevelUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -758,28 +721,29 @@ private bool TryToUnit(LevelUnit unit, [NotNullWhen(true)] out Level? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Level ToUnit(UnitSystem unitSystem) { - if (!(unit is LevelUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LevelUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Level ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LevelUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LevelUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LevelUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LevelUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -793,6 +757,8 @@ public Level ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs index d7f7b3128b..ac267a3050 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs @@ -81,10 +81,10 @@ static LinearDensity() Info = new QuantityInfo("LinearDensity", new UnitInfo[] { - new UnitInfo(LinearDensityUnit.GramPerCentimeter, "GramsPerCentimeter", BaseUnits.Undefined, "LinearDensity"), - new UnitInfo(LinearDensityUnit.GramPerFoot, "GramsPerFoot", BaseUnits.Undefined, "LinearDensity"), - new UnitInfo(LinearDensityUnit.GramPerMeter, "GramsPerMeter", BaseUnits.Undefined, "LinearDensity"), - new UnitInfo(LinearDensityUnit.GramPerMillimeter, "GramsPerMillimeter", BaseUnits.Undefined, "LinearDensity"), + new UnitInfo(LinearDensityUnit.GramPerCentimeter, "GramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "LinearDensity"), + new UnitInfo(LinearDensityUnit.GramPerFoot, "GramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Gram), "LinearDensity"), + new UnitInfo(LinearDensityUnit.GramPerMeter, "GramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "LinearDensity"), + new UnitInfo(LinearDensityUnit.GramPerMillimeter, "GramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "LinearDensity"), new UnitInfo(LinearDensityUnit.KilogramPerCentimeter, "KilogramsPerCentimeter", BaseUnits.Undefined, "LinearDensity"), new UnitInfo(LinearDensityUnit.KilogramPerFoot, "KilogramsPerFoot", BaseUnits.Undefined, "LinearDensity"), new UnitInfo(LinearDensityUnit.KilogramPerMeter, "KilogramsPerMeter", BaseUnits.Undefined, "LinearDensity"), @@ -97,8 +97,8 @@ static LinearDensity() new UnitInfo(LinearDensityUnit.MilligramPerFoot, "MilligramsPerFoot", BaseUnits.Undefined, "LinearDensity"), new UnitInfo(LinearDensityUnit.MilligramPerMeter, "MilligramsPerMeter", BaseUnits.Undefined, "LinearDensity"), new UnitInfo(LinearDensityUnit.MilligramPerMillimeter, "MilligramsPerMillimeter", BaseUnits.Undefined, "LinearDensity"), - new UnitInfo(LinearDensityUnit.PoundPerFoot, "PoundsPerFoot", BaseUnits.Undefined, "LinearDensity"), - new UnitInfo(LinearDensityUnit.PoundPerInch, "PoundsPerInch", BaseUnits.Undefined, "LinearDensity"), + new UnitInfo(LinearDensityUnit.PoundPerFoot, "PoundsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "LinearDensity"), + new UnitInfo(LinearDensityUnit.PoundPerInch, "PoundsPerInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound), "LinearDensity"), }, BaseUnit, Zero, BaseDimensions); @@ -127,13 +127,8 @@ public LinearDensity(double value, LinearDensityUnit unit) /// No unit was found for the given . public LinearDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -939,25 +934,7 @@ public double As(LinearDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LinearDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1068,28 +1045,29 @@ private bool TryToUnit(LinearDensityUnit unit, [NotNullWhen(true)] out LinearDen return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public LinearDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is LinearDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public LinearDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LinearDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LinearDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1103,6 +1081,8 @@ public LinearDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs index 22c3f0a7a1..d56fe6d1db 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -99,7 +99,7 @@ static LinearPowerDensity() new UnitInfo(LinearPowerDensityUnit.WattPerCentimeter, "WattsPerCentimeter", BaseUnits.Undefined, "LinearPowerDensity"), new UnitInfo(LinearPowerDensityUnit.WattPerFoot, "WattsPerFoot", BaseUnits.Undefined, "LinearPowerDensity"), new UnitInfo(LinearPowerDensityUnit.WattPerInch, "WattsPerInch", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.WattPerMeter, "WattsPerMeter", BaseUnits.Undefined, "LinearPowerDensity"), + new UnitInfo(LinearPowerDensityUnit.WattPerMeter, "WattsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LinearPowerDensity"), new UnitInfo(LinearPowerDensityUnit.WattPerMillimeter, "WattsPerMillimeter", BaseUnits.Undefined, "LinearPowerDensity"), }, BaseUnit, Zero, BaseDimensions); @@ -129,13 +129,8 @@ public LinearPowerDensity(double value, LinearPowerDensityUnit unit) /// No unit was found for the given . public LinearPowerDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1024,25 +1019,7 @@ public double As(LinearPowerDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LinearPowerDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearPowerDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1167,28 +1144,29 @@ private bool TryToUnit(LinearPowerDensityUnit unit, [NotNullWhen(true)] out Line return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public LinearPowerDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is LinearPowerDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearPowerDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public LinearPowerDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LinearPowerDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearPowerDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LinearPowerDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearPowerDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1202,6 +1180,8 @@ public LinearPowerDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs index 1233fa2041..143917c8a0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs @@ -117,13 +117,8 @@ public Luminance(double value, LuminanceUnit unit) /// No unit was found for the given . public Luminance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -797,25 +792,7 @@ public double As(LuminanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LuminanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -910,28 +887,29 @@ private bool TryToUnit(LuminanceUnit unit, [NotNullWhen(true)] out Luminance? co return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Luminance ToUnit(UnitSystem unitSystem) { - if (!(unit is LuminanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Luminance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LuminanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LuminanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -945,6 +923,8 @@ public Luminance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs index 403d3c812f..2048620172 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs @@ -89,7 +89,7 @@ static Luminosity() new UnitInfo(LuminosityUnit.Picowatt, "Picowatts", BaseUnits.Undefined, "Luminosity"), new UnitInfo(LuminosityUnit.SolarLuminosity, "SolarLuminosities", BaseUnits.Undefined, "Luminosity"), new UnitInfo(LuminosityUnit.Terawatt, "Terawatts", BaseUnits.Undefined, "Luminosity"), - new UnitInfo(LuminosityUnit.Watt, "Watts", BaseUnits.Undefined, "Luminosity"), + new UnitInfo(LuminosityUnit.Watt, "Watts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Luminosity"), }, BaseUnit, Zero, BaseDimensions); @@ -118,13 +118,8 @@ public Luminosity(double value, LuminosityUnit unit) /// No unit was found for the given . public Luminosity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -848,25 +843,7 @@ public double As(LuminosityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LuminosityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminosityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -969,28 +946,29 @@ private bool TryToUnit(LuminosityUnit unit, [NotNullWhen(true)] out Luminosity? return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Luminosity ToUnit(UnitSystem unitSystem) { - if (!(unit is LuminosityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminosityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Luminosity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LuminosityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminosityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LuminosityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminosityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1004,6 +982,8 @@ public Luminosity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs index 9337439ba6..f7db868075 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs @@ -80,7 +80,7 @@ static LuminousFlux() Info = new QuantityInfo("LuminousFlux", new UnitInfo[] { - new UnitInfo(LuminousFluxUnit.Lumen, "Lumens", BaseUnits.Undefined, "LuminousFlux"), + new UnitInfo(LuminousFluxUnit.Lumen, "Lumens", new BaseUnits(luminousIntensity: LuminousIntensityUnit.Candela), "LuminousFlux"), }, BaseUnit, Zero, BaseDimensions); @@ -109,13 +109,8 @@ public LuminousFlux(double value, LuminousFluxUnit unit) /// No unit was found for the given . public LuminousFlux(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -660,25 +655,7 @@ public double As(LuminousFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LuminousFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousFluxUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -755,28 +732,29 @@ private bool TryToUnit(LuminousFluxUnit unit, [NotNullWhen(true)] out LuminousFl return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public LuminousFlux ToUnit(UnitSystem unitSystem) { - if (!(unit is LuminousFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousFluxUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public LuminousFlux ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LuminousFluxUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousFluxUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LuminousFluxUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousFluxUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -790,6 +768,8 @@ public LuminousFlux ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs index 07272d5cde..7e2d128ea3 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs @@ -109,13 +109,8 @@ public LuminousIntensity(double value, LuminousIntensityUnit unit) /// No unit was found for the given . public LuminousIntensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -660,25 +655,7 @@ public double As(LuminousIntensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is LuminousIntensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousIntensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -755,28 +732,29 @@ private bool TryToUnit(LuminousIntensityUnit unit, [NotNullWhen(true)] out Lumin return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public LuminousIntensity ToUnit(UnitSystem unitSystem) { - if (!(unit is LuminousIntensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousIntensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public LuminousIntensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not LuminousIntensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousIntensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is LuminousIntensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousIntensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -790,6 +768,8 @@ public LuminousIntensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs index f6b31abbc4..98f69b2da9 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs @@ -81,7 +81,7 @@ static MagneticField() new UnitInfo(MagneticFieldUnit.Milligauss, "Milligausses", BaseUnits.Undefined, "MagneticField"), new UnitInfo(MagneticFieldUnit.Millitesla, "Milliteslas", BaseUnits.Undefined, "MagneticField"), new UnitInfo(MagneticFieldUnit.Nanotesla, "Nanoteslas", BaseUnits.Undefined, "MagneticField"), - new UnitInfo(MagneticFieldUnit.Tesla, "Teslas", BaseUnits.Undefined, "MagneticField"), + new UnitInfo(MagneticFieldUnit.Tesla, "Teslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, current: ElectricCurrentUnit.Ampere), "MagneticField"), }, BaseUnit, Zero, BaseDimensions); @@ -110,13 +110,8 @@ public MagneticField(double value, MagneticFieldUnit unit) /// No unit was found for the given . public MagneticField(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -720,25 +715,7 @@ public double As(MagneticFieldUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MagneticFieldUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFieldUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -825,28 +802,29 @@ private bool TryToUnit(MagneticFieldUnit unit, [NotNullWhen(true)] out MagneticF return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MagneticField ToUnit(UnitSystem unitSystem) { - if (!(unit is MagneticFieldUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFieldUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MagneticField ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MagneticFieldUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFieldUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MagneticFieldUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFieldUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -860,6 +838,8 @@ public MagneticField ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs index 0259aea044..308eb4923c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs @@ -76,7 +76,7 @@ static MagneticFlux() Info = new QuantityInfo("MagneticFlux", new UnitInfo[] { - new UnitInfo(MagneticFluxUnit.Weber, "Webers", BaseUnits.Undefined, "MagneticFlux"), + new UnitInfo(MagneticFluxUnit.Weber, "Webers", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "MagneticFlux"), }, BaseUnit, Zero, BaseDimensions); @@ -105,13 +105,8 @@ public MagneticFlux(double value, MagneticFluxUnit unit) /// No unit was found for the given . public MagneticFlux(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -640,25 +635,7 @@ public double As(MagneticFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MagneticFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFluxUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +712,29 @@ private bool TryToUnit(MagneticFluxUnit unit, [NotNullWhen(true)] out MagneticFl return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MagneticFlux ToUnit(UnitSystem unitSystem) { - if (!(unit is MagneticFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFluxUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MagneticFlux ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MagneticFluxUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFluxUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MagneticFluxUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFluxUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +748,8 @@ public MagneticFlux ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs index b1833c8480..6497d0312e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs @@ -105,13 +105,8 @@ public Magnetization(double value, MagnetizationUnit unit) /// No unit was found for the given . public Magnetization(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -640,25 +635,7 @@ public double As(MagnetizationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MagnetizationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagnetizationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +712,29 @@ private bool TryToUnit(MagnetizationUnit unit, [NotNullWhen(true)] out Magnetiza return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Magnetization ToUnit(UnitSystem unitSystem) { - if (!(unit is MagnetizationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagnetizationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Magnetization ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MagnetizationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagnetizationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MagnetizationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagnetizationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +748,8 @@ public Magnetization ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index 1dc2ca8792..3576d6a244 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -146,13 +146,8 @@ public Mass(double value, MassUnit unit) /// No unit was found for the given . public Mass(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1171,25 +1166,7 @@ public double As(MassUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MassUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1318,28 +1295,29 @@ private bool TryToUnit(MassUnit unit, [NotNullWhen(true)] out Mass? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Mass ToUnit(UnitSystem unitSystem) { - if (!(unit is MassUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Mass ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MassUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MassUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1353,6 +1331,8 @@ public Mass ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs index e67e356d19..1c9e4e903c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs @@ -96,7 +96,7 @@ static MassConcentration() new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, "GramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "MassConcentration"), new UnitInfo(MassConcentrationUnit.GramPerDeciliter, "GramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), new UnitInfo(MassConcentrationUnit.GramPerLiter, "GramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerMicroliter, "GramsPerMicroliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "MassConcentration"), + new UnitInfo(MassConcentrationUnit.GramPerMicroliter, "GramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), new UnitInfo(MassConcentrationUnit.GramPerMilliliter, "GramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "MassConcentration"), new UnitInfo(MassConcentrationUnit.KilogramPerCubicCentimeter, "KilogramsPerCubicCentimeter", BaseUnits.Undefined, "MassConcentration"), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMeter, "KilogramsPerCubicMeter", BaseUnits.Undefined, "MassConcentration"), @@ -160,13 +160,8 @@ public MassConcentration(double value, MassConcentrationUnit unit) /// No unit was found for the given . public MassConcentration(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1449,25 +1444,7 @@ public double As(MassConcentrationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MassConcentrationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassConcentrationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1640,28 +1617,29 @@ private bool TryToUnit(MassConcentrationUnit unit, [NotNullWhen(true)] out MassC return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MassConcentration ToUnit(UnitSystem unitSystem) { - if (!(unit is MassConcentrationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassConcentrationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MassConcentration ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MassConcentrationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassConcentrationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MassConcentrationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassConcentrationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1675,6 +1653,8 @@ public MassConcentration ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index 84b717d434..b14179bc58 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -91,14 +91,14 @@ static MassFlow() new UnitInfo(MassFlowUnit.DecagramPerSecond, "DecagramsPerSecond", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.DecigramPerDay, "DecigramsPerDay", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.DecigramPerSecond, "DecigramsPerSecond", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.GramPerDay, "GramsPerDay", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.GramPerHour, "GramsPerHour", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.GramPerSecond, "GramsPerSecond", BaseUnits.Undefined, "MassFlow"), + new UnitInfo(MassFlowUnit.GramPerDay, "GramsPerDay", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Day), "MassFlow"), + new UnitInfo(MassFlowUnit.GramPerHour, "GramsPerHour", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlow"), + new UnitInfo(MassFlowUnit.GramPerSecond, "GramsPerSecond", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlow"), new UnitInfo(MassFlowUnit.HectogramPerDay, "HectogramsPerDay", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.HectogramPerSecond, "HectogramsPerSecond", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.KilogramPerDay, "KilogramsPerDay", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.KilogramPerHour, "KilogramsPerHour", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.KilogramPerMinute, "KilogramsPerMinute", BaseUnits.Undefined, "MassFlow"), + new UnitInfo(MassFlowUnit.KilogramPerHour, "KilogramsPerHour", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Hour), "MassFlow"), + new UnitInfo(MassFlowUnit.KilogramPerMinute, "KilogramsPerMinute", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Minute), "MassFlow"), new UnitInfo(MassFlowUnit.KilogramPerSecond, "KilogramsPerSecond", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.MegagramPerDay, "MegagramsPerDay", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.MegapoundPerDay, "MegapoundsPerDay", BaseUnits.Undefined, "MassFlow"), @@ -111,13 +111,13 @@ static MassFlow() new UnitInfo(MassFlowUnit.MilligramPerSecond, "MilligramsPerSecond", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.NanogramPerDay, "NanogramsPerDay", BaseUnits.Undefined, "MassFlow"), new UnitInfo(MassFlowUnit.NanogramPerSecond, "NanogramsPerSecond", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerDay, "PoundsPerDay", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerHour, "PoundsPerHour", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerMinute, "PoundsPerMinute", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerSecond, "PoundsPerSecond", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.ShortTonPerHour, "ShortTonsPerHour", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.TonnePerDay, "TonnesPerDay", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.TonnePerHour, "TonnesPerHour", BaseUnits.Undefined, "MassFlow"), + new UnitInfo(MassFlowUnit.PoundPerDay, "PoundsPerDay", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Day), "MassFlow"), + new UnitInfo(MassFlowUnit.PoundPerHour, "PoundsPerHour", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Hour), "MassFlow"), + new UnitInfo(MassFlowUnit.PoundPerMinute, "PoundsPerMinute", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Minute), "MassFlow"), + new UnitInfo(MassFlowUnit.PoundPerSecond, "PoundsPerSecond", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Second), "MassFlow"), + new UnitInfo(MassFlowUnit.ShortTonPerHour, "ShortTonsPerHour", new BaseUnits(mass: MassUnit.ShortTon, time: DurationUnit.Hour), "MassFlow"), + new UnitInfo(MassFlowUnit.TonnePerDay, "TonnesPerDay", new BaseUnits(mass: MassUnit.Tonne, time: DurationUnit.Day), "MassFlow"), + new UnitInfo(MassFlowUnit.TonnePerHour, "TonnesPerHour", new BaseUnits(mass: MassUnit.Tonne, time: DurationUnit.Hour), "MassFlow"), }, BaseUnit, Zero, BaseDimensions); @@ -146,13 +146,8 @@ public MassFlow(double value, MassFlowUnit unit) /// No unit was found for the given . public MassFlow(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1225,25 +1220,7 @@ public double As(MassFlowUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MassFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFlowUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1384,28 +1361,29 @@ private bool TryToUnit(MassFlowUnit unit, [NotNullWhen(true)] out MassFlow? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MassFlow ToUnit(UnitSystem unitSystem) { - if (!(unit is MassFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFlowUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MassFlow ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MassFlowUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFlowUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MassFlowUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFlowUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1419,6 +1397,8 @@ public MassFlow ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index 1963819ea4..7f59baa289 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -78,12 +78,12 @@ static MassFlux() Info = new QuantityInfo("MassFlux", new UnitInfo[] { - new UnitInfo(MassFluxUnit.GramPerHourPerSquareCentimeter, "GramsPerHourPerSquareCentimeter", BaseUnits.Undefined, "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerHourPerSquareMeter, "GramsPerHourPerSquareMeter", BaseUnits.Undefined, "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerHourPerSquareMillimeter, "GramsPerHourPerSquareMillimeter", BaseUnits.Undefined, "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerSecondPerSquareCentimeter, "GramsPerSecondPerSquareCentimeter", BaseUnits.Undefined, "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMeter, "GramsPerSecondPerSquareMeter", BaseUnits.Undefined, "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMillimeter, "GramsPerSecondPerSquareMillimeter", BaseUnits.Undefined, "MassFlux"), + new UnitInfo(MassFluxUnit.GramPerHourPerSquareCentimeter, "GramsPerHourPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlux"), + new UnitInfo(MassFluxUnit.GramPerHourPerSquareMeter, "GramsPerHourPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlux"), + new UnitInfo(MassFluxUnit.GramPerHourPerSquareMillimeter, "GramsPerHourPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlux"), + new UnitInfo(MassFluxUnit.GramPerSecondPerSquareCentimeter, "GramsPerSecondPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlux"), + new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMeter, "GramsPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlux"), + new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMillimeter, "GramsPerSecondPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlux"), new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareCentimeter, "KilogramsPerHourPerSquareCentimeter", BaseUnits.Undefined, "MassFlux"), new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareMeter, "KilogramsPerHourPerSquareMeter", BaseUnits.Undefined, "MassFlux"), new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareMillimeter, "KilogramsPerHourPerSquareMillimeter", BaseUnits.Undefined, "MassFlux"), @@ -118,13 +118,8 @@ public MassFlux(double value, MassFluxUnit unit) /// No unit was found for the given . public MassFlux(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -840,25 +835,7 @@ public double As(MassFluxUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MassFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFluxUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -957,28 +934,29 @@ private bool TryToUnit(MassFluxUnit unit, [NotNullWhen(true)] out MassFlux? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MassFlux ToUnit(UnitSystem unitSystem) { - if (!(unit is MassFluxUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFluxUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MassFlux ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MassFluxUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFluxUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MassFluxUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFluxUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -992,6 +970,8 @@ public MassFlux ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs index 503b15c268..d8992b1464 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs @@ -121,25 +121,6 @@ public MassFraction(double value, MassFractionUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public MassFraction(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -1021,25 +1002,7 @@ public double As(MassFractionUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MassFractionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFractionUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1162,28 +1125,29 @@ private bool TryToUnit(MassFractionUnit unit, [NotNullWhen(true)] out MassFracti return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MassFraction ToUnit(UnitSystem unitSystem) { - if (!(unit is MassFractionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFractionUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MassFraction ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MassFractionUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFractionUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MassFractionUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFractionUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1197,6 +1161,8 @@ public MassFraction ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs index 6f9e809cf3..e9d03cd74a 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs @@ -73,10 +73,10 @@ static MassMomentOfInertia() Info = new QuantityInfo("MassMomentOfInertia", new UnitInfo[] { - new UnitInfo(MassMomentOfInertiaUnit.GramSquareCentimeter, "GramSquareCentimeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.GramSquareDecimeter, "GramSquareDecimeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.GramSquareMeter, "GramSquareMeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.GramSquareMillimeter, "GramSquareMillimeters", BaseUnits.Undefined, "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.GramSquareCentimeter, "GramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.GramSquareDecimeter, "GramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.GramSquareMeter, "GramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.GramSquareMillimeter, "GramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "MassMomentOfInertia"), new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareCentimeter, "KilogramSquareCentimeters", BaseUnits.Undefined, "MassMomentOfInertia"), new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareDecimeter, "KilogramSquareDecimeters", BaseUnits.Undefined, "MassMomentOfInertia"), new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareMeter, "KilogramSquareMeters", BaseUnits.Undefined, "MassMomentOfInertia"), @@ -93,14 +93,14 @@ static MassMomentOfInertia() new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareDecimeter, "MilligramSquareDecimeters", BaseUnits.Undefined, "MassMomentOfInertia"), new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareMeter, "MilligramSquareMeters", BaseUnits.Undefined, "MassMomentOfInertia"), new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareMillimeter, "MilligramSquareMillimeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.PoundSquareFoot, "PoundSquareFeet", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.PoundSquareInch, "PoundSquareInches", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.SlugSquareFoot, "SlugSquareFeet", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.SlugSquareInch, "SlugSquareInches", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareCentimeter, "TonneSquareCentimeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareDecimeter, "TonneSquareDecimeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareMeter, "TonneSquareMeters", BaseUnits.Undefined, "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareMilimeter, "TonneSquareMilimeters", BaseUnits.Undefined, "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.PoundSquareFoot, "PoundSquareFeet", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.PoundSquareInch, "PoundSquareInches", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.SlugSquareFoot, "SlugSquareFeet", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.SlugSquareInch, "SlugSquareInches", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Slug), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.TonneSquareCentimeter, "TonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.TonneSquareDecimeter, "TonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Tonne), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.TonneSquareMeter, "TonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne), "MassMomentOfInertia"), + new UnitInfo(MassMomentOfInertiaUnit.TonneSquareMilimeter, "TonneSquareMilimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne), "MassMomentOfInertia"), }, BaseUnit, Zero, BaseDimensions); @@ -129,13 +129,8 @@ public MassMomentOfInertia(double value, MassMomentOfInertiaUnit unit) /// No unit was found for the given . public MassMomentOfInertia(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1069,25 +1064,7 @@ public double As(MassMomentOfInertiaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MassMomentOfInertiaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassMomentOfInertiaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1218,28 +1195,29 @@ private bool TryToUnit(MassMomentOfInertiaUnit unit, [NotNullWhen(true)] out Mas return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MassMomentOfInertia ToUnit(UnitSystem unitSystem) { - if (!(unit is MassMomentOfInertiaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassMomentOfInertiaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MassMomentOfInertia ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MassMomentOfInertiaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassMomentOfInertiaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MassMomentOfInertiaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassMomentOfInertiaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1253,6 +1231,8 @@ public MassMomentOfInertia ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Molality.g.cs b/UnitsNet/GeneratedCode/Quantities/Molality.g.cs index 6ab7a23a58..17c8198cdf 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molality.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molality.g.cs @@ -107,13 +107,8 @@ public Molality(double value, MolalityUnit unit) /// No unit was found for the given . public Molality(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -672,25 +667,7 @@ public double As(MolalityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MolalityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolalityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -771,28 +748,29 @@ private bool TryToUnit(MolalityUnit unit, [NotNullWhen(true)] out Molality? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Molality ToUnit(UnitSystem unitSystem) { - if (!(unit is MolalityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolalityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Molality ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MolalityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolalityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolalityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolalityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -806,6 +784,8 @@ public Molality ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs index de51686dbd..6c46e31ea8 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs @@ -76,7 +76,7 @@ static MolarEnergy() Info = new QuantityInfo("MolarEnergy", new UnitInfo[] { - new UnitInfo(MolarEnergyUnit.JoulePerMole, "JoulesPerMole", BaseUnits.Undefined, "MolarEnergy"), + new UnitInfo(MolarEnergyUnit.JoulePerMole, "JoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Mole), "MolarEnergy"), new UnitInfo(MolarEnergyUnit.KilojoulePerMole, "KilojoulesPerMole", BaseUnits.Undefined, "MolarEnergy"), new UnitInfo(MolarEnergyUnit.MegajoulePerMole, "MegajoulesPerMole", BaseUnits.Undefined, "MolarEnergy"), }, @@ -107,13 +107,8 @@ public MolarEnergy(double value, MolarEnergyUnit unit) /// No unit was found for the given . public MolarEnergy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -682,25 +677,7 @@ public double As(MolarEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MolarEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -781,28 +758,29 @@ private bool TryToUnit(MolarEnergyUnit unit, [NotNullWhen(true)] out MolarEnergy return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MolarEnergy ToUnit(UnitSystem unitSystem) { - if (!(unit is MolarEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MolarEnergy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MolarEnergyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEnergyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolarEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEnergyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -816,6 +794,8 @@ public MolarEnergy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs index 2fa666d663..04bb0cade2 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs @@ -73,7 +73,7 @@ static MolarEntropy() Info = new QuantityInfo("MolarEntropy", new UnitInfo[] { - new UnitInfo(MolarEntropyUnit.JoulePerMoleKelvin, "JoulesPerMoleKelvin", BaseUnits.Undefined, "MolarEntropy"), + new UnitInfo(MolarEntropyUnit.JoulePerMoleKelvin, "JoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Mole), "MolarEntropy"), new UnitInfo(MolarEntropyUnit.KilojoulePerMoleKelvin, "KilojoulesPerMoleKelvin", BaseUnits.Undefined, "MolarEntropy"), new UnitInfo(MolarEntropyUnit.MegajoulePerMoleKelvin, "MegajoulesPerMoleKelvin", BaseUnits.Undefined, "MolarEntropy"), }, @@ -104,13 +104,8 @@ public MolarEntropy(double value, MolarEntropyUnit unit) /// No unit was found for the given . public MolarEntropy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -669,25 +664,7 @@ public double As(MolarEntropyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MolarEntropyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEntropyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -768,28 +745,29 @@ private bool TryToUnit(MolarEntropyUnit unit, [NotNullWhen(true)] out MolarEntro return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MolarEntropy ToUnit(UnitSystem unitSystem) { - if (!(unit is MolarEntropyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEntropyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MolarEntropy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MolarEntropyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEntropyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolarEntropyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEntropyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -803,6 +781,8 @@ public MolarEntropy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs index f923dcfe2b..5ef2503dc6 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -116,13 +116,8 @@ public MolarFlow(double value, MolarFlowUnit unit) /// No unit was found for the given . public MolarFlow(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -799,25 +794,7 @@ public double As(MolarFlowUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MolarFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarFlowUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -910,28 +887,29 @@ private bool TryToUnit(MolarFlowUnit unit, [NotNullWhen(true)] out MolarFlow? co return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MolarFlow ToUnit(UnitSystem unitSystem) { - if (!(unit is MolarFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarFlowUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MolarFlow ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MolarFlowUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarFlowUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolarFlowUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarFlowUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -945,6 +923,8 @@ public MolarFlow ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index 7769880fa7..6214edbe4d 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -81,16 +81,16 @@ static MolarMass() new UnitInfo(MolarMassUnit.CentigramPerMole, "CentigramsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.DecagramPerMole, "DecagramsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.DecigramPerMole, "DecigramsPerMole", BaseUnits.Undefined, "MolarMass"), - new UnitInfo(MolarMassUnit.GramPerMole, "GramsPerMole", BaseUnits.Undefined, "MolarMass"), + new UnitInfo(MolarMassUnit.GramPerMole, "GramsPerMole", new BaseUnits(mass: MassUnit.Gram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), new UnitInfo(MolarMassUnit.HectogramPerMole, "HectogramsPerMole", BaseUnits.Undefined, "MolarMass"), - new UnitInfo(MolarMassUnit.KilogramPerKilomole, "KilogramsPerKilomole", BaseUnits.Undefined, "MolarMass"), + new UnitInfo(MolarMassUnit.KilogramPerKilomole, "KilogramsPerKilomole", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Kilomole), "MolarMass"), new UnitInfo(MolarMassUnit.KilogramPerMole, "KilogramsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.KilopoundPerMole, "KilopoundsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.MegapoundPerMole, "MegapoundsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.MicrogramPerMole, "MicrogramsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.MilligramPerMole, "MilligramsPerMole", BaseUnits.Undefined, "MolarMass"), new UnitInfo(MolarMassUnit.NanogramPerMole, "NanogramsPerMole", BaseUnits.Undefined, "MolarMass"), - new UnitInfo(MolarMassUnit.PoundPerMole, "PoundsPerMole", BaseUnits.Undefined, "MolarMass"), + new UnitInfo(MolarMassUnit.PoundPerMole, "PoundsPerMole", new BaseUnits(mass: MassUnit.Pound, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), }, BaseUnit, Zero, BaseDimensions); @@ -119,13 +119,8 @@ public MolarMass(double value, MolarMassUnit unit) /// No unit was found for the given . public MolarMass(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -856,25 +851,7 @@ public double As(MolarMassUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MolarMassUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarMassUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -975,28 +952,29 @@ private bool TryToUnit(MolarMassUnit unit, [NotNullWhen(true)] out MolarMass? co return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public MolarMass ToUnit(UnitSystem unitSystem) { - if (!(unit is MolarMassUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarMassUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public MolarMass ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MolarMassUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarMassUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolarMassUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarMassUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1010,6 +988,8 @@ public MolarMass ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index acf94a9c67..6e9f863d9a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -122,13 +122,8 @@ public Molarity(double value, MolarityUnit unit) /// No unit was found for the given . public Molarity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -841,25 +836,7 @@ public double As(MolarityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is MolarityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -956,28 +933,29 @@ private bool TryToUnit(MolarityUnit unit, [NotNullWhen(true)] out Molarity? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Molarity ToUnit(UnitSystem unitSystem) { - if (!(unit is MolarityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Molarity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not MolarityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is MolarityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -991,6 +969,8 @@ public Molarity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs index b62c7f271c..5c7f960069 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs @@ -76,7 +76,7 @@ static Permeability() Info = new QuantityInfo("Permeability", new UnitInfo[] { - new UnitInfo(PermeabilityUnit.HenryPerMeter, "HenriesPerMeter", BaseUnits.Undefined, "Permeability"), + new UnitInfo(PermeabilityUnit.HenryPerMeter, "HenriesPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "Permeability"), }, BaseUnit, Zero, BaseDimensions); @@ -105,13 +105,8 @@ public Permeability(double value, PermeabilityUnit unit) /// No unit was found for the given . public Permeability(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -640,25 +635,7 @@ public double As(PermeabilityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PermeabilityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermeabilityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +712,29 @@ private bool TryToUnit(PermeabilityUnit unit, [NotNullWhen(true)] out Permeabili return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Permeability ToUnit(UnitSystem unitSystem) { - if (!(unit is PermeabilityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermeabilityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Permeability ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PermeabilityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermeabilityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PermeabilityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermeabilityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +748,8 @@ public Permeability ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs index 6aa79acd0e..4383a6ed83 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs @@ -76,7 +76,7 @@ static Permittivity() Info = new QuantityInfo("Permittivity", new UnitInfo[] { - new UnitInfo(PermittivityUnit.FaradPerMeter, "FaradsPerMeter", BaseUnits.Undefined, "Permittivity"), + new UnitInfo(PermittivityUnit.FaradPerMeter, "FaradsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "Permittivity"), }, BaseUnit, Zero, BaseDimensions); @@ -105,13 +105,8 @@ public Permittivity(double value, PermittivityUnit unit) /// No unit was found for the given . public Permittivity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -640,25 +635,7 @@ public double As(PermittivityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PermittivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermittivityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +712,29 @@ private bool TryToUnit(PermittivityUnit unit, [NotNullWhen(true)] out Permittivi return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Permittivity ToUnit(UnitSystem unitSystem) { - if (!(unit is PermittivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermittivityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Permittivity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PermittivityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermittivityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PermittivityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermittivityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +748,8 @@ public Permittivity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs index 537d7ce3dd..f17e84f4e8 100644 --- a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs @@ -109,13 +109,8 @@ public PorousMediumPermeability(double value, PorousMediumPermeabilityUnit unit) /// No unit was found for the given . public PorousMediumPermeability(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -704,25 +699,7 @@ public double As(PorousMediumPermeabilityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PorousMediumPermeabilityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PorousMediumPermeabilityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -807,28 +784,29 @@ private bool TryToUnit(PorousMediumPermeabilityUnit unit, [NotNullWhen(true)] ou return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public PorousMediumPermeability ToUnit(UnitSystem unitSystem) { - if (!(unit is PorousMediumPermeabilityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PorousMediumPermeabilityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public PorousMediumPermeability ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PorousMediumPermeabilityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PorousMediumPermeabilityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PorousMediumPermeabilityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PorousMediumPermeabilityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -842,6 +820,8 @@ public PorousMediumPermeability ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index 35361409e3..9f7cf412bd 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -144,13 +144,8 @@ public Power(double value, PowerUnit unit) /// No unit was found for the given . public Power(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1157,25 +1152,7 @@ public double As(PowerUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1304,28 +1281,29 @@ private bool TryToUnit(PowerUnit unit, [NotNullWhen(true)] out Power? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Power ToUnit(UnitSystem unitSystem) { - if (!(unit is PowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Power ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PowerUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1339,6 +1317,8 @@ public Power ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs index 9131620116..e33eaf209e 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs @@ -145,13 +145,8 @@ public PowerDensity(double value, PowerDensityUnit unit) /// No unit was found for the given . public PowerDensity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1325,25 +1320,7 @@ public double As(PowerDensityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PowerDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerDensityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1506,28 +1483,29 @@ private bool TryToUnit(PowerDensityUnit unit, [NotNullWhen(true)] out PowerDensi return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public PowerDensity ToUnit(UnitSystem unitSystem) { - if (!(unit is PowerDensityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerDensityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public PowerDensity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PowerDensityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerDensityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PowerDensityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerDensityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1541,6 +1519,8 @@ public PowerDensity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs index df55289635..1b98d9cf78 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs @@ -93,25 +93,6 @@ public PowerRatio(double value, PowerRatioUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public PowerRatio(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -661,25 +642,7 @@ public double As(PowerRatioUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PowerRatioUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerRatioUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -758,28 +721,29 @@ private bool TryToUnit(PowerRatioUnit unit, [NotNullWhen(true)] out PowerRatio? return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public PowerRatio ToUnit(UnitSystem unitSystem) { - if (!(unit is PowerRatioUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerRatioUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public PowerRatio ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PowerRatioUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerRatioUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PowerRatioUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerRatioUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -793,6 +757,8 @@ public PowerRatio ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index 49151ac5d0..428b9d2be9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -99,7 +99,7 @@ static Pressure() new UnitInfo(PressureUnit.InchOfMercury, "InchesOfMercury", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.InchOfWaterColumn, "InchesOfWaterColumn", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.Kilobar, "Kilobars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilogramForcePerSquareCentimeter, "KilogramsForcePerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), + new UnitInfo(PressureUnit.KilogramForcePerSquareCentimeter, "KilogramsForcePerSquareCentimeter", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.KilogramForcePerSquareMeter, "KilogramsForcePerSquareMeter", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.KilogramForcePerSquareMillimeter, "KilogramsForcePerSquareMillimeter", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.KilonewtonPerSquareCentimeter, "KilonewtonsPerSquareCentimeter", BaseUnits.Undefined, "Pressure"), @@ -122,17 +122,17 @@ static Pressure() new UnitInfo(PressureUnit.MillimeterOfWaterColumn, "MillimetersOfWaterColumn", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.Millipascal, "Millipascals", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.NewtonPerSquareCentimeter, "NewtonsPerSquareCentimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.NewtonPerSquareMeter, "NewtonsPerSquareMeter", BaseUnits.Undefined, "Pressure"), + new UnitInfo(PressureUnit.NewtonPerSquareMeter, "NewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), new UnitInfo(PressureUnit.NewtonPerSquareMillimeter, "NewtonsPerSquareMillimeter", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.Pascal, "Pascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.PoundForcePerSquareFoot, "PoundsForcePerSquareFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.PoundForcePerSquareInch, "PoundsForcePerSquareInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.PoundForcePerSquareMil, "PoundsForcePerSquareMil", new BaseUnits(length: LengthUnit.Mil, mass: MassUnit.Pound, time: DurationUnit.Second), "Pressure"), + new UnitInfo(PressureUnit.PoundForcePerSquareFoot, "PoundsForcePerSquareFoot", BaseUnits.Undefined, "Pressure"), + new UnitInfo(PressureUnit.PoundForcePerSquareInch, "PoundsForcePerSquareInch", BaseUnits.Undefined, "Pressure"), + new UnitInfo(PressureUnit.PoundForcePerSquareMil, "PoundsForcePerSquareMil", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.PoundPerInchSecondSquared, "PoundsPerInchSecondSquared", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.TechnicalAtmosphere, "TechnicalAtmospheres", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.TonneForcePerSquareCentimeter, "TonnesForcePerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.TonneForcePerSquareMeter, "TonnesForcePerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.TonneForcePerSquareMillimeter, "TonnesForcePerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne, time: DurationUnit.Second), "Pressure"), + new UnitInfo(PressureUnit.TonneForcePerSquareCentimeter, "TonnesForcePerSquareCentimeter", BaseUnits.Undefined, "Pressure"), + new UnitInfo(PressureUnit.TonneForcePerSquareMeter, "TonnesForcePerSquareMeter", BaseUnits.Undefined, "Pressure"), + new UnitInfo(PressureUnit.TonneForcePerSquareMillimeter, "TonnesForcePerSquareMillimeter", BaseUnits.Undefined, "Pressure"), new UnitInfo(PressureUnit.Torr, "Torrs", BaseUnits.Undefined, "Pressure"), }, BaseUnit, Zero, BaseDimensions); @@ -162,13 +162,8 @@ public Pressure(double value, PressureUnit unit) /// No unit was found for the given . public Pressure(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1481,25 +1476,7 @@ public double As(PressureUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PressureUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1672,28 +1649,29 @@ private bool TryToUnit(PressureUnit unit, [NotNullWhen(true)] out Pressure? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Pressure ToUnit(UnitSystem unitSystem) { - if (!(unit is PressureUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Pressure ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PressureUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PressureUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1707,6 +1685,8 @@ public Pressure ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs index a3fd7b60d8..c8063f865f 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs @@ -122,13 +122,8 @@ public PressureChangeRate(double value, PressureChangeRateUnit unit) /// No unit was found for the given . public PressureChangeRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -922,25 +917,7 @@ public double As(PressureChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is PressureChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureChangeRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1051,28 +1028,29 @@ private bool TryToUnit(PressureChangeRateUnit unit, [NotNullWhen(true)] out Pres return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public PressureChangeRate ToUnit(UnitSystem unitSystem) { - if (!(unit is PressureChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureChangeRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public PressureChangeRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not PressureChangeRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureChangeRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is PressureChangeRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1086,6 +1064,8 @@ public PressureChangeRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs index 0fba853820..12f93efe35 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs @@ -111,13 +111,8 @@ public RadiationEquivalentDose(double value, RadiationEquivalentDoseUnit unit) /// No unit was found for the given . public RadiationEquivalentDose(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -737,25 +732,7 @@ public double As(RadiationEquivalentDoseUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RadiationEquivalentDoseUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -842,28 +819,29 @@ private bool TryToUnit(RadiationEquivalentDoseUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RadiationEquivalentDose ToUnit(UnitSystem unitSystem) { - if (!(unit is RadiationEquivalentDoseUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RadiationEquivalentDose ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RadiationEquivalentDoseUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RadiationEquivalentDoseUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -877,6 +855,8 @@ public RadiationEquivalentDose ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs index da6b630d8f..4216744e40 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs @@ -85,7 +85,7 @@ static RadiationEquivalentDoseRate() new UnitInfo(RadiationEquivalentDoseRateUnit.NanosievertPerSecond, "NanosievertsPerSecond", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), new UnitInfo(RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, "RoentgensEquivalentManPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), new UnitInfo(RadiationEquivalentDoseRateUnit.SievertPerHour, "SievertsPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.SievertPerSecond, "SievertsPerSecond", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), + new UnitInfo(RadiationEquivalentDoseRateUnit.SievertPerSecond, "SievertsPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "RadiationEquivalentDoseRate"), }, BaseUnit, Zero, BaseDimensions); @@ -114,13 +114,8 @@ public RadiationEquivalentDoseRate(double value, RadiationEquivalentDoseRateUnit /// No unit was found for the given . public RadiationEquivalentDoseRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -794,25 +789,7 @@ public double As(RadiationEquivalentDoseRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RadiationEquivalentDoseRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -907,28 +884,29 @@ private bool TryToUnit(RadiationEquivalentDoseRateUnit unit, [NotNullWhen(true)] return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RadiationEquivalentDoseRate ToUnit(UnitSystem unitSystem) { - if (!(unit is RadiationEquivalentDoseRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RadiationEquivalentDoseRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RadiationEquivalentDoseRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RadiationEquivalentDoseRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationEquivalentDoseRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -942,6 +920,8 @@ public RadiationEquivalentDoseRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs index 346fe5364b..2db5f66572 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs @@ -109,13 +109,8 @@ public RadiationExposure(double value, RadiationExposureUnit unit) /// No unit was found for the given . public RadiationExposure(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -749,25 +744,7 @@ public double As(RadiationExposureUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RadiationExposureUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -858,28 +835,29 @@ private bool TryToUnit(RadiationExposureUnit unit, [NotNullWhen(true)] out Radia return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RadiationExposure ToUnit(UnitSystem unitSystem) { - if (!(unit is RadiationExposureUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RadiationExposure ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RadiationExposureUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RadiationExposureUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -893,6 +871,8 @@ public RadiationExposure ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs index 6d1027aa15..04633c45e2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs @@ -130,13 +130,8 @@ public Radioactivity(double value, RadioactivityUnit unit) /// No unit was found for the given . public Radioactivity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1085,25 +1080,7 @@ public double As(RadioactivityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RadioactivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadioactivityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1236,28 +1213,29 @@ private bool TryToUnit(RadioactivityUnit unit, [NotNullWhen(true)] out Radioacti return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Radioactivity ToUnit(UnitSystem unitSystem) { - if (!(unit is RadioactivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadioactivityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Radioactivity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RadioactivityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadioactivityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RadioactivityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadioactivityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1271,6 +1249,8 @@ public Radioactivity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs index e506a1f2b4..61d01c71be 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs @@ -97,25 +97,6 @@ public Ratio(double value, RatioUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public Ratio(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -717,25 +698,7 @@ public double As(RatioUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RatioUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -822,28 +785,29 @@ private bool TryToUnit(RatioUnit unit, [NotNullWhen(true)] out Ratio? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Ratio ToUnit(UnitSystem unitSystem) { - if (!(unit is RatioUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Ratio ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RatioUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RatioUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -857,6 +821,8 @@ public Ratio ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs index de937910a2..28035c2af5 100644 --- a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs @@ -73,7 +73,7 @@ static RatioChangeRate() Info = new QuantityInfo("RatioChangeRate", new UnitInfo[] { - new UnitInfo(RatioChangeRateUnit.DecimalFractionPerSecond, "DecimalFractionsPerSecond", BaseUnits.Undefined, "RatioChangeRate"), + new UnitInfo(RatioChangeRateUnit.DecimalFractionPerSecond, "DecimalFractionsPerSecond", new BaseUnits(time: DurationUnit.Second), "RatioChangeRate"), new UnitInfo(RatioChangeRateUnit.PercentPerSecond, "PercentsPerSecond", BaseUnits.Undefined, "RatioChangeRate"), }, BaseUnit, Zero, BaseDimensions); @@ -103,13 +103,8 @@ public RatioChangeRate(double value, RatioChangeRateUnit unit) /// No unit was found for the given . public RatioChangeRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -653,25 +648,7 @@ public double As(RatioChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RatioChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioChangeRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -750,28 +727,29 @@ private bool TryToUnit(RatioChangeRateUnit unit, [NotNullWhen(true)] out RatioCh return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RatioChangeRate ToUnit(UnitSystem unitSystem) { - if (!(unit is RatioChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioChangeRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RatioChangeRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RatioChangeRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioChangeRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RatioChangeRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -785,6 +763,8 @@ public RatioChangeRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs index a0e332617c..6ec194d1be 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs @@ -83,17 +83,17 @@ static ReciprocalArea() Info = new QuantityInfo("ReciprocalArea", new UnitInfo[] { - new UnitInfo(ReciprocalAreaUnit.InverseSquareCentimeter, "InverseSquareCentimeters", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareDecimeter, "InverseSquareDecimeters", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareFoot, "InverseSquareFeet", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareInch, "InverseSquareInches", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareKilometer, "InverseSquareKilometers", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMeter, "InverseSquareMeters", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMicrometer, "InverseSquareMicrometers", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMile, "InverseSquareMiles", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMillimeter, "InverseSquareMillimeters", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareYard, "InverseSquareYards", BaseUnits.Undefined, "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseUsSurveySquareFoot, "InverseUsSurveySquareFeet", BaseUnits.Undefined, "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareCentimeter, "InverseSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareDecimeter, "InverseSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareFoot, "InverseSquareFeet", new BaseUnits(length: LengthUnit.Foot), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareInch, "InverseSquareInches", new BaseUnits(length: LengthUnit.Inch), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareKilometer, "InverseSquareKilometers", new BaseUnits(length: LengthUnit.Kilometer), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareMeter, "InverseSquareMeters", new BaseUnits(length: LengthUnit.Meter), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareMicrometer, "InverseSquareMicrometers", new BaseUnits(length: LengthUnit.Micrometer), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareMile, "InverseSquareMiles", new BaseUnits(length: LengthUnit.Mile), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareMillimeter, "InverseSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseSquareYard, "InverseSquareYards", new BaseUnits(length: LengthUnit.Yard), "ReciprocalArea"), + new UnitInfo(ReciprocalAreaUnit.InverseUsSurveySquareFoot, "InverseUsSurveySquareFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot), "ReciprocalArea"), }, BaseUnit, Zero, BaseDimensions); @@ -122,13 +122,8 @@ public ReciprocalArea(double value, ReciprocalAreaUnit unit) /// No unit was found for the given . public ReciprocalArea(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -848,25 +843,7 @@ public double As(ReciprocalAreaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ReciprocalAreaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalAreaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -963,28 +940,29 @@ private bool TryToUnit(ReciprocalAreaUnit unit, [NotNullWhen(true)] out Reciproc return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ReciprocalArea ToUnit(UnitSystem unitSystem) { - if (!(unit is ReciprocalAreaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalAreaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ReciprocalArea ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ReciprocalAreaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalAreaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ReciprocalAreaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalAreaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -998,6 +976,8 @@ public ReciprocalArea ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index 38e3679662..c6d5dfd42f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -85,16 +85,16 @@ static ReciprocalLength() Info = new QuantityInfo("ReciprocalLength", new UnitInfo[] { - new UnitInfo(ReciprocalLengthUnit.InverseCentimeter, "InverseCentimeters", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseFoot, "InverseFeet", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseInch, "InverseInches", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMeter, "InverseMeters", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMicroinch, "InverseMicroinches", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMil, "InverseMils", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMile, "InverseMiles", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMillimeter, "InverseMillimeters", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseUsSurveyFoot, "InverseUsSurveyFeet", BaseUnits.Undefined, "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseYard, "InverseYards", BaseUnits.Undefined, "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseCentimeter, "InverseCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseFoot, "InverseFeet", new BaseUnits(length: LengthUnit.Foot), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseInch, "InverseInches", new BaseUnits(length: LengthUnit.Inch), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseMeter, "InverseMeters", new BaseUnits(length: LengthUnit.Meter), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseMicroinch, "InverseMicroinches", new BaseUnits(length: LengthUnit.Microinch), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseMil, "InverseMils", new BaseUnits(length: LengthUnit.Mil), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseMile, "InverseMiles", new BaseUnits(length: LengthUnit.Mile), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseMillimeter, "InverseMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseUsSurveyFoot, "InverseUsSurveyFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot), "ReciprocalLength"), + new UnitInfo(ReciprocalLengthUnit.InverseYard, "InverseYards", new BaseUnits(length: LengthUnit.Yard), "ReciprocalLength"), }, BaseUnit, Zero, BaseDimensions); @@ -123,13 +123,8 @@ public ReciprocalLength(double value, ReciprocalLengthUnit unit) /// No unit was found for the given . public ReciprocalLength(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -846,25 +841,7 @@ public double As(ReciprocalLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ReciprocalLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalLengthUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -959,28 +936,29 @@ private bool TryToUnit(ReciprocalLengthUnit unit, [NotNullWhen(true)] out Recipr return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ReciprocalLength ToUnit(UnitSystem unitSystem) { - if (!(unit is ReciprocalLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalLengthUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ReciprocalLength ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ReciprocalLengthUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalLengthUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ReciprocalLengthUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReciprocalLengthUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -994,6 +972,8 @@ public ReciprocalLength ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs index 50b34bc085..b14795608b 100644 --- a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs @@ -92,25 +92,6 @@ public RelativeHumidity(double value, RelativeHumidityUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public RelativeHumidity(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -637,25 +618,7 @@ public double As(RelativeHumidityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RelativeHumidityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RelativeHumidityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -732,28 +695,29 @@ private bool TryToUnit(RelativeHumidityUnit unit, [NotNullWhen(true)] out Relati return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RelativeHumidity ToUnit(UnitSystem unitSystem) { - if (!(unit is RelativeHumidityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RelativeHumidityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RelativeHumidity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RelativeHumidityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RelativeHumidityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RelativeHumidityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RelativeHumidityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -767,6 +731,8 @@ public RelativeHumidity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs index cbab003998..fd96df6886 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs @@ -74,7 +74,7 @@ static RotationalAcceleration() new UnitInfo[] { new UnitInfo(RotationalAccelerationUnit.DegreePerSecondSquared, "DegreesPerSecondSquared", BaseUnits.Undefined, "RotationalAcceleration"), - new UnitInfo(RotationalAccelerationUnit.RadianPerSecondSquared, "RadiansPerSecondSquared", BaseUnits.Undefined, "RotationalAcceleration"), + new UnitInfo(RotationalAccelerationUnit.RadianPerSecondSquared, "RadiansPerSecondSquared", new BaseUnits(time: DurationUnit.Second), "RotationalAcceleration"), new UnitInfo(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, "RevolutionsPerMinutePerSecond", BaseUnits.Undefined, "RotationalAcceleration"), new UnitInfo(RotationalAccelerationUnit.RevolutionPerSecondSquared, "RevolutionsPerSecondSquared", BaseUnits.Undefined, "RotationalAcceleration"), }, @@ -105,13 +105,8 @@ public RotationalAcceleration(double value, RotationalAccelerationUnit unit) /// No unit was found for the given . public RotationalAcceleration(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -685,25 +680,7 @@ public double As(RotationalAccelerationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RotationalAccelerationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalAccelerationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -786,28 +763,29 @@ private bool TryToUnit(RotationalAccelerationUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RotationalAcceleration ToUnit(UnitSystem unitSystem) { - if (!(unit is RotationalAccelerationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalAccelerationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RotationalAcceleration ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RotationalAccelerationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalAccelerationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RotationalAccelerationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalAccelerationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -821,6 +799,8 @@ public RotationalAcceleration ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index b69cedc1fc..f9da7d6283 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -87,7 +87,7 @@ static RotationalSpeed() new UnitInfo(RotationalSpeedUnit.MilliradianPerSecond, "MilliradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), new UnitInfo(RotationalSpeedUnit.NanodegreePerSecond, "NanodegreesPerSecond", BaseUnits.Undefined, "RotationalSpeed"), new UnitInfo(RotationalSpeedUnit.NanoradianPerSecond, "NanoradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.RadianPerSecond, "RadiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), + new UnitInfo(RotationalSpeedUnit.RadianPerSecond, "RadiansPerSecond", new BaseUnits(time: DurationUnit.Second), "RotationalSpeed"), new UnitInfo(RotationalSpeedUnit.RevolutionPerMinute, "RevolutionsPerMinute", BaseUnits.Undefined, "RotationalSpeed"), new UnitInfo(RotationalSpeedUnit.RevolutionPerSecond, "RevolutionsPerSecond", BaseUnits.Undefined, "RotationalSpeed"), }, @@ -118,13 +118,8 @@ public RotationalSpeed(double value, RotationalSpeedUnit unit) /// No unit was found for the given . public RotationalSpeed(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -849,25 +844,7 @@ public double As(RotationalSpeedUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RotationalSpeedUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalSpeedUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -968,28 +945,29 @@ private bool TryToUnit(RotationalSpeedUnit unit, [NotNullWhen(true)] out Rotatio return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RotationalSpeed ToUnit(UnitSystem unitSystem) { - if (!(unit is RotationalSpeedUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalSpeedUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RotationalSpeed ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RotationalSpeedUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalSpeedUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RotationalSpeedUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalSpeedUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1003,6 +981,8 @@ public RotationalSpeed ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs index 188c559fa8..9bed04d86f 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs @@ -106,7 +106,7 @@ static RotationalStiffness() new UnitInfo(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, "NanonewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), new UnitInfo(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, "NanonewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), new UnitInfo(RotationalStiffnessUnit.NewtonMeterPerDegree, "NewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NewtonMeterPerRadian, "NewtonMetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), + new UnitInfo(RotationalStiffnessUnit.NewtonMeterPerRadian, "NewtonMetersPerRadian", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffness"), new UnitInfo(RotationalStiffnessUnit.NewtonMillimeterPerDegree, "NewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), new UnitInfo(RotationalStiffnessUnit.NewtonMillimeterPerRadian, "NewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), new UnitInfo(RotationalStiffnessUnit.PoundForceFeetPerRadian, "PoundForceFeetPerRadian", BaseUnits.Undefined, "RotationalStiffness"), @@ -139,13 +139,8 @@ public RotationalStiffness(double value, RotationalStiffnessUnit unit) /// No unit was found for the given . public RotationalStiffness(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1176,25 +1171,7 @@ public double As(RotationalStiffnessUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RotationalStiffnessUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1335,28 +1312,29 @@ private bool TryToUnit(RotationalStiffnessUnit unit, [NotNullWhen(true)] out Rot return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RotationalStiffness ToUnit(UnitSystem unitSystem) { - if (!(unit is RotationalStiffnessUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RotationalStiffness ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RotationalStiffnessUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RotationalStiffnessUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1370,6 +1348,8 @@ public RotationalStiffness ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs index 84bdb784db..30b61a9b07 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs @@ -79,7 +79,7 @@ static RotationalStiffnessPerLength() new UnitInfo(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, "KilonewtonMetersPerRadianPerMeter", BaseUnits.Undefined, "RotationalStiffnessPerLength"), new UnitInfo(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, "KilopoundForceFeetPerDegreesPerFeet", BaseUnits.Undefined, "RotationalStiffnessPerLength"), new UnitInfo(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, "MeganewtonMetersPerRadianPerMeter", BaseUnits.Undefined, "RotationalStiffnessPerLength"), - new UnitInfo(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, "NewtonMetersPerRadianPerMeter", BaseUnits.Undefined, "RotationalStiffnessPerLength"), + new UnitInfo(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, "NewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffnessPerLength"), new UnitInfo(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, "PoundForceFeetPerDegreesPerFeet", BaseUnits.Undefined, "RotationalStiffnessPerLength"), }, BaseUnit, Zero, BaseDimensions); @@ -109,13 +109,8 @@ public RotationalStiffnessPerLength(double value, RotationalStiffnessPerLengthUn /// No unit was found for the given . public RotationalStiffnessPerLength(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -714,25 +709,7 @@ public double As(RotationalStiffnessPerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is RotationalStiffnessPerLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessPerLengthUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -817,28 +794,29 @@ private bool TryToUnit(RotationalStiffnessPerLengthUnit unit, [NotNullWhen(true) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public RotationalStiffnessPerLength ToUnit(UnitSystem unitSystem) { - if (!(unit is RotationalStiffnessPerLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessPerLengthUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public RotationalStiffnessPerLength ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not RotationalStiffnessPerLengthUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessPerLengthUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RotationalStiffnessPerLengthUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessPerLengthUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -852,6 +830,8 @@ public RotationalStiffnessPerLength ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs index 92493d7493..3c5bdc3153 100644 --- a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs @@ -92,25 +92,6 @@ public Scalar(double value, ScalarUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public Scalar(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -637,25 +618,7 @@ public double As(ScalarUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ScalarUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ScalarUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -732,28 +695,29 @@ private bool TryToUnit(ScalarUnit unit, [NotNullWhen(true)] out Scalar? converte return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Scalar ToUnit(UnitSystem unitSystem) { - if (!(unit is ScalarUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ScalarUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Scalar ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ScalarUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ScalarUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ScalarUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ScalarUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -767,6 +731,8 @@ public Scalar ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs index fec6ca3157..d9579a9bec 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs @@ -95,25 +95,6 @@ public SolidAngle(double value, SolidAngleUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public SolidAngle(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -640,25 +621,7 @@ public double As(SolidAngleUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SolidAngleUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SolidAngleUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +698,29 @@ private bool TryToUnit(SolidAngleUnit unit, [NotNullWhen(true)] out SolidAngle? return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public SolidAngle ToUnit(UnitSystem unitSystem) { - if (!(unit is SolidAngleUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SolidAngleUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public SolidAngle ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SolidAngleUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SolidAngleUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SolidAngleUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SolidAngleUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +734,8 @@ public SolidAngle ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs index 0e15994478..9e3b4ef753 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs @@ -91,7 +91,7 @@ static SpecificEnergy() new UnitInfo(SpecificEnergyUnit.GigawattDayPerTonne, "GigawattDaysPerTonne", BaseUnits.Undefined, "SpecificEnergy"), new UnitInfo(SpecificEnergyUnit.GigawattHourPerKilogram, "GigawattHoursPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), new UnitInfo(SpecificEnergyUnit.GigawattHourPerPound, "GigawattHoursPerPound", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.JoulePerKilogram, "JoulesPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), + new UnitInfo(SpecificEnergyUnit.JoulePerKilogram, "JoulesPerKilogram", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "SpecificEnergy"), new UnitInfo(SpecificEnergyUnit.KilocaloriePerGram, "KilocaloriesPerGram", BaseUnits.Undefined, "SpecificEnergy"), new UnitInfo(SpecificEnergyUnit.KilojoulePerKilogram, "KilojoulesPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), new UnitInfo(SpecificEnergyUnit.KilowattDayPerKilogram, "KilowattDaysPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), @@ -142,13 +142,8 @@ public SpecificEnergy(double value, SpecificEnergyUnit unit) /// No unit was found for the given . public SpecificEnergy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1158,25 +1153,7 @@ public double As(SpecificEnergyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SpecificEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1311,28 +1288,29 @@ private bool TryToUnit(SpecificEnergyUnit unit, [NotNullWhen(true)] out Specific return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public SpecificEnergy ToUnit(UnitSystem unitSystem) { - if (!(unit is SpecificEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public SpecificEnergy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SpecificEnergyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEnergyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SpecificEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEnergyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1346,6 +1324,8 @@ public SpecificEnergy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs index 2ec5620495..94ba3b214a 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs @@ -79,8 +79,8 @@ static SpecificEntropy() { new UnitInfo(SpecificEntropyUnit.BtuPerPoundFahrenheit, "BtusPerPoundFahrenheit", BaseUnits.Undefined, "SpecificEntropy"), new UnitInfo(SpecificEntropyUnit.CaloriePerGramKelvin, "CaloriesPerGramKelvin", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, "JoulesPerKilogramDegreeCelsius", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.JoulePerKilogramKelvin, "JoulesPerKilogramKelvin", BaseUnits.Undefined, "SpecificEntropy"), + new UnitInfo(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, "JoulesPerKilogramDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "SpecificEntropy"), + new UnitInfo(SpecificEntropyUnit.JoulePerKilogramKelvin, "JoulesPerKilogramKelvin", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "SpecificEntropy"), new UnitInfo(SpecificEntropyUnit.KilocaloriePerGramKelvin, "KilocaloriesPerGramKelvin", BaseUnits.Undefined, "SpecificEntropy"), new UnitInfo(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, "KilojoulesPerKilogramDegreeCelsius", BaseUnits.Undefined, "SpecificEntropy"), new UnitInfo(SpecificEntropyUnit.KilojoulePerKilogramKelvin, "KilojoulesPerKilogramKelvin", BaseUnits.Undefined, "SpecificEntropy"), @@ -114,13 +114,8 @@ public SpecificEntropy(double value, SpecificEntropyUnit unit) /// No unit was found for the given . public SpecificEntropy(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -785,25 +780,7 @@ public double As(SpecificEntropyUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SpecificEntropyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEntropyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -896,28 +873,29 @@ private bool TryToUnit(SpecificEntropyUnit unit, [NotNullWhen(true)] out Specifi return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public SpecificEntropy ToUnit(UnitSystem unitSystem) { - if (!(unit is SpecificEntropyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEntropyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public SpecificEntropy ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SpecificEntropyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEntropyUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SpecificEntropyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEntropyUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -931,6 +909,8 @@ public SpecificEntropy ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs index 001138f7c1..20391038f6 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs @@ -69,14 +69,14 @@ namespace UnitsNet static SpecificFuelConsumption() { - BaseDimensions = BaseDimensions.Dimensionless; + BaseDimensions = new BaseDimensions(-1, 0, 1, 0, 0, 0, 0); BaseUnit = SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond; Units = Enum.GetValues(typeof(SpecificFuelConsumptionUnit)).Cast().ToArray(); Zero = new SpecificFuelConsumption(0, BaseUnit); Info = new QuantityInfo("SpecificFuelConsumption", new UnitInfo[] { - new UnitInfo(SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, "GramsPerKiloNewtonSecond", BaseUnits.Undefined, "SpecificFuelConsumption"), + new UnitInfo(SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, "GramsPerKiloNewtonSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "SpecificFuelConsumption"), new UnitInfo(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, "KilogramsPerKilogramForceHour", BaseUnits.Undefined, "SpecificFuelConsumption"), new UnitInfo(SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond, "KilogramsPerKiloNewtonSecond", BaseUnits.Undefined, "SpecificFuelConsumption"), new UnitInfo(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, "PoundsMassPerPoundForceHour", BaseUnits.Undefined, "SpecificFuelConsumption"), @@ -108,13 +108,8 @@ public SpecificFuelConsumption(double value, SpecificFuelConsumptionUnit unit) /// No unit was found for the given . public SpecificFuelConsumption(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -688,25 +683,7 @@ public double As(SpecificFuelConsumptionUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SpecificFuelConsumptionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -789,28 +766,29 @@ private bool TryToUnit(SpecificFuelConsumptionUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public SpecificFuelConsumption ToUnit(UnitSystem unitSystem) { - if (!(unit is SpecificFuelConsumptionUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public SpecificFuelConsumption ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SpecificFuelConsumptionUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SpecificFuelConsumptionUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -824,6 +802,8 @@ public SpecificFuelConsumption ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs index a8ffc3b923..2b5f9a5a89 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs @@ -76,8 +76,8 @@ static SpecificVolume() Info = new QuantityInfo("SpecificVolume", new UnitInfo[] { - new UnitInfo(SpecificVolumeUnit.CubicFootPerPound, "CubicFeetPerPound", BaseUnits.Undefined, "SpecificVolume"), - new UnitInfo(SpecificVolumeUnit.CubicMeterPerKilogram, "CubicMetersPerKilogram", BaseUnits.Undefined, "SpecificVolume"), + new UnitInfo(SpecificVolumeUnit.CubicFootPerPound, "CubicFeetPerPound", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "SpecificVolume"), + new UnitInfo(SpecificVolumeUnit.CubicMeterPerKilogram, "CubicMetersPerKilogram", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "SpecificVolume"), new UnitInfo(SpecificVolumeUnit.MillicubicMeterPerKilogram, "MillicubicMetersPerKilogram", BaseUnits.Undefined, "SpecificVolume"), }, BaseUnit, Zero, BaseDimensions); @@ -107,13 +107,8 @@ public SpecificVolume(double value, SpecificVolumeUnit unit) /// No unit was found for the given . public SpecificVolume(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -689,25 +684,7 @@ public double As(SpecificVolumeUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SpecificVolumeUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificVolumeUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -788,28 +765,29 @@ private bool TryToUnit(SpecificVolumeUnit unit, [NotNullWhen(true)] out Specific return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public SpecificVolume ToUnit(UnitSystem unitSystem) { - if (!(unit is SpecificVolumeUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificVolumeUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public SpecificVolume ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SpecificVolumeUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificVolumeUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SpecificVolumeUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificVolumeUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -823,6 +801,8 @@ public SpecificVolume ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs index eb8a6572b6..edd2554ffd 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs @@ -92,7 +92,7 @@ static SpecificWeight() new UnitInfo(SpecificWeightUnit.KilopoundForcePerCubicInch, "KilopoundsForcePerCubicInch", BaseUnits.Undefined, "SpecificWeight"), new UnitInfo(SpecificWeightUnit.MeganewtonPerCubicMeter, "MeganewtonsPerCubicMeter", BaseUnits.Undefined, "SpecificWeight"), new UnitInfo(SpecificWeightUnit.NewtonPerCubicCentimeter, "NewtonsPerCubicCentimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.NewtonPerCubicMeter, "NewtonsPerCubicMeter", BaseUnits.Undefined, "SpecificWeight"), + new UnitInfo(SpecificWeightUnit.NewtonPerCubicMeter, "NewtonsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "SpecificWeight"), new UnitInfo(SpecificWeightUnit.NewtonPerCubicMillimeter, "NewtonsPerCubicMillimeter", BaseUnits.Undefined, "SpecificWeight"), new UnitInfo(SpecificWeightUnit.PoundForcePerCubicFoot, "PoundsForcePerCubicFoot", BaseUnits.Undefined, "SpecificWeight"), new UnitInfo(SpecificWeightUnit.PoundForcePerCubicInch, "PoundsForcePerCubicInch", BaseUnits.Undefined, "SpecificWeight"), @@ -127,13 +127,8 @@ public SpecificWeight(double value, SpecificWeightUnit unit) /// No unit was found for the given . public SpecificWeight(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -930,25 +925,7 @@ public double As(SpecificWeightUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SpecificWeightUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificWeightUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1057,28 +1034,29 @@ private bool TryToUnit(SpecificWeightUnit unit, [NotNullWhen(true)] out Specific return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public SpecificWeight ToUnit(UnitSystem unitSystem) { - if (!(unit is SpecificWeightUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificWeightUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public SpecificWeight ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SpecificWeightUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificWeightUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SpecificWeightUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificWeightUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1092,6 +1070,8 @@ public SpecificWeight ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs index 528334c505..b31e6c76cb 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs @@ -144,13 +144,8 @@ public Speed(double value, SpeedUnit unit) /// No unit was found for the given . public Speed(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1211,25 +1206,7 @@ public double As(SpeedUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is SpeedUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpeedUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1370,28 +1347,29 @@ private bool TryToUnit(SpeedUnit unit, [NotNullWhen(true)] out Speed? converted) return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Speed ToUnit(UnitSystem unitSystem) { - if (!(unit is SpeedUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpeedUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Speed ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not SpeedUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpeedUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is SpeedUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpeedUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1405,6 +1383,8 @@ public Speed ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs index 197672af10..b681817539 100644 --- a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs @@ -73,15 +73,15 @@ static StandardVolumeFlow() Info = new QuantityInfo("StandardVolumeFlow", new UnitInfo[] { - new UnitInfo(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, "StandardCubicCentimetersPerMinute", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerHour, "StandardCubicFeetPerHour", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerMinute, "StandardCubicFeetPerMinute", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerSecond, "StandardCubicFeetPerSecond", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerDay, "StandardCubicMetersPerDay", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerHour, "StandardCubicMetersPerHour", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, "StandardCubicMetersPerMinute", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, "StandardCubicMetersPerSecond", BaseUnits.Undefined, "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardLiterPerMinute, "StandardLitersPerMinute", BaseUnits.Undefined, "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, "StandardCubicCentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerHour, "StandardCubicFeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerMinute, "StandardCubicFeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerSecond, "StandardCubicFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerDay, "StandardCubicMetersPerDay", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Day), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerHour, "StandardCubicMetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, "StandardCubicMetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, "StandardCubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "StandardVolumeFlow"), + new UnitInfo(StandardVolumeFlowUnit.StandardLiterPerMinute, "StandardLitersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute), "StandardVolumeFlow"), }, BaseUnit, Zero, BaseDimensions); @@ -110,13 +110,8 @@ public StandardVolumeFlow(double value, StandardVolumeFlowUnit unit) /// No unit was found for the given . public StandardVolumeFlow(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -765,25 +760,7 @@ public double As(StandardVolumeFlowUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is StandardVolumeFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(StandardVolumeFlowUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -876,28 +853,29 @@ private bool TryToUnit(StandardVolumeFlowUnit unit, [NotNullWhen(true)] out Stan return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public StandardVolumeFlow ToUnit(UnitSystem unitSystem) { - if (!(unit is StandardVolumeFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(StandardVolumeFlowUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public StandardVolumeFlow ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not StandardVolumeFlowUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(StandardVolumeFlowUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is StandardVolumeFlowUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(StandardVolumeFlowUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -911,6 +889,8 @@ public StandardVolumeFlow ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs index 26643d725a..821bee9d94 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs @@ -111,13 +111,8 @@ public Temperature(double value, TemperatureUnit unit) /// No unit was found for the given . public Temperature(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -732,25 +727,7 @@ public double As(TemperatureUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is TemperatureUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -845,28 +822,29 @@ private bool TryToUnit(TemperatureUnit unit, [NotNullWhen(true)] out Temperature return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Temperature ToUnit(UnitSystem unitSystem) { - if (!(unit is TemperatureUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Temperature ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not TemperatureUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is TemperatureUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -880,6 +858,8 @@ public Temperature ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs index f720e628d6..82c2c809e5 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs @@ -80,8 +80,8 @@ static TemperatureChangeRate() new UnitInfo(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, "DecadegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), new UnitInfo(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, "DecidegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerHour, "DegreesCelsiusPerHour", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, "DegreesCelsiusPerMinute", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, "DegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), + new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, "DegreesCelsiusPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.DegreeCelsius), "TemperatureChangeRate"), + new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, "DegreesCelsiusPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "TemperatureChangeRate"), new UnitInfo(TemperatureChangeRateUnit.DegreeFahrenheitPerHour, "DegreesFahrenheitPerHour", BaseUnits.Undefined, "TemperatureChangeRate"), new UnitInfo(TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, "DegreesFahrenheitPerMinute", BaseUnits.Undefined, "TemperatureChangeRate"), new UnitInfo(TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, "DegreesFahrenheitPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), @@ -121,13 +121,8 @@ public TemperatureChangeRate(double value, TemperatureChangeRateUnit unit) /// No unit was found for the given . public TemperatureChangeRate(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -906,25 +901,7 @@ public double As(TemperatureChangeRateUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is TemperatureChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureChangeRateUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1033,28 +1010,29 @@ private bool TryToUnit(TemperatureChangeRateUnit unit, [NotNullWhen(true)] out T return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public TemperatureChangeRate ToUnit(UnitSystem unitSystem) { - if (!(unit is TemperatureChangeRateUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureChangeRateUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public TemperatureChangeRate ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not TemperatureChangeRateUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureChangeRateUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is TemperatureChangeRateUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1068,6 +1046,8 @@ public TemperatureChangeRate ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs index f5225656f3..0a02aca388 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs @@ -82,14 +82,14 @@ static TemperatureDelta() Info = new QuantityInfo("TemperatureDelta", new UnitInfo[] { - new UnitInfo(TemperatureDeltaUnit.DegreeCelsius, "DegreesCelsius", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeDelisle, "DegreesDelisle", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeFahrenheit, "DegreesFahrenheit", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeNewton, "DegreesNewton", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeRankine, "DegreesRankine", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeReaumur, "DegreesReaumur", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeRoemer, "DegreesRoemer", BaseUnits.Undefined, "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.Kelvin, "Kelvins", BaseUnits.Undefined, "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeCelsius, "DegreesCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeDelisle, "DegreesDelisle", new BaseUnits(temperature: TemperatureUnit.DegreeDelisle), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeFahrenheit, "DegreesFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeNewton, "DegreesNewton", new BaseUnits(temperature: TemperatureUnit.DegreeNewton), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeRankine, "DegreesRankine", new BaseUnits(temperature: TemperatureUnit.DegreeRankine), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeReaumur, "DegreesReaumur", new BaseUnits(temperature: TemperatureUnit.DegreeReaumur), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.DegreeRoemer, "DegreesRoemer", new BaseUnits(temperature: TemperatureUnit.DegreeRoemer), "TemperatureDelta"), + new UnitInfo(TemperatureDeltaUnit.Kelvin, "Kelvins", new BaseUnits(temperature: TemperatureUnit.Kelvin), "TemperatureDelta"), new UnitInfo(TemperatureDeltaUnit.MillidegreeCelsius, "MillidegreesCelsius", BaseUnits.Undefined, "TemperatureDelta"), }, BaseUnit, Zero, BaseDimensions); @@ -119,13 +119,8 @@ public TemperatureDelta(double value, TemperatureDeltaUnit unit) /// No unit was found for the given . public TemperatureDelta(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -820,25 +815,7 @@ public double As(TemperatureDeltaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is TemperatureDeltaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureDeltaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -931,28 +908,29 @@ private bool TryToUnit(TemperatureDeltaUnit unit, [NotNullWhen(true)] out Temper return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public TemperatureDelta ToUnit(UnitSystem unitSystem) { - if (!(unit is TemperatureDeltaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureDeltaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public TemperatureDelta ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not TemperatureDeltaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureDeltaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is TemperatureDeltaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureDeltaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -966,6 +944,8 @@ public TemperatureDelta ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs index 08326a2eaf..02afa3cd6f 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs @@ -108,13 +108,8 @@ public TemperatureGradient(double value, TemperatureGradientUnit unit) /// No unit was found for the given . public TemperatureGradient(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -698,25 +693,7 @@ public double As(TemperatureGradientUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is TemperatureGradientUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureGradientUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -799,28 +776,29 @@ private bool TryToUnit(TemperatureGradientUnit unit, [NotNullWhen(true)] out Tem return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public TemperatureGradient ToUnit(UnitSystem unitSystem) { - if (!(unit is TemperatureGradientUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureGradientUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public TemperatureGradient ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not TemperatureGradientUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureGradientUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is TemperatureGradientUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureGradientUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -834,6 +812,8 @@ public TemperatureGradient ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs index 742c6fec00..2bcd45793f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs @@ -77,7 +77,7 @@ static ThermalConductivity() new UnitInfo[] { new UnitInfo(ThermalConductivityUnit.BtuPerHourFootFahrenheit, "BtusPerHourFootFahrenheit", BaseUnits.Undefined, "ThermalConductivity"), - new UnitInfo(ThermalConductivityUnit.WattPerMeterKelvin, "WattsPerMeterKelvin", BaseUnits.Undefined, "ThermalConductivity"), + new UnitInfo(ThermalConductivityUnit.WattPerMeterKelvin, "WattsPerMeterKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "ThermalConductivity"), }, BaseUnit, Zero, BaseDimensions); @@ -106,13 +106,8 @@ public ThermalConductivity(double value, ThermalConductivityUnit unit) /// No unit was found for the given . public ThermalConductivity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -656,25 +651,7 @@ public double As(ThermalConductivityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ThermalConductivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalConductivityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -753,28 +730,29 @@ private bool TryToUnit(ThermalConductivityUnit unit, [NotNullWhen(true)] out The return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ThermalConductivity ToUnit(UnitSystem unitSystem) { - if (!(unit is ThermalConductivityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalConductivityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ThermalConductivity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ThermalConductivityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalConductivityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ThermalConductivityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalConductivityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -788,6 +766,8 @@ public ThermalConductivity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs index 74c3b9d514..4ffbf0ee5c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs @@ -76,9 +76,9 @@ static ThermalInsulance() new UnitInfo(ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, "HourSquareFeetDegreesFahrenheitPerBtu", BaseUnits.Undefined, "ThermalInsulance"), new UnitInfo(ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, "SquareCentimeterHourDegreesCelsiusPerKilocalorie", BaseUnits.Undefined, "ThermalInsulance"), new UnitInfo(ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, "SquareCentimeterKelvinsPerWatt", BaseUnits.Undefined, "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, "SquareMeterDegreesCelsiusPerWatt", BaseUnits.Undefined, "ThermalInsulance"), + new UnitInfo(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, "SquareMeterDegreesCelsiusPerWatt", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "ThermalInsulance"), new UnitInfo(ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, "SquareMeterKelvinsPerKilowatt", BaseUnits.Undefined, "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, "SquareMeterKelvinsPerWatt", BaseUnits.Undefined, "ThermalInsulance"), + new UnitInfo(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, "SquareMeterKelvinsPerWatt", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "ThermalInsulance"), }, BaseUnit, Zero, BaseDimensions); @@ -107,13 +107,8 @@ public ThermalInsulance(double value, ThermalInsulanceUnit unit) /// No unit was found for the given . public ThermalInsulance(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -717,25 +712,7 @@ public double As(ThermalInsulanceUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ThermalInsulanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalInsulanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -822,28 +799,29 @@ private bool TryToUnit(ThermalInsulanceUnit unit, [NotNullWhen(true)] out Therma return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public ThermalInsulance ToUnit(UnitSystem unitSystem) { - if (!(unit is ThermalInsulanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalInsulanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public ThermalInsulance ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not ThermalInsulanceUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalInsulanceUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ThermalInsulanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalInsulanceUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -857,6 +835,8 @@ public ThermalInsulance ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs index ddc02b268d..ee23e43987 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs @@ -99,7 +99,7 @@ static Torque() new UnitInfo(TorqueUnit.MegapoundForceFoot, "MegapoundForceFeet", BaseUnits.Undefined, "Torque"), new UnitInfo(TorqueUnit.MegapoundForceInch, "MegapoundForceInches", BaseUnits.Undefined, "Torque"), new UnitInfo(TorqueUnit.NewtonCentimeter, "NewtonCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.NewtonMeter, "NewtonMeters", BaseUnits.Undefined, "Torque"), + new UnitInfo(TorqueUnit.NewtonMeter, "NewtonMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Torque"), new UnitInfo(TorqueUnit.NewtonMillimeter, "NewtonMillimeters", BaseUnits.Undefined, "Torque"), new UnitInfo(TorqueUnit.PoundalFoot, "PoundalFeet", BaseUnits.Undefined, "Torque"), new UnitInfo(TorqueUnit.PoundForceFoot, "PoundForceFeet", BaseUnits.Undefined, "Torque"), @@ -135,13 +135,8 @@ public Torque(double value, TorqueUnit unit) /// No unit was found for the given . public Torque(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1076,25 +1071,7 @@ public double As(TorqueUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is TorqueUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TorqueUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1219,28 +1196,29 @@ private bool TryToUnit(TorqueUnit unit, [NotNullWhen(true)] out Torque? converte return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Torque ToUnit(UnitSystem unitSystem) { - if (!(unit is TorqueUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TorqueUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Torque ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not TorqueUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TorqueUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is TorqueUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TorqueUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1254,6 +1232,8 @@ public Torque ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs index 54f2b1cf86..e10d096fad 100644 --- a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs @@ -95,25 +95,6 @@ public Turbidity(double value, TurbidityUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public Turbidity(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -640,25 +621,7 @@ public double As(TurbidityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is TurbidityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TurbidityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -735,28 +698,29 @@ private bool TryToUnit(TurbidityUnit unit, [NotNullWhen(true)] out Turbidity? co return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Turbidity ToUnit(UnitSystem unitSystem) { - if (!(unit is TurbidityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TurbidityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Turbidity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not TurbidityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TurbidityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is TurbidityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TurbidityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -770,6 +734,8 @@ public Turbidity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs index f4982d634c..ef2c7139da 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs @@ -92,25 +92,6 @@ public VitaminA(double value, VitaminAUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public VitaminA(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -637,25 +618,7 @@ public double As(VitaminAUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VitaminAUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VitaminAUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -732,28 +695,29 @@ private bool TryToUnit(VitaminAUnit unit, [NotNullWhen(true)] out VitaminA? conv return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public VitaminA ToUnit(UnitSystem unitSystem) { - if (!(unit is VitaminAUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VitaminAUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public VitaminA ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VitaminAUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VitaminAUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VitaminAUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VitaminAUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -767,6 +731,8 @@ public VitaminA ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index fde13a3255..a492a47249 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -92,17 +92,17 @@ static Volume() new UnitInfo(VolumeUnit.AuTablespoon, "AuTablespoons", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.BoardFoot, "BoardFeet", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.Centiliter, "Centiliters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicCentimeter, "CubicCentimeters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicDecimeter, "CubicDecimeters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicFoot, "CubicFeet", BaseUnits.Undefined, "Volume"), + new UnitInfo(VolumeUnit.CubicCentimeter, "CubicCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "Volume"), + new UnitInfo(VolumeUnit.CubicDecimeter, "CubicDecimeters", new BaseUnits(length: LengthUnit.Decimeter), "Volume"), + new UnitInfo(VolumeUnit.CubicFoot, "CubicFeet", new BaseUnits(length: LengthUnit.Foot), "Volume"), new UnitInfo(VolumeUnit.CubicHectometer, "CubicHectometers", new BaseUnits(length: LengthUnit.Hectometer), "Volume"), - new UnitInfo(VolumeUnit.CubicInch, "CubicInches", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicKilometer, "CubicKilometers", BaseUnits.Undefined, "Volume"), + new UnitInfo(VolumeUnit.CubicInch, "CubicInches", new BaseUnits(length: LengthUnit.Inch), "Volume"), + new UnitInfo(VolumeUnit.CubicKilometer, "CubicKilometers", new BaseUnits(length: LengthUnit.Kilometer), "Volume"), new UnitInfo(VolumeUnit.CubicMeter, "CubicMeters", new BaseUnits(length: LengthUnit.Meter), "Volume"), - new UnitInfo(VolumeUnit.CubicMicrometer, "CubicMicrometers", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicMile, "CubicMiles", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicMillimeter, "CubicMillimeters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicYard, "CubicYards", BaseUnits.Undefined, "Volume"), + new UnitInfo(VolumeUnit.CubicMicrometer, "CubicMicrometers", new BaseUnits(length: LengthUnit.Micrometer), "Volume"), + new UnitInfo(VolumeUnit.CubicMile, "CubicMiles", new BaseUnits(length: LengthUnit.Mile), "Volume"), + new UnitInfo(VolumeUnit.CubicMillimeter, "CubicMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "Volume"), + new UnitInfo(VolumeUnit.CubicYard, "CubicYards", new BaseUnits(length: LengthUnit.Yard), "Volume"), new UnitInfo(VolumeUnit.Decaliter, "Decaliters", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.DecausGallon, "DecausGallons", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.Deciliter, "Deciliters", BaseUnits.Undefined, "Volume"), @@ -114,14 +114,14 @@ static Volume() new UnitInfo(VolumeUnit.ImperialBeerBarrel, "ImperialBeerBarrels", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.ImperialGallon, "ImperialGallons", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.ImperialOunce, "ImperialOunces", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.ImperialPint, "ImperialPints", new BaseUnits(length: LengthUnit.Decimeter), "Volume"), + new UnitInfo(VolumeUnit.ImperialPint, "ImperialPints", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.ImperialQuart, "ImperialQuarts", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.KilocubicFoot, "KilocubicFeet", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.KilocubicMeter, "KilocubicMeters", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.KiloimperialGallon, "KiloimperialGallons", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.Kiloliter, "Kiloliters", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.KilousGallon, "KilousGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Liter, "Liters", BaseUnits.Undefined, "Volume"), + new UnitInfo(VolumeUnit.Liter, "Liters", new BaseUnits(length: LengthUnit.Decimeter), "Volume"), new UnitInfo(VolumeUnit.MegacubicFoot, "MegacubicFeet", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.MegaimperialGallon, "MegaimperialGallons", BaseUnits.Undefined, "Volume"), new UnitInfo(VolumeUnit.Megaliter, "Megaliters", BaseUnits.Undefined, "Volume"), @@ -170,13 +170,8 @@ public Volume(double value, VolumeUnit unit) /// No unit was found for the given . public Volume(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1582,25 +1577,7 @@ public double As(VolumeUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VolumeUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1783,28 +1760,29 @@ private bool TryToUnit(VolumeUnit unit, [NotNullWhen(true)] out Volume? converte return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public Volume ToUnit(UnitSystem unitSystem) { - if (!(unit is VolumeUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public Volume ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VolumeUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VolumeUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1818,6 +1796,8 @@ public Volume ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs index 3db7b6f24c..429116b6c8 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs @@ -118,25 +118,6 @@ public VolumeConcentration(double value, VolumeConcentrationUnit unit) _unit = unit; } - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public VolumeConcentration(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - #region Static Properties /// @@ -964,25 +945,7 @@ public double As(VolumeConcentrationUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VolumeConcentrationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeConcentrationUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -1097,28 +1060,29 @@ private bool TryToUnit(VolumeConcentrationUnit unit, [NotNullWhen(true)] out Vol return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public VolumeConcentration ToUnit(UnitSystem unitSystem) { - if (!(unit is VolumeConcentrationUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeConcentrationUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public VolumeConcentration ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VolumeConcentrationUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeConcentrationUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VolumeConcentrationUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeConcentrationUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -1132,6 +1096,8 @@ public VolumeConcentration ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index 42f5c6c53e..8a63666af7 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -88,19 +88,19 @@ static VolumeFlow() new UnitInfo(VolumeFlowUnit.CentiliterPerHour, "CentilitersPerHour", BaseUnits.Undefined, "VolumeFlow"), new UnitInfo(VolumeFlowUnit.CentiliterPerMinute, "CentilitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), new UnitInfo(VolumeFlowUnit.CentiliterPerSecond, "CentilitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicCentimeterPerMinute, "CubicCentimetersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicDecimeterPerMinute, "CubicDecimetersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicFootPerHour, "CubicFeetPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicFootPerMinute, "CubicFeetPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicFootPerSecond, "CubicFeetPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerDay, "CubicMetersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerHour, "CubicMetersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerMinute, "CubicMetersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerSecond, "CubicMetersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMillimeterPerSecond, "CubicMillimetersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerDay, "CubicYardsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerHour, "CubicYardsPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerMinute, "CubicYardsPerMinute", BaseUnits.Undefined, "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicCentimeterPerMinute, "CubicCentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicDecimeterPerMinute, "CubicDecimetersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicFootPerHour, "CubicFeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicFootPerMinute, "CubicFeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicFootPerSecond, "CubicFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicMeterPerDay, "CubicMetersPerDay", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Day), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicMeterPerHour, "CubicMetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicMeterPerMinute, "CubicMetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicMeterPerSecond, "CubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicMillimeterPerSecond, "CubicMillimetersPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicYardPerDay, "CubicYardsPerDay", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Day), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicYardPerHour, "CubicYardsPerHour", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Hour), "VolumeFlow"), + new UnitInfo(VolumeFlowUnit.CubicYardPerMinute, "CubicYardsPerMinute", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Minute), "VolumeFlow"), new UnitInfo(VolumeFlowUnit.CubicYardPerSecond, "CubicYardsPerSecond", BaseUnits.Undefined, "VolumeFlow"), new UnitInfo(VolumeFlowUnit.DecaliterPerDay, "DecalitersPerDay", BaseUnits.Undefined, "VolumeFlow"), new UnitInfo(VolumeFlowUnit.DecaliterPerHour, "DecalitersPerHour", BaseUnits.Undefined, "VolumeFlow"), @@ -183,13 +183,8 @@ public VolumeFlow(double value, VolumeFlowUnit unit) /// No unit was found for the given . public VolumeFlow(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -1862,25 +1857,7 @@ public double As(VolumeFlowUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VolumeFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -2105,28 +2082,29 @@ private bool TryToUnit(VolumeFlowUnit unit, [NotNullWhen(true)] out VolumeFlow? return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public VolumeFlow ToUnit(UnitSystem unitSystem) { - if (!(unit is VolumeFlowUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public VolumeFlow ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VolumeFlowUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VolumeFlowUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -2140,6 +2118,8 @@ public VolumeFlow ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs index f0d791ad1a..f854f37730 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs @@ -103,13 +103,8 @@ public VolumeFlowPerArea(double value, VolumeFlowPerAreaUnit unit) /// No unit was found for the given . public VolumeFlowPerArea(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -653,25 +648,7 @@ public double As(VolumeFlowPerAreaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VolumeFlowPerAreaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowPerAreaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -750,28 +727,29 @@ private bool TryToUnit(VolumeFlowPerAreaUnit unit, [NotNullWhen(true)] out Volum return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public VolumeFlowPerArea ToUnit(UnitSystem unitSystem) { - if (!(unit is VolumeFlowPerAreaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowPerAreaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public VolumeFlowPerArea ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VolumeFlowPerAreaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowPerAreaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VolumeFlowPerAreaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowPerAreaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -785,6 +763,8 @@ public VolumeFlowPerArea ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs index 4469a3869a..2f0a7fdc63 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs @@ -110,13 +110,8 @@ public VolumePerLength(double value, VolumePerLengthUnit unit) /// No unit was found for the given . public VolumePerLength(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -765,25 +760,7 @@ public double As(VolumePerLengthUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VolumePerLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumePerLengthUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -876,28 +853,29 @@ private bool TryToUnit(VolumePerLengthUnit unit, [NotNullWhen(true)] out VolumeP return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public VolumePerLength ToUnit(UnitSystem unitSystem) { - if (!(unit is VolumePerLengthUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumePerLengthUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public VolumePerLength ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VolumePerLengthUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumePerLengthUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VolumePerLengthUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumePerLengthUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -911,6 +889,8 @@ public VolumePerLength ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs index a248572171..d7886fbcca 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs @@ -78,8 +78,8 @@ static VolumetricHeatCapacity() { new UnitInfo(VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, "BtusPerCubicFootDegreeFahrenheit", BaseUnits.Undefined, "VolumetricHeatCapacity"), new UnitInfo(VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, "CaloriesPerCubicCentimeterDegreeCelsius", BaseUnits.Undefined, "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, "JoulesPerCubicMeterDegreeCelsius", BaseUnits.Undefined, "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, "JoulesPerCubicMeterKelvin", BaseUnits.Undefined, "VolumetricHeatCapacity"), + new UnitInfo(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, "JoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "VolumetricHeatCapacity"), + new UnitInfo(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, "JoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "VolumetricHeatCapacity"), new UnitInfo(VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, "KilocaloriesPerCubicCentimeterDegreeCelsius", BaseUnits.Undefined, "VolumetricHeatCapacity"), new UnitInfo(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, "KilojoulesPerCubicMeterDegreeCelsius", BaseUnits.Undefined, "VolumetricHeatCapacity"), new UnitInfo(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, "KilojoulesPerCubicMeterKelvin", BaseUnits.Undefined, "VolumetricHeatCapacity"), @@ -113,13 +113,8 @@ public VolumetricHeatCapacity(double value, VolumetricHeatCapacityUnit unit) /// No unit was found for the given . public VolumetricHeatCapacity(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -768,25 +763,7 @@ public double As(VolumetricHeatCapacityUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is VolumetricHeatCapacityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumetricHeatCapacityUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -879,28 +856,29 @@ private bool TryToUnit(VolumetricHeatCapacityUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public VolumetricHeatCapacity ToUnit(UnitSystem unitSystem) { - if (!(unit is VolumetricHeatCapacityUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumetricHeatCapacityUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public VolumetricHeatCapacity ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not VolumetricHeatCapacityUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumetricHeatCapacityUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is VolumetricHeatCapacityUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumetricHeatCapacityUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -914,6 +892,8 @@ public VolumetricHeatCapacity ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs index ef32e3655c..6dcd2c45ff 100644 --- a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs @@ -107,13 +107,8 @@ public WarpingMomentOfInertia(double value, WarpingMomentOfInertiaUnit unit) /// No unit was found for the given . public WarpingMomentOfInertia(double value, UnitSystem unitSystem) { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - _value = value; - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + _unit = Info.GetDefaultUnit(unitSystem); } #region Static Properties @@ -717,25 +712,7 @@ public double As(WarpingMomentOfInertiaUnit unit) /// public double As(UnitSystem unitSystem) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is WarpingMomentOfInertiaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(WarpingMomentOfInertiaUnit)} is supported.", nameof(unit)); - - return As(typedUnit); + return As(Info.GetDefaultUnit(unitSystem)); } /// @@ -822,28 +799,29 @@ private bool TryToUnit(WarpingMomentOfInertiaUnit unit, [NotNullWhen(true)] out return true; } - /// - IQuantity IQuantity.ToUnit(Enum unit) + /// + public WarpingMomentOfInertia ToUnit(UnitSystem unitSystem) { - if (!(unit is WarpingMomentOfInertiaUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(WarpingMomentOfInertiaUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); + return ToUnit(Info.GetDefaultUnit(unitSystem)); } - /// - public WarpingMomentOfInertia ToUnit(UnitSystem unitSystem) + #region Explicit implementations + + double IQuantity.As(Enum unit) { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); + if (unit is not WarpingMomentOfInertiaUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(WarpingMomentOfInertiaUnit)} is supported.", nameof(unit)); - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + return As(typedUnit); + } - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is WarpingMomentOfInertiaUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(WarpingMomentOfInertiaUnit)} is supported.", nameof(unit)); - return ToUnit(firstUnitInfo.Value); + return ToUnit(typedUnit, DefaultConversionFunctions); } /// @@ -857,6 +835,8 @@ public WarpingMomentOfInertia ToUnit(UnitSystem unitSystem) #endregion + #endregion + #region ToString Methods /// diff --git a/UnitsNet/UnitsNet.csproj.DotSettings b/UnitsNet/UnitsNet.csproj.DotSettings index 78ef24c567..a60c20895b 100644 --- a/UnitsNet/UnitsNet.csproj.DotSettings +++ b/UnitsNet/UnitsNet.csproj.DotSettings @@ -1,3 +1,4 @@  True - True \ No newline at end of file + True + True \ No newline at end of file