@@ -74,6 +74,7 @@ public override string Generate()
7474using System.Globalization;
7575using System.Linq;
7676using System.Threading;
77+ using UnitsNet.Tests.TestsBase;
7778using UnitsNet.Units;
7879using Xunit;
7980
@@ -87,7 +88,7 @@ namespace UnitsNet.Tests
8788 /// Test of { _quantity . Name } .
8889 /// </summary>
8990// ReSharper disable once PartialTypeWithSinglePart
90- public abstract partial class { _quantity . Name } TestsBase
91+ public abstract partial class { _quantity . Name } TestsBase : QuantityTestsBase
9192 {{" ) ;
9293 foreach ( var unit in _quantity . Units ) Writer . WL ( $@ "
9394 protected abstract double { unit . PluralName } InOne{ _baseUnit . SingularName } {{ get; }}" ) ;
@@ -127,13 +128,28 @@ public void Ctor_WithNaNValue_ThrowsArgumentException()
127128 {{
128129 Assert.Throws<ArgumentException>(() => new { _quantity . Name } (double.NaN, { _baseUnitFullName } ));
129130 }}
131+ " ) ; Writer . WL ( $@ "
130132
131133 [Fact]
132134 public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException()
133135 {{
134- Assert.Throws<ArgumentNullException>(() => new { _quantity . Name } (value: 1.0, unitSystem: null));
136+ Assert.Throws<ArgumentNullException>(() => new { _quantity . Name } (value: 1, unitSystem: null));
137+ }}
138+
139+ [Fact]
140+ public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported()
141+ {{
142+ Func<object> TestCode = () => new { _quantity . Name } (value: 1, unitSystem: UnitSystem.SI);
143+ if (SupportsSIUnitSystem)
144+ {{
145+ var quantity = ({ _quantity . Name } ) TestCode();
146+ Assert.Equal(1, quantity.Value);
147+ }}
148+ else
149+ {{
150+ Assert.Throws<ArgumentException>(TestCode);
151+ }}
135152 }}
136- " ) ; Writer . WL ( $@ "
137153
138154 [Fact]
139155 public void { _quantity . Name } _QuantityInfo_ReturnsQuantityInfoDescribingQuantity()
@@ -207,6 +223,23 @@ public void As()
207223 Writer . WL ( $@ "
208224 }}
209225
226+ [Fact]
227+ public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported()
228+ {{
229+ var quantity = new { _quantity . Name } (value: 1, unit: { _quantity . Name } .BaseUnit);
230+ Func<object> AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI);
231+
232+ if (SupportsSIUnitSystem)
233+ {{
234+ var value = (double) AsWithSIUnitSystem();
235+ Assert.Equal(1, value);
236+ }}
237+ else
238+ {{
239+ Assert.Throws<ArgumentException>(AsWithSIUnitSystem);
240+ }}
241+ }}
242+
210243 [Fact]
211244 public void ToUnit()
212245 {{
@@ -224,6 +257,14 @@ public void ToUnit()
224257 Writer . WL ( $@ "
225258 }}
226259
260+ [Fact]
261+ public void ToBaseUnit_ReturnsQuantityWithBaseUnit()
262+ {{
263+ var quantityInBaseUnit = { _quantity . Name } .From{ _baseUnit . PluralName } (1).ToBaseUnit();
264+ Assert.Equal({ _quantity . Name } .BaseUnit, quantityInBaseUnit.Unit);" ) ;
265+ Writer . WL ( $@ "
266+ }}
267+
227268 [Fact]
228269 public void ConversionRoundTrip()
229270 {{
@@ -657,11 +698,10 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
657698 {{
658699 var quantity = { _quantity . Name } .From{ _baseUnit . PluralName } (value);
659700 Assert.Equal({ _quantity . Name } .From{ _baseUnit . PluralName } (-value), -quantity);
660- }}
661- " ) ;
701+ }}" ) ;
662702 }
663703
664- Writer . WL ( $@ "
704+ Writer . WL ( $@ "
665705 }}
666706}}" ) ;
667707 return Writer . ToString ( ) ;
0 commit comments