|
2 | 2 | // Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections.Generic; |
5 | 6 | using System.Diagnostics.CodeAnalysis; |
6 | 7 | using System.Runtime.Serialization; |
7 | 8 | using UnitsNet.Units; |
@@ -108,6 +109,52 @@ public virtual void ArrayOfDecimalValueQuantities_SerializationRoundTrips() |
108 | 109 | }); |
109 | 110 | } |
110 | 111 |
|
| 112 | + [Fact] |
| 113 | + public virtual void EnumerableOfDoubleValueQuantities_SerializationRoundTrips() |
| 114 | + { |
| 115 | + var firstQuantity = new Mass(1.2, MassUnit.Milligram); |
| 116 | + var secondQuantity = new Mass(2, MassUnit.Gram); |
| 117 | + IEnumerable<Mass> quantities = new List<Mass> {firstQuantity, secondQuantity}; |
| 118 | + var payload = SerializeObject(quantities); |
| 119 | + |
| 120 | + var results = DeserializeObject<IEnumerable<Mass>>(payload); |
| 121 | + |
| 122 | + Assert.Collection(results, result => |
| 123 | + { |
| 124 | + Assert.Equal(firstQuantity.Unit, result.Unit); |
| 125 | + Assert.Equal(firstQuantity.Value, result.Value); |
| 126 | + Assert.Equal(firstQuantity, result); |
| 127 | + }, result => |
| 128 | + { |
| 129 | + Assert.Equal(secondQuantity.Unit, result.Unit); |
| 130 | + Assert.Equal(secondQuantity.Value, result.Value); |
| 131 | + Assert.Equal(secondQuantity, result); |
| 132 | + }); |
| 133 | + } |
| 134 | + |
| 135 | + [Fact] |
| 136 | + public virtual void EnumerableOfDecimalValueQuantities_SerializationRoundTrips() |
| 137 | + { |
| 138 | + var firstQuantity = new Information(1.2m, InformationUnit.Exabit); |
| 139 | + var secondQuantity = new Information(2, InformationUnit.Exabyte); |
| 140 | + IEnumerable<Information> quantities = new List<Information> {firstQuantity, secondQuantity}; |
| 141 | + var payload = SerializeObject(quantities); |
| 142 | + |
| 143 | + var results = DeserializeObject<IEnumerable<Information>>(payload); |
| 144 | + |
| 145 | + Assert.Collection(results, result => |
| 146 | + { |
| 147 | + Assert.Equal(firstQuantity.Unit, result.Unit); |
| 148 | + Assert.Equal(firstQuantity.Value, result.Value); |
| 149 | + Assert.Equal(firstQuantity, result); |
| 150 | + }, result => |
| 151 | + { |
| 152 | + Assert.Equal(secondQuantity.Unit, result.Unit); |
| 153 | + Assert.Equal(secondQuantity.Value, result.Value); |
| 154 | + Assert.Equal(secondQuantity, result); |
| 155 | + }); |
| 156 | + } |
| 157 | + |
111 | 158 | [Fact] |
112 | 159 | public virtual void TupleOfMixedValueQuantities_SerializationRoundTrips() |
113 | 160 | { |
|
0 commit comments