26 #region Set Up and Configuration
27 private const string TypeName =
"MonetaryUnit";
30 #endregion Set Up and Configuration
33 [TestMethod, TestCategory(TypeName)]
36 string t = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
37 string d = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
38 string neg = CultureInfo.CurrentCulture.NumberFormat.NegativeSign;
41 Assert.AreEqual($
"USD 123{d}45",
43 Assert.AreEqual($
"USD 12{t}345{t}678{t}901{d}57",
45 Assert.AreEqual($
"USD 0{d}01234",
49 Assert.AreEqual($
"123{d}45",
53 Assert.AreEqual($
"CAD 1{d}234E{neg}06",
55 Assert.AreEqual($
"CAD 1{d}2345678E+55",
57 Assert.AreEqual($
"CAD 1{d}79769313486232E+308",
59 Assert.AreEqual($
"CAD {CultureInfo.CurrentCulture.NumberFormat.PositiveInfinitySymbol}",
63 DateTime aTime =
new DateTime(2017, 8, 16, 1, 2, 3, DateTimeKind.Utc);
64 Assert.AreEqual($
"USD 123{d}45 FX rate fixed to 2017-08-16T01:02:03.0000000Z",
66 Assert.AreEqual($
"USD 123{d}45 FX rate fixed to EUR 0{d}998877",
67 new MonetaryUnit(123.45,
"USD", 0.998877,
"EUR").ToString());
69 Assert.AreEqual($
"123{d}45 FX rate fixed to 1{d}3344",
70 new MonetaryUnit(123.45,
null, 1.3344,
null).ToString());
73 Assert.AreEqual($
"USD {neg}123{d}45",
75 Assert.AreEqual($
"USD {neg}12{t}345{t}678{t}901{d}57",
77 Assert.AreEqual($
"USD {neg}0{d}01234",
79 Assert.AreEqual($
"CAD {neg}1{d}234E{neg}06",
81 Assert.AreEqual($
"CAD {neg}1{d}2345678E+55",
83 Assert.AreEqual($
"CAD {neg}1{d}79769313486232E+308",
85 Assert.AreEqual($
"CAD {CultureInfo.CurrentCulture.NumberFormat.NegativeInfinitySymbol}",
89 Assert.AreEqual($
"USD {CultureInfo.CurrentCulture.NumberFormat.NaNSymbol}",
94 #region Test Helper Methods
95 private void TestPOSTValue(
double value,
bool shouldSucceed)
97 PUT_WithValue(l => l.premium,
new MonetaryUnit(value,
"USD"), shouldSucceed);
99 private void TestPOSTCurrency(
string currency,
bool shouldSucceed)
101 POST_WithValue(l => l.premium,
new MonetaryUnit(0, currency), shouldSucceed);
103 private void TestPUTValue(
double value,
bool shouldSucceed)
105 PUT_WithValue(l => l.premium,
new MonetaryUnit(value,
"USD"), shouldSucceed);
107 private void TestPUTCurrency(
string currency,
bool shouldSucceed)
109 PUT_WithValue(l => l.premium,
new MonetaryUnit(0, currency), shouldSucceed);
111 #endregion Test Helper Methods
114 #region MonetaryUnit.value
115 [TestMethod, TestCategory(TypeName)]
118 TestPOSTValue(Double.MaxValue,
true);
120 [TestMethod, TestCategory(TypeName)]
123 TestPOSTValue(Double.MinValue,
false);
125 [TestMethod, TestCategory(TypeName)]
128 TestPOSTValue(0d,
true);
130 [TestMethod, TestCategory(TypeName)]
133 TestPOSTValue(-1d,
false);
135 [TestMethod, TestCategory(TypeName)]
138 TestPOSTValue(Double.NaN,
false);
140 [TestMethod, TestCategory(TypeName)]
143 TestPOSTValue(Double.PositiveInfinity,
false);
145 [TestMethod, TestCategory(TypeName)]
148 TestPOSTValue(Double.NegativeInfinity,
false);
150 [TestMethod, TestCategory(TypeName)]
153 TestPOSTValue(Math.PI / 1E12,
true);
155 #endregion MonetaryUnit.value
157 #region MonetaryUnit.currency
158 [TestMethod, TestCategory(TypeName)]
161 TestPOSTCurrency(
null,
false);
163 [TestMethod, TestCategory(TypeName)]
166 TestPOSTCurrency(
"",
false);
168 [TestMethod, TestCategory(TypeName)]
171 TestPOSTCurrency(
"AU",
false);
173 [TestMethod, TestCategory(TypeName)]
176 TestPOSTCurrency(
"asdf",
false);
178 [TestMethod, TestCategory(TypeName)]
181 TestPOSTCurrency(
"EUR",
true);
183 [TestMethod, TestCategory(TypeName)]
186 TestPOSTCurrency(
"AAA",
true);
188 #endregion MonetaryUnit.currency
190 #region MonetaryUnit.value_date
191 [TestMethod, TestCategory(TypeName)]
194 POST_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD",
195 new DateTime(2015, 01, 02, 3, 4, 5)),
true);
197 #endregion MonetaryUnit.value_date
199 #region MonetaryUnit.rate
200 [TestMethod, TestCategory(TypeName)]
203 POST_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", 1.23,
"CAD"),
true);
206 [TestMethod, TestCategory(TypeName)]
209 POST_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", 0,
"CAD"),
true);
212 [TestMethod, TestCategory(TypeName)]
215 POST_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", -1.23,
"CAD"),
false);
218 [TestMethod, TestCategory(TypeName)]
221 POST_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", 1.23,
null),
false);
223 #endregion MonetaryUnit.rate
225 #region MonetaryUnit.rate and .value_date
227 [TestMethod, TestCategory(TypeName)]
233 value_date =
new DateTime(2015, 01, 02, 3, 4, 5)
235 POST_WithValue(l => l.premium, toSupply,
false);
237 #endregion MonetaryUnit.rate and .value_date
241 #region MonetaryUnit.value
242 [TestMethod, TestCategory(TypeName)]
245 TestPUTValue(Double.MaxValue,
true);
247 [TestMethod, TestCategory(TypeName)]
250 TestPUTValue(Double.MinValue,
false);
252 [TestMethod, TestCategory(TypeName)]
255 TestPUTValue(0d,
true);
257 [TestMethod, TestCategory(TypeName)]
260 TestPUTValue(-1d,
false);
262 [TestMethod, TestCategory(TypeName)]
265 TestPUTValue(Double.NaN,
false);
267 [TestMethod, TestCategory(TypeName)]
270 TestPUTValue(Double.PositiveInfinity,
false);
272 [TestMethod, TestCategory(TypeName)]
275 TestPUTValue(Double.NegativeInfinity,
false);
277 [TestMethod, TestCategory(TypeName)]
280 TestPUTValue(Math.PI / 1E12,
true);
282 #endregion MonetaryUnit.value
284 #region MonetaryUnit.currency
285 [TestMethod, TestCategory(TypeName)]
290 TestPUTCurrency(
null,
false);
292 [TestMethod, TestCategory(TypeName)]
295 TestPUTCurrency(
"",
false);
297 [TestMethod, TestCategory(TypeName)]
300 TestPUTCurrency(
"AU",
false);
302 [TestMethod, TestCategory(TypeName)]
305 TestPUTCurrency(
"asdf",
false);
307 [TestMethod, TestCategory(TypeName)]
310 TestPUTCurrency(
"EUR",
true);
312 [TestMethod, TestCategory(TypeName)]
315 TestPUTCurrency(
"AAA",
true);
317 #endregion MonetaryUnit.currency
319 #region MonetaryUnit.value_date
320 [TestMethod, TestCategory(TypeName)]
323 PUT_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD",
324 new DateTime(2015, 01, 02, 3, 4, 5)),
true);
326 #endregion MonetaryUnit.value_date
328 #region MonetaryUnit.rate
329 [TestMethod, TestCategory(TypeName)]
332 PUT_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", 1.23,
"CAD"),
true);
335 [TestMethod, TestCategory(TypeName)]
338 PUT_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", 0,
"CAD"),
true);
341 [TestMethod, TestCategory(TypeName)]
344 PUT_WithValue(l => l.premium,
new MonetaryUnit(0,
"USD", -1.23,
"CAD"),
false);
346 #endregion MonetaryUnit.rate
348 #region MonetaryUnit.rate and .value_date
350 [TestMethod, TestCategory(TypeName)]
356 value_date =
new DateTime(2015, 01, 02, 3, 4, 5)
358 PUT_WithValue(l => l.premium, toSupply,
false);
360 #endregion MonetaryUnit.rate and .value_date