diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
index 6c5cf268d0..c91c2f7244 100644
--- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
+++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
@@ -1034,15 +1034,6 @@ public double As(UnitKey unitKey)
}}
");
- Writer.WL( $@"
-
- ///
- public double As(UnitSystem unitSystem)
- {{
- return As(Info.GetDefaultUnit(unitSystem));
- }}
-");
-
Writer.WL($@"
///
/// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation .
@@ -1140,14 +1131,6 @@ private bool TryToUnit({_unitEnumName} unit, [NotNullWhen(true)] out {_quantity.
return true;
}}
");
- Writer.WL($@"
- ///
- public {_quantity.Name} ToUnit(UnitSystem unitSystem)
- {{
- return ToUnit(Info.GetDefaultUnit(unitSystem));
- }}
-");
-
Writer.WL($@"
#region Explicit implementations
@@ -1168,14 +1151,11 @@ IQuantity IQuantity.ToUnit(Enum unit)
return ToUnit(typedUnit, DefaultConversionFunctions);
}}
- ///
- IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
-
///
IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit({_unitEnumName} unit) => ToUnit(unit);
///
- IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
+ IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit(UnitSystem unitSystem) => this.ToUnit(unitSystem);
#endregion
diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
index 249277e290..b2ebbdf0b3 100644
--- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
+++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs
@@ -410,7 +410,7 @@ public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull()
}}
[Fact]
- public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
+ public void ToUnit_UnitSystem_ReturnsValueInDimensionlessUnit()
{{
Assert.Multiple(() =>
{{
@@ -428,17 +428,21 @@ public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
Assert.Equal({_baseUnitFullName}, convertedQuantity.Unit);
Assert.Equal(quantity.Value, convertedQuantity.Value);
- }}, () =>
- {{
- IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName});
+ }});
+ }}
+
+ [Fact]
+ public void ToUnitUntyped_UnitSystem_ReturnsValueInDimensionlessUnit()
+ {{
+ IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName});
- IQuantity convertedQuantity = quantity.ToUnit(UnitSystem.SI);
+ IQuantity convertedQuantity = quantity.ToUnitUntyped(UnitSystem.SI);
- Assert.Equal({_baseUnitFullName}, convertedQuantity.Unit);
- Assert.Equal(quantity.Value, convertedQuantity.Value);
- }});
+ Assert.Equal({_baseUnitFullName}, convertedQuantity.Unit);
+ Assert.Equal(quantity.Value, convertedQuantity.Value);
}}
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{{
@@ -446,15 +450,15 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
Assert.Multiple(() =>
{{
var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}}, () =>
{{
IQuantity<{_unitEnumName}> quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}}, () =>
{{
IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}});
}}
");
@@ -520,15 +524,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }}, () =>
- {{
- IQuantity quantityToConvert = quantity;
+ }});
+ }}
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ [Fact]
+ public virtual void ToUnitUntyped_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.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- }});
+ IQuantity quantityToConvert = quantity;
+
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}}
[Fact]
@@ -543,13 +554,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {{
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }}
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{{
@@ -562,12 +577,16 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{{
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));
}});
}}
+
+ [Fact]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {{
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }}
");
}
diff --git a/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs b/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs
index c1f249132c..0e03d7c445 100644
--- a/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs
+++ b/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs
@@ -37,23 +37,29 @@ 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();
}
+
+ [Fact(Skip = "See about adding an SI unit (VoltampereSecond, Joules?)")]
+ public override void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ base.ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits();
+ }
}
}
diff --git a/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs b/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs
index 3f0ea76660..c6a879999c 100644
--- a/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs
+++ b/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs
@@ -36,23 +36,29 @@ 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();
}
+
+ [Fact(Skip = "See about adding an SI unit (VoltampereReactiveSecond, Joules?)")]
+ public override void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ base.ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits();
+ }
}
}
diff --git a/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs
index 329dac3619..06bf5627cb 100644
--- a/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs
+++ b/UnitsNet.Tests/CustomCode/FuelEfficiencyTests.cs
@@ -24,19 +24,19 @@ namespace UnitsNet.Tests.CustomCode
public class FuelEfficiencyTests : FuelEfficiencyTestsBase
{
protected override bool SupportsSIUnitSystem => false;
-
+
protected override double KilometersPerLiterInOneKilometerPerLiter => 1;
protected override double LitersPer100KilometersInOneKilometerPerLiter => 100;
protected override double MilesPerUkGallonInOneKilometerPerLiter => 2.824809363318222;
protected override double MilesPerUsGallonInOneKilometerPerLiter => 2.352145833333333;
-
+
[Fact(Skip = "The SI unit would have to be MeterPerCubicMeter")]
public override void BaseUnit_HasSIBase()
{
base.BaseUnit_HasSIBase();
}
-
+
[Fact(Skip = "The SI unit would have to be MeterPerCubicMeter")]
public override void Ctor_SIUnitSystem_ReturnsQuantityWithSIUnits()
{
@@ -54,5 +54,11 @@ public override void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
{
base.ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits();
}
+
+ [Fact(Skip = "The SI unit would have to be MeterPerCubicMeter")]
+ public override void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ base.ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits();
+ }
}
}
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs
index e3445b5909..1468b9c0bc 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs
@@ -321,15 +321,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit);
+ var expectedUnit = AbsorbedDoseOfIonizingRadiation.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -344,13 +351,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -363,13 +374,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new AbsorbedDoseOfIonizingRadiation(value: 1, unit: AbsorbedDoseOfIonizingRadiation.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray, 4.2)]
[InlineData("en-US", "4.2 dGy", AbsorbedDoseOfIonizingRadiationUnit.Decigray, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs
index e9cd2bc642..df6b31005e 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs
@@ -303,15 +303,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit);
+ var expectedUnit = Acceleration.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -326,13 +333,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -345,13 +356,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new Acceleration(value: 1, unit: Acceleration.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cm/s²", AccelerationUnit.CentimeterPerSecondSquared, 4.2)]
[InlineData("en-US", "4.2 dm/s²", AccelerationUnit.DecimeterPerSecondSquared, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs
index d763ffe4e5..f83c68a30b 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs
@@ -321,15 +321,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit);
+ var expectedUnit = AmountOfSubstance.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -344,13 +351,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -363,13 +374,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new AmountOfSubstance(value: 1, unit: AmountOfSubstance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cmol", AmountOfSubstanceUnit.Centimole, 4.2)]
[InlineData("en-US", "4.2 clbmol", AmountOfSubstanceUnit.CentipoundMole, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs
index e50a6f329b..3b46e2b40b 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs
@@ -184,7 +184,7 @@ public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull()
}
[Fact]
- public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
+ public void ToUnit_UnitSystem_ReturnsValueInDimensionlessUnit()
{
Assert.Multiple(() =>
{
@@ -202,17 +202,21 @@ public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
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);
+ [Fact]
+ public void ToUnitUntyped_UnitSystem_ReturnsValueInDimensionlessUnit()
+ {
+ IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatioUnit.DecibelVolt);
- Assert.Equal(AmplitudeRatioUnit.DecibelVolt, convertedQuantity.Unit);
- Assert.Equal(quantity.Value, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantity.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(AmplitudeRatioUnit.DecibelVolt, convertedQuantity.Unit);
+ Assert.Equal(quantity.Value, convertedQuantity.Value);
}
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
@@ -220,15 +224,15 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
Assert.Multiple(() =>
{
var quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}, () =>
{
IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}, () =>
{
IQuantity quantity = new AmplitudeRatio(value: 1, unit: AmplitudeRatio.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
});
}
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs
index 1905e576a8..213bdd8424 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs
@@ -250,7 +250,7 @@ public void As_UnitSystem_ThrowsArgumentNullExceptionIfNull()
}
[Fact]
- public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
+ public void ToUnit_UnitSystem_ReturnsValueInDimensionlessUnit()
{
Assert.Multiple(() =>
{
@@ -268,17 +268,21 @@ public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
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);
+ [Fact]
+ public void ToUnitUntyped_UnitSystem_ReturnsValueInDimensionlessUnit()
+ {
+ IQuantity quantity = new Angle(value: 1, unit: AngleUnit.Radian);
- Assert.Equal(AngleUnit.Radian, convertedQuantity.Unit);
- Assert.Equal(quantity.Value, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantity.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(AngleUnit.Radian, convertedQuantity.Unit);
+ Assert.Equal(quantity.Value, convertedQuantity.Value);
}
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
@@ -286,15 +290,15 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
Assert.Multiple(() =>
{
var quantity = new Angle(value: 1, unit: Angle.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}, () =>
{
IQuantity quantity = new Angle(value: 1, unit: Angle.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
}, () =>
{
IQuantity quantity = new Angle(value: 1, unit: Angle.BaseUnit);
- Assert.Throws(() => quantity.ToUnit(nullUnitSystem));
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
});
}
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs
index a41cea8ad7..6da629fbf6 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs
@@ -237,15 +237,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit);
+ var expectedUnit = AreaDensity.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -260,13 +267,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -279,13 +290,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new AreaDensity(value: 1, unit: AreaDensity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 g/m²", AreaDensityUnit.GramPerSquareMeter, 4.2)]
[InlineData("en-US", "4.2 gsm", AreaDensityUnit.GramPerSquareMeter, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs
index c9e37a12fc..7476dc3f70 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs
@@ -255,15 +255,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit);
+ var expectedUnit = AreaMomentOfInertia.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -278,13 +285,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -297,13 +308,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new AreaMomentOfInertia(value: 1, unit: AreaMomentOfInertia.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth, 4.2)]
[InlineData("en-US", "4.2 dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs
index 07316d3858..197378c4e9 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs
@@ -303,15 +303,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new Area(value: 1, unit: Area.BaseUnit);
+ var expectedUnit = Area.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -326,13 +333,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new Area(value: 1, unit: Area.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -345,13 +356,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new Area(value: 1, unit: Area.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 ac", AreaUnit.Acre, 4.2)]
[InlineData("en-US", "4.2 ha", AreaUnit.Hectare, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs
index c235cf59ba..854e9900b1 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs
@@ -453,15 +453,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new BitRate(value: 1, unit: BitRate.BaseUnit);
+ var expectedUnit = BitRate.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -476,13 +483,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new BitRate(value: 1, unit: BitRate.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -495,13 +506,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new BitRate(value: 1, unit: BitRate.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 bit/s", BitRateUnit.BitPerSecond, 4.2)]
[InlineData("en-US", "4.2 bps", BitRateUnit.BitPerSecond, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs
index 6062eee45d..536f5b101f 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs
@@ -237,15 +237,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit);
+ var expectedUnit = BrakeSpecificFuelConsumption.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -260,13 +267,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -279,13 +290,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new BrakeSpecificFuelConsumption(value: 1, unit: BrakeSpecificFuelConsumption.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, 4.2)]
[InlineData("en-US", "4.2 kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs
index 8db65616ee..64fcb85cca 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs
@@ -255,15 +255,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit);
+ var expectedUnit = CoefficientOfThermalExpansion.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -278,13 +285,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -297,13 +308,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new CoefficientOfThermalExpansion(value: 1, unit: CoefficientOfThermalExpansion.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 °C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius, 4.2)]
[InlineData("en-US", "4.2 °F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs
index 9a4fa19df3..964d15a611 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs
@@ -261,15 +261,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit);
+ var expectedUnit = Compressibility.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -284,13 +291,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -303,13 +314,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 atm⁻¹", CompressibilityUnit.InverseAtmosphere, 4.2)]
[InlineData("en-US", "4.2 1/atm", CompressibilityUnit.InverseAtmosphere, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs
index 5af5af8aa4..48e3d7e820 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs
@@ -555,15 +555,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new Density(value: 1, unit: Density.BaseUnit);
+ var expectedUnit = Density.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -578,13 +585,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new Density(value: 1, unit: Density.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -597,13 +608,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new Density(value: 1, unit: Density.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cg/dl", DensityUnit.CentigramPerDeciliter, 4.2)]
[InlineData("en-US", "4.2 cg/l", DensityUnit.CentigramPerLiter, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs
index 7e87f51cdc..d2c1304e26 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DoseAreaProductTestsBase.g.cs
@@ -369,15 +369,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit);
+ var expectedUnit = DoseAreaProduct.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -392,13 +399,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -411,13 +422,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new DoseAreaProduct(value: 1, unit: DoseAreaProduct.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cGy·cm²", DoseAreaProductUnit.CentigraySquareCentimeter, 4.2)]
[InlineData("en-US", "4.2 cGy·dm²", DoseAreaProductUnit.CentigraySquareDecimeter, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs
index f83d33989b..1e77b4db99 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs
@@ -297,15 +297,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new Duration(value: 1, unit: Duration.BaseUnit);
+ var expectedUnit = Duration.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -320,13 +327,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new Duration(value: 1, unit: Duration.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -339,13 +350,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new Duration(value: 1, unit: Duration.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 d", DurationUnit.Day, 4.2)]
[InlineData("en-US", "4.2 day", DurationUnit.Day, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs
index 7632d103bf..483cff37e8 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs
@@ -279,15 +279,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit);
+ var expectedUnit = DynamicViscosity.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -302,13 +309,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -321,13 +332,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new DynamicViscosity(value: 1, unit: DynamicViscosity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 cP", DynamicViscosityUnit.Centipoise, 4.2)]
[InlineData("en-US", "4.2 µPa·s", DynamicViscosityUnit.MicropascalSecond, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs
index 55ee5df321..5e8754b5ee 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs
@@ -315,15 +315,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit);
+ var expectedUnit = ElectricAdmittance.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -338,13 +345,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -357,13 +368,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricAdmittance(value: 1, unit: ElectricAdmittance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 G℧", ElectricAdmittanceUnit.Gigamho, 4.2)]
[InlineData("en-US", "4.2 GS", ElectricAdmittanceUnit.Gigasiemens, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs
index 8dd6c53fe7..79f5ea0993 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs
@@ -237,15 +237,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit);
+ var expectedUnit = ElectricApparentEnergy.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -260,13 +267,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -279,13 +290,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 kVAh", ElectricApparentEnergyUnit.KilovoltampereHour, 4.2)]
[InlineData("en-US", "4.2 MVAh", ElectricApparentEnergyUnit.MegavoltampereHour, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs
index 21f3870bd0..8572daa8ff 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs
@@ -255,15 +255,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit);
+ var expectedUnit = ElectricApparentPower.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -278,13 +285,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -297,13 +308,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 GVA", ElectricApparentPowerUnit.Gigavoltampere, 4.2)]
[InlineData("en-US", "4.2 kVA", ElectricApparentPowerUnit.Kilovoltampere, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs
index f2d4863228..f6c32ffea9 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs
@@ -261,15 +261,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit);
+ var expectedUnit = ElectricCapacitance.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -284,13 +291,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -303,13 +314,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 F", ElectricCapacitanceUnit.Farad, 4.2)]
[InlineData("en-US", "4.2 kF", ElectricCapacitanceUnit.Kilofarad, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs
index d40904ba05..ef3f5777ae 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs
@@ -225,15 +225,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit);
+ var expectedUnit = ElectricChargeDensity.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -248,13 +255,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -267,13 +278,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricChargeDensity(value: 1, unit: ElectricChargeDensity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter, 4.2)]
public void Parse(string culture, string quantityString, ElectricChargeDensityUnit expectedUnit, double expectedValue)
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs
index 76accb87a1..5d53b09e3e 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs
@@ -285,15 +285,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit);
+ var expectedUnit = ElectricCharge.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -308,13 +315,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -327,13 +338,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricCharge(value: 1, unit: ElectricCharge.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 A-h", ElectricChargeUnit.AmpereHour, 4.2)]
[InlineData("en-US", "4.2 Ah", ElectricChargeUnit.AmpereHour, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs
index efdd4279e4..74df3bb25a 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs
@@ -315,15 +315,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit);
+ var expectedUnit = ElectricConductance.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -338,13 +345,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -357,13 +368,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricConductance(value: 1, unit: ElectricConductance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 G℧", ElectricConductanceUnit.Gigamho, 4.2)]
[InlineData("en-US", "4.2 GS", ElectricConductanceUnit.Gigasiemens, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs
index 713642f804..2eb01bb833 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs
@@ -255,15 +255,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit);
+ var expectedUnit = ElectricConductivity.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -278,13 +285,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -297,13 +308,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricConductivity(value: 1, unit: ElectricConductivity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter, 4.2)]
[InlineData("en-US", "4.2 mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs
index c6bf55548a..63824a627e 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs
@@ -237,15 +237,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit);
+ var expectedUnit = ElectricCurrentDensity.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -260,13 +267,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -279,13 +290,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricCurrentDensity(value: 1, unit: ElectricCurrentDensity.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot, 4.2)]
[InlineData("en-US", "4.2 A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs
index 7187e3e17e..d1bb6aef40 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs
@@ -261,15 +261,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit);
+ var expectedUnit = ElectricCurrentGradient.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -284,13 +291,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -303,13 +314,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricCurrentGradient(value: 1, unit: ElectricCurrentGradient.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond, 4.2)]
[InlineData("en-US", "4.2 A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs
index 5bd54a9db6..ae61a05fce 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs
@@ -273,15 +273,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit);
+ var expectedUnit = ElectricCurrent.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -296,13 +303,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -315,13 +326,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricCurrent(value: 1, unit: ElectricCurrent.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 A", ElectricCurrentUnit.Ampere, 4.2)]
[InlineData("en-US", "4.2 cA", ElectricCurrentUnit.Centiampere, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs
index 33a9457355..4871795759 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs
@@ -225,15 +225,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit);
+ var expectedUnit = ElectricField.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -248,13 +255,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -267,13 +278,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricField(value: 1, unit: ElectricField.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 V/m", ElectricFieldUnit.VoltPerMeter, 4.2)]
public void Parse(string culture, string quantityString, ElectricFieldUnit expectedUnit, double expectedValue)
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs
index a27ea66477..61b4092eda 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs
@@ -267,15 +267,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit);
+ var expectedUnit = ElectricImpedance.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -290,13 +297,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -309,13 +320,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 GΩ", ElectricImpedanceUnit.Gigaohm, 4.2)]
[InlineData("en-US", "4.2 kΩ", ElectricImpedanceUnit.Kiloohm, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs
index 88f5bb2386..c52256b465 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs
@@ -249,15 +249,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit);
+ var expectedUnit = ElectricInductance.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -272,13 +279,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(nullUnitSystem));
+ }
+
[Fact]
public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
@@ -291,13 +302,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
{
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]
+ public void ToUnitUntyped_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
+ {
+ var unsupportedUnitSystem = new UnitSystem(UnsupportedBaseUnits);
+ IQuantity quantity = new ElectricInductance(value: 1, unit: ElectricInductance.BaseUnit);
+ Assert.Throws(() => quantity.ToUnitUntyped(unsupportedUnitSystem));
+ }
+
[Theory]
[InlineData("en-US", "4.2 H", ElectricInductanceUnit.Henry, 4.2)]
[InlineData("en-US", "4.2 µH", ElectricInductanceUnit.Microhenry, 4.2)]
diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs
index c2362a019b..dadaac73d6 100644
--- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs
+++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs
@@ -339,15 +339,22 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
Assert.Equal(expectedUnit, convertedQuantity.Unit);
Assert.Equal(expectedValue, convertedQuantity.Value);
- }, () =>
- {
- IQuantity quantityToConvert = quantity;
+ });
+ }
+
+ [Fact]
+ public virtual void ToUnitUntyped_UnitSystem_SI_ReturnsQuantityInSIUnits()
+ {
+ var quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit);
+ var expectedUnit = ElectricPotentialChangeRate.Info.GetDefaultUnit(UnitSystem.SI);
+ var expectedValue = quantity.As(expectedUnit);
- IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
+ IQuantity quantityToConvert = quantity;
- Assert.Equal(expectedUnit, convertedQuantity.Unit);
- Assert.Equal(expectedValue, convertedQuantity.Value);
- });
+ IQuantity convertedQuantity = quantityToConvert.ToUnitUntyped(UnitSystem.SI);
+
+ Assert.Equal(expectedUnit, convertedQuantity.Unit);
+ Assert.Equal(expectedValue, convertedQuantity.Value);
}
[Fact]
@@ -362,13 +369,17 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
{
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 ToUnitUntyped_UnitSystem_ThrowsArgumentNullExceptionIfNull()
+ {
+ UnitSystem nullUnitSystem = null!;
+ IQuantity quantity = new ElectricPotentialChangeRate(value: 1, unit: ElectricPotentialChangeRate.BaseUnit);
+ Assert.Throws