@@ -74,6 +74,7 @@ public override string Generate()
74
74
using System.Globalization;
75
75
using System.Linq;
76
76
using System.Threading;
77
+ using UnitsNet.Tests.TestsBase;
77
78
using UnitsNet.Units;
78
79
using Xunit;
79
80
@@ -87,7 +88,7 @@ namespace UnitsNet.Tests
87
88
/// Test of { _quantity . Name } .
88
89
/// </summary>
89
90
// ReSharper disable once PartialTypeWithSinglePart
90
- public abstract partial class { _quantity . Name } TestsBase
91
+ public abstract partial class { _quantity . Name } TestsBase : QuantityTestsBase
91
92
{{" ) ;
92
93
foreach ( var unit in _quantity . Units ) Writer . WL ( $@ "
93
94
protected abstract double { unit . PluralName } InOne{ _baseUnit . SingularName } {{ get; }}" ) ;
@@ -127,13 +128,28 @@ public void Ctor_WithNaNValue_ThrowsArgumentException()
127
128
{{
128
129
Assert.Throws<ArgumentException>(() => new { _quantity . Name } (double.NaN, { _baseUnitFullName } ));
129
130
}}
131
+ " ) ; Writer . WL ( $@ "
130
132
131
133
[Fact]
132
134
public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException()
133
135
{{
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
+ }}
135
152
}}
136
- " ) ; Writer . WL ( $@ "
137
153
138
154
[Fact]
139
155
public void { _quantity . Name } _QuantityInfo_ReturnsQuantityInfoDescribingQuantity()
@@ -207,6 +223,23 @@ public void As()
207
223
Writer . WL ( $@ "
208
224
}}
209
225
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
+
210
243
[Fact]
211
244
public void ToUnit()
212
245
{{
@@ -224,6 +257,14 @@ public void ToUnit()
224
257
Writer . WL ( $@ "
225
258
}}
226
259
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
+
227
268
[Fact]
228
269
public void ConversionRoundTrip()
229
270
{{
@@ -657,11 +698,10 @@ public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
657
698
{{
658
699
var quantity = { _quantity . Name } .From{ _baseUnit . PluralName } (value);
659
700
Assert.Equal({ _quantity . Name } .From{ _baseUnit . PluralName } (-value), -quantity);
660
- }}
661
- " ) ;
701
+ }}" ) ;
662
702
}
663
703
664
- Writer . WL ( $@ "
704
+ Writer . WL ( $@ "
665
705
}}
666
706
}}" ) ;
667
707
return Writer . ToString ( ) ;
0 commit comments