|
| 1 | +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). |
| 2 | +// https://github.com/angularsen/UnitsNet |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +// of this software and associated documentation files (the "Software"), to deal |
| 6 | +// in the Software without restriction, including without limitation the rights |
| 7 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +// copies of the Software, and to permit persons to whom the Software is |
| 9 | +// furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in |
| 12 | +// all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +// THE SOFTWARE. |
| 21 | + |
| 22 | +using System; |
| 23 | +using System.Diagnostics.CodeAnalysis; |
| 24 | +using UnitsNet.Units; |
| 25 | +using Xunit; |
| 26 | + |
| 27 | +namespace UnitsNet.Tests |
| 28 | +{ |
| 29 | + public class QuantityInfoTest |
| 30 | + { |
| 31 | + [Fact] |
| 32 | + public void Constructor_AssignsProperties() |
| 33 | + { |
| 34 | + var expectedZero = Length.FromCentimeters(10); |
| 35 | + var expectedUnits = new Enum[] {LengthUnit.Centimeter, LengthUnit.Kilometer}; |
| 36 | + var expectedQuantityType = QuantityType.Length; |
| 37 | + |
| 38 | + var info = new QuantityInfo(expectedQuantityType, expectedUnits, expectedZero); |
| 39 | + |
| 40 | + Assert.Equal(expectedZero, info.Zero); |
| 41 | + Assert.Equal("Length", info.Name); |
| 42 | + Assert.Equal(expectedUnits, info.Units); |
| 43 | + Assert.Equal(new[]{"Centimeter", "Kilometer"}, info.UnitNames); |
| 44 | + Assert.Equal(expectedQuantityType, info.QuantityType); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void GenericsConstructor_AssignsProperties() |
| 49 | + { |
| 50 | + var expectedZero = Length.FromCentimeters(10); |
| 51 | + var expectedUnits = new[] {LengthUnit.Centimeter, LengthUnit.Kilometer}; |
| 52 | + var expectedQuantityType = QuantityType.Length; |
| 53 | + |
| 54 | + var info = new QuantityInfo<LengthUnit>(expectedQuantityType, expectedUnits, expectedZero); |
| 55 | + |
| 56 | + Assert.Equal(expectedZero, info.Zero); |
| 57 | + Assert.Equal("Length", info.Name); |
| 58 | + Assert.Equal(expectedUnits, info.Units); |
| 59 | + Assert.Equal(new[]{"Centimeter", "Kilometer"}, info.UnitNames); |
| 60 | + Assert.Equal(expectedQuantityType, info.QuantityType); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] |
| 65 | + public void Constructor_GivenNullAsUnits_ThrowsArgumentNullException() |
| 66 | + { |
| 67 | + Assert.Throws<ArgumentNullException>(() => new QuantityInfo(QuantityType.Length, null, null)); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] |
| 72 | + public void GenericsConstructor_GivenNullAsUnits_ThrowsArgumentNullException() |
| 73 | + { |
| 74 | + Assert.Throws<ArgumentNullException>(() => new QuantityInfo<LengthUnit>(QuantityType.Length, null, null)); |
| 75 | + } |
| 76 | + |
| 77 | + [Fact] |
| 78 | + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] |
| 79 | + public void Constructor_GivenNullAsZero_ThrowsArgumentNullException() |
| 80 | + { |
| 81 | + Assert.Throws<ArgumentNullException>(() => new QuantityInfo(QuantityType.Length, new Enum[0], null)); |
| 82 | + } |
| 83 | + |
| 84 | + [Fact] |
| 85 | + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] |
| 86 | + public void GenericsConstructor_GivenNullAsZero_ThrowsArgumentNullException() |
| 87 | + { |
| 88 | + Assert.Throws<ArgumentNullException>(() => new QuantityInfo<LengthUnit>(QuantityType.Length, new LengthUnit[0], null)); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments