72 #region Set Up and Configuration
73 private const string TypeName =
"IAPIResourceView";
74 #endregion Set Up and Configuration
91 #region analysis_profile
92 [TestMethod, TestCategory(TypeName)]
95 POST_Attribute_Null(l => l.analysis_profile);
97 [TestMethod, TestCategory(TypeName)]
100 POST_Reference_NullId(l => l.analysis_profile);
102 [TestMethod, TestCategory(TypeName)]
105 POST_Reference_EmptyStringId(l => l.analysis_profile);
107 [TestMethod, TestCategory(TypeName)]
110 POST_Reference_NonExistantId(l => l.analysis_profile);
112 #endregion analysis_profile
114 #region target_currency
115 [TestMethod, TestCategory(TypeName)]
118 POST_Attribute_Null(l => l.target_currency);
120 [TestMethod, TestCategory(TypeName)]
123 POST_WithValue(l => l.target_currency,
"EUR",
true);
125 #endregion target_currency
129 #region Helper Methods
135 Action<TException> exceptionTest) where TException : Exception
138 AssertApi.ExceptionThrown(() => action(posted), exceptionTest));
145 if (leastGranularPerspective ==
null)
154 private static void Test_Metrics_Perspective(T posted,
Perspective perspective,
161 posted.exceedance_probability_blocking(1,
165 Assert.Fail(
"Metrics for perspective " + perspective +
166 " succeeded, when an error was expected.");
173 Assert.Fail(
"Metrics for perspective " + perspective +
" failed, when " +
174 "it was expected to succeed: " + ex.
ServerError.message);
177 Assert.AreEqual(HttpStatusCode.BadRequest, ex.
RestResponse.StatusCode);
184 string expectedMessage = min < 0 || min >= 1 ?
"The min probability must be " +
185 (min < 0 ?
"greater than or equal to zero." :
"less than one.") +
" The range is [0,1)" :
186 max <= 0 || max > 1 ?
"The max probability must be " +
187 (max <= 0 ?
"greater than zero." :
"less than or equal to one.") +
" The range is (0,1]" :
188 "The max probability must be greater or equal to than the min probability.";
189 return ex => Assert.IsTrue(ex.Message.StartsWith(expectedMessage),
190 "Expected an ArgumentOutOfRangeException with an error message starting with:\n" +
191 $
"{expectedMessage}\n{ex.Message}\n^ This was the actual message. " +
192 $
"Full Exception Details:\n{ex}");
194 #endregion Helper Methods
197 #region Helper Methods
198 private void Test_IAPIResourceView_GET_TailMetrics_Succeeds(
202 arg => GetTailMetricsAction(probability, options)(arg));
205 private void Test_IAPIResourceView_GET_TailMetrics_Fails<TException>(
206 Action<TException> exceptionTest,
double probability,
MetricsOptions options =
null)
207 where TException : Exception
209 Test_IAPIResourceView_Action_Fails(
210 arg => GetTailMetricsAction(probability, options)(arg), exceptionTest);
213 private static Func<T, TailMetrics> GetTailMetricsAction(
221 AssertTailDistributionMetricsExist(result);
223 RunTailMetricsContextAssertions(view, probability, options, result.
context);
232 Assert.IsNotNull(result);
233 Assert.AreNotEqual(Double.NaN, result.
min,
"min was not assigned a value.");
234 Assert.AreNotEqual(Double.NaN, result.
mean,
"mean was not assigned a value.");
235 Assert.AreNotEqual(Double.NaN, result.
max,
"max was not assigned a value.");
236 Assert.AreNotEqual(Double.NaN, result.
variance,
"variance was not assigned a value.");
237 Assert.AreNotEqual(Double.NaN, result.
skewness,
"skewness was not assigned a value.");
238 Assert.AreNotEqual(Double.NaN, result.
kurtosis,
"kurtosis was not assigned a value.");
241 private static void RunTailMetricsContextAssertions(
248 AssertBasicOptionsMatchContext(view, options, context);
250 Assert.AreEqual(options.
currency ?? view.target_currency, context.currency);
255 Assert.IsTrue(context.apply_participation);
274 Assert.AreEqual(expectedFilter, context.
filter);
279 Assert.AreEqual(expectedPerspective, context.
perspective);
292 #endregion Helper Methods
295 [TestMethod, TestCategory(TypeName)]
298 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1);
299 Test_IAPIResourceView_GET_TailMetrics_Succeeds(0.01);
301 Test_IAPIResourceView_GET_TailMetrics_Succeeds(Math.PI / 4d);
303 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1.234556789E-12);
306 [TestMethod, TestCategory(TypeName)]
309 void TestBadProbability(
double probability) =>
311 Test_IAPIResourceView_GET_TailMetrics_Fails(
ProbabilityError(0, probability), probability);
313 TestBadProbability(0);
314 TestBadProbability(1.00000000000001);
315 TestBadProbability(2);
316 TestBadProbability(-0.5);
317 TestBadProbability(Double.MinValue);
318 TestBadProbability(Double.MaxValue);
321 [TestMethod, TestCategory(TypeName)]
326 List<IReference<LossFilter>> availableFilters =
327 Reflection.Resolve(view.analysis_profile).loss_filters;
333 [TestMethod, TestCategory(TypeName)]
336 Test_IAPIResourceView_GET_TailMetrics_Fails(
341 #region Test Perspectives
344 private void TestGetTailMetricsForPerspective(T view,
Perspective persp) =>
346 $
"Get TailMetrics for perspective {persp}");
348 [TestMethod, TestCategory(TypeName)]
352 TestGetTailMetricsForPerspective(view, perspective)));
355 [TestMethod, TestCategory(TypeName)]
356 [Obsolete(
"Tests an obsolete factory method for constructing legacy perspectives")]
360 TestGetTailMetricsForPerspective(view, perspective)));
362 #endregion Test Perspectives
364 [TestMethod, TestCategory(TypeName)]
367 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1,
new MetricsOptions(
"GBP"));
370 [TestMethod, TestCategory(TypeName)]
373 Test_IAPIResourceView_GET_TailMetrics_Fails(
378 [TestMethod, TestCategory(TypeName)]
381 Test_IAPIResourceView_GET_TailMetrics_Succeeds(0.95d,
385 [TestMethod, TestCategory(TypeName)]
388 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1 / 3d,
391 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1 / 3d,
395 [TestMethod, TestCategory(TypeName)]
398 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1 / 3d,
new MetricsOptions(
399 reporting_period:
new ReportingPeriod(DateTime.UtcNow, DateTime.UtcNow.AddYears(1))));
402 [TestMethod, TestCategory(TypeName)]
405 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1 / 3d,
408 Test_IAPIResourceView_GET_TailMetrics_Succeeds(1 / 3d,
412 [TestMethod, TestCategory(TypeName)]
417 double expectedLoss =
API.PollUntilReady(
419 TailMetrics metrics = view.tail_metrics_blocking(1,
425 [TestMethod, TestCategory(TypeName)]
430 double tvar =
API.PollUntilReady(
432 TailMetrics metrics = view.tail_metrics_blocking(0.5,
438 [TestMethod, TestCategory(TypeName)]
443 List<TailMetrics> result = view.tail_metrics_blocking(
444 new List<double> { 0.1, 1, 0.5, 0.25 },
448 Assert.AreEqual(4, result.Count,
"Expected 4 TailMetrics responses");
459 [TestMethod, TestCategory(TypeName)]
466 List<TailMetrics> result = view.tail_metrics_blocking(
469 Assert.AreEqual(1, result.Count,
"Expected 1 TailMetrics response in a list");
474 [TestMethod, TestCategory(TypeName)]
482 arg.tail_metrics_blocking(1, options);
483 arg.tail_metrics_blocking(0.5, options);
484 arg.tail_metrics_blocking(
new[] { 1d }, options);
485 arg.tail_metrics_blocking(
new List<double> { 1, 0.5, 0.25 }, options);
486 arg.tail_metrics_blocking(
new HashSet<double> { 1, 0.5, 0.25 }, options);
487 arg.tail_metrics_blocking(Enumerable.Range(1, 10).Select(i => 1d / i), options);
488 arg.tail_metrics(1, options);
489 arg.tail_metrics(0.5, options);
490 arg.tail_metrics(
new[] { 1d }, options);
491 arg.tail_metrics(
new List<double> { 1, 0.5, 0.25 }, options);
492 arg.tail_metrics(
new HashSet<double> { 1, 0.5, 0.25 }, options);
493 arg.tail_metrics(Enumerable.Range(1, 10).Select(i => 1d / i), options);
494 arg.expected_loss(options);
495 arg.var(0.5, options);
496 arg.tvar(0.5, options);
500 [TestMethod, TestCategory(TypeName)]
507 Double probability = 0.25;
508 TailMetrics regular_metrics = view.tail_metrics_blocking(probability,
511 $
"/{view.collection_name}/{view.id}/tail_metrics/{probability}",
516 Assert.AreEqual(regular_metrics.
mean, endpoint_metrics.
mean);
522 #endregion Test Methods
523 #endregion TailMetrics
525 #region WindowMetrics
526 #region Helper Methods
527 private void Test_IAPIResourceView_GET_WindowMetrics_Succeeds(
531 arg => GetWindowMetricsAction(range, options)(arg));
534 private void Test_IAPIResourceView_GET_WindowMetrics_Fails<TException>(
536 where TException : Exception
538 Test_IAPIResourceView_Action_Fails(
539 arg => GetWindowMetricsAction(range, options)(arg), exceptionTest);
542 private static Func<T, WindowMetrics> GetWindowMetricsAction(
550 AssertTailDistributionMetricsExist(result);
552 RunWindowMetricsContextAssertions(view, range, options, result.
context);
557 private static void RunWindowMetricsContextAssertions(
564 AssertBasicOptionsMatchContext(view, options, context);
567 Assert.AreEqual(options.
currency ?? view.target_currency, context.currency);
572 Assert.IsTrue(context.apply_participation);
577 #endregion Helper Methods
580 [TestMethod, TestCategory(TypeName)]
584 Test_IAPIResourceView_GET_WindowMetrics_Succeeds(
new ProbabilityWindow(0.01, 1));
586 Test_IAPIResourceView_GET_WindowMetrics_Succeeds(
new ProbabilityWindow(Math.PI / 10d, Math.PI / 4d));
589 Test_IAPIResourceView_GET_WindowMetrics_Succeeds(
new ProbabilityWindow(0, 1.234556789E-12));
592 [TestMethod, TestCategory(TypeName)]
595 void TestBadProbability(
double min,
double max)
600 Test_IAPIResourceView_Action_Fails(
601 arg => arg.GetSubResource<
WindowMetrics>($
"window_metrics/{min}_{max}/"),
605 TestBadProbability(0, 0);
606 TestBadProbability(1, 1);
607 TestBadProbability(0, 1.00000000000001);
608 TestBadProbability(0, 2);
609 TestBadProbability(-.1, 0);
610 TestBadProbability(0, Double.MaxValue);
611 TestBadProbability(Double.MinValue, 0);
612 TestBadProbability(0, Double.MinValue);
613 TestBadProbability(Double.MaxValue, 0);
614 TestBadProbability(.5, .4);
615 TestBadProbability(1, 0);
618 [TestMethod, TestCategory(TypeName)]
623 List<IReference<LossFilter>> availableFilters =
624 Reflection.Resolve(view.analysis_profile).loss_filters;
631 [TestMethod, TestCategory(TypeName)]
634 Test_IAPIResourceView_GET_WindowMetrics_Fails(
639 #region Test Perspectives
642 private void TestGetWindowMetricsForPerspective(T view,
Perspective persp) =>
644 new MetricsOptions(perspective: persp))(view), $
"Get WindowMetrics for perspective {persp}");
646 [TestMethod, TestCategory(TypeName)]
650 TestGetWindowMetricsForPerspective(view, perspective)));
653 [TestMethod, TestCategory(TypeName)]
654 [Obsolete(
"Tests an obsolete factory method for constructing legacy perspectives")]
658 TestGetWindowMetricsForPerspective(view, perspective)));
660 #endregion Test Perspectives
662 [TestMethod, TestCategory(TypeName)]
668 [TestMethod, TestCategory(TypeName)]
671 Test_IAPIResourceView_GET_WindowMetrics_Fails(
676 [TestMethod, TestCategory(TypeName)]
683 [TestMethod, TestCategory(TypeName)]
693 [TestMethod, TestCategory(TypeName)]
697 reporting_period:
new ReportingPeriod(DateTime.UtcNow, DateTime.UtcNow.AddYears(1))));
700 [TestMethod, TestCategory(TypeName)]
710 [TestMethod, TestCategory(TypeName)]
715 double expectedLoss =
API.PollUntilReady(
723 [TestMethod, TestCategory(TypeName)]
728 double tvar =
API.PollUntilReady(
736 [TestMethod, TestCategory(TypeName)]
741 List<WindowMetrics> result = view.window_metrics_blocking(
742 new List<ProbabilityWindow> {
751 Assert.AreEqual(4, result.Count,
"Expected 4 WindowMetrics responses");
756 [TestMethod, TestCategory(TypeName)]
763 List<WindowMetrics> result = view.window_metrics_blocking(
767 Assert.AreEqual(1, result.Count,
"Expected 1 WindowMetrics response in a list");
773 [TestMethod, TestCategory(TypeName)]
781 arg.window_metrics_blocking(
new[] { ProbabilityWindow.All }, options);
786 arg.window_metrics_blocking(Enumerable.Range(1, 10).Select(i =>
ProbabilityWindow.
Tail(1d / i)), options);
787 arg.window_metrics(
new[] { ProbabilityWindow.All }, options);
796 [TestMethod, TestCategory(TypeName)]
797 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
805 arg.window_metrics_blocking(1, options);
806 arg.window_metrics_blocking(0.5, options);
807 arg.window_metrics(1, options);
808 arg.window_metrics(0.5, options);
811 #endregion Test Methods
812 #endregion WindowMetrics
814 #region ExceedanceProbability
815 #region Helper Methods
820 arg => GetExceedanceProbabilityAction(threshold, options)(arg));
823 private void Test_IAPIResourceView_GET_ExceedanceProbability_Fails<TException>(
825 where TException : Exception
827 Test_IAPIResourceView_Action_Fails(
828 arg => GetExceedanceProbabilityAction(threshold, options)(arg), exceptionTest);
831 private static Func<T, ExceedanceProbability> GetExceedanceProbabilityAction(
839 Assert.AreNotEqual(Double.NaN, result.
probability,
"probability was not assigned a value.");
841 RunExceedanceProbContextAssertions(view, threshold, options, result.
context);
846 private static void RunExceedanceProbContextAssertions(
854 AssertBasicOptionsMatchContext(view, options, context);
857 Assert.AreEqual(options.
threshold_currency ?? view.target_currency, context.threshold_currency);
862 Assert.IsTrue(context.threshold_includes_participation);
866 context.threshold_includes_participation);
868 #endregion Helper Methods
872 [TestMethod, TestCategory(TypeName)]
889 [TestMethod, TestCategory(TypeName)]
894 List<IReference<LossFilter>> availableFilters =
895 Reflection.Resolve(view.analysis_profile).loss_filters;
898 GetExceedanceProbabilityAction(0, options.Change(o => o.filter,
903 [TestMethod, TestCategory(TypeName)]
906 Test_IAPIResourceView_GET_ExceedanceProbability_Fails(
911 #region Test Perspectives
914 private void TestGetExceedanceProbabilityForPerspective(T view,
Perspective persp) =>
917 $
"Get ExceedanceProbability for perspective {persp}");
919 [TestMethod, TestCategory(TypeName)]
923 TestGetExceedanceProbabilityForPerspective(view, perspective)));
926 [TestMethod, TestCategory(TypeName)]
927 [Obsolete(
"Tests an obsolete factory method for constructing legacy perspectives")]
931 TestGetExceedanceProbabilityForPerspective(view, perspective)));
933 #endregion Test Perspectives
935 [TestMethod, TestCategory(TypeName)]
941 .Change(o => o.inclusive_threshold,
false);
942 double exclusive = GetExceedanceProbabilityAction(0, exclusiveOptions)(view).probability;
945 .Change(o => o.inclusive_threshold,
true);
946 double inclusive = GetExceedanceProbabilityAction(0, inclusiveOptions)(view).probability;
947 Console.WriteLine(
"Exceedance Probability for a threshold of 0 - " +
948 $
"Inclusive: {exclusive:P2} Exclusive: {inclusive:P2}");
953 exclusive = GetExceedanceProbabilityAction(max, exclusiveOptions)(view).probability;
954 Assert.AreEqual(0, exclusive,
"Expected the exclusive exceedance probability " +
955 $
"of {max} to be 0%, because it is the largest loss (nothing exceeds it).");
958 inclusive = GetExceedanceProbabilityAction(max, inclusiveOptions)(view).probability;
959 Console.WriteLine($
"Exceedance Probability for a threshold of {max} - " +
960 $
"Inclusive: {exclusive:P2} Exclusive: {inclusive:P2}");
961 Assert.AreNotEqual(exclusive, inclusive,
"Expected the inclusive and " +
962 "exclusive exceedance probabilities to be different.");
966 double defaultV = GetExceedanceProbabilityAction(max, defaultOptions)(view).probability;
967 Assert.AreEqual(defaultV, exclusive,
968 "Expected the default result to match the result of " +
969 "explicitly excluding the threshold for the exceedance probability.");
973 [TestMethod, TestCategory(TypeName)]
980 [TestMethod, TestCategory(TypeName)]
983 Test_IAPIResourceView_GET_ExceedanceProbability_Fails(
988 [TestMethod, TestCategory(TypeName)]
995 [TestMethod, TestCategory(TypeName)]
1005 [TestMethod, TestCategory(TypeName)]
1009 reporting_period:
new ReportingPeriod(DateTime.UtcNow, DateTime.UtcNow.AddYears(1))));
1012 [TestMethod, TestCategory(TypeName)]
1022 [TestMethod, TestCategory(TypeName)]
1027 List<ExceedanceProbability> result = view.exceedance_probability_blocking(
1028 new List<double> { 10000, 0, 100, 1000 },
1032 Assert.AreEqual(4, result.Count,
"Expected 4 TailMetrics responses");
1043 [TestMethod, TestCategory(TypeName)]
1051 arg.exceedance_probability_blocking(1, options);
1052 arg.exceedance_probability_blocking(1.23E6, options);
1053 arg.exceedance_probability_blocking(
new[] { 1.23E6 }, options);
1054 arg.exceedance_probability_blocking(
new List<double> { 1, 2, 3 }, options);
1055 arg.exceedance_probability_blocking(
new HashSet<double> { 1, 0.5, 0.25 }, options);
1056 arg.exceedance_probability_blocking(Enumerable.Range(1, 10).Select(i => 1d / i), options);
1057 arg.exceedance_probability(1, options);
1058 arg.exceedance_probability(1.23E6, options);
1059 arg.exceedance_probability(
new[] { 1.23E6 }, options);
1060 arg.exceedance_probability(
new List<double> { 1, 2, 3 }, options);
1061 arg.exceedance_probability(
new HashSet<double> { 1, 0.5, 0.25 }, options);
1062 arg.exceedance_probability(Enumerable.Range(1, 10).Select(i => 1d / i), options);
1065 #endregion Test Methods
1066 #endregion ExceedanceProbability
1069 #region Helper Methods
1074 Assert.Inconclusive(
"RUN_OFFLINE = true");
1075 if (_layerViewComponentSingleton !=
null)
1076 return _layerViewComponentSingleton;
1078 component.description =
"Component Layer";
1081 _layerViewComponentSingleton = lv.ToReference();
1082 return _layerViewComponentSingleton;
1089 Assert.Inconclusive(
"RUN_OFFLINE = true");
1093 layer_views =
new HashSet<IReference<ILayerView>> { layerView },
1094 analysis_profile = TestResource.analysis_profile
1096 return pv.Post().ToReference();
1099 private void Test_IAPIResourceView_GET_CoMetrics_Succeeds(
ProbabilityWindow range,
1101 Action<CoMetrics> additionalAssertions =
null)
1105 CoMetrics response = GetCoMetricsAction(range, component, options)(arg);
1106 additionalAssertions?.Invoke(response);
1110 private void Test_IAPIResourceView_GET_CoMetrics_Fails<TException>(
1113 where TException : Exception
1115 Test_IAPIResourceView_Action_Fails(
1116 arg => GetCoMetricsAction(range, component, options)(arg), exceptionTest);
1124 CoMetrics result = view.co_metrics_blocking(
1129 RunCoMetricsContextAssertions(view, range, component, options, result.
context);
1131 if (options?.include_primary_metrics ??
false)
1141 Assert.IsNotNull(result);
1142 Assert.AreNotEqual(Double.NaN, result.
min,
"min was not assigned a value.");
1143 Assert.AreNotEqual(Double.NaN, result.
mean,
"mean was not assigned a value.");
1144 Assert.AreNotEqual(Double.NaN, result.
covariance,
"covariance was not assigned a value.");
1145 Assert.AreNotEqual(Double.NaN, result.
correlation,
"correlation was not assigned a value.");
1148 private static void RunCoMetricsContextAssertions(
1153 RunWindowMetricsContextAssertions(view, range, options, context);
1160 Assert.AreEqual(component, context.component);
1165 Assert.AreEqual(expectedComponentFilter, context.component_filter);
1169 Perspective expectedComponentPerspective = options.component_perspective ??
1171 Assert.AreEqual(expectedComponentPerspective, context.component_perspective);
1181 context.include_primary_metrics);
1186 Assert.IsTrue(context.apply_participation);
1191 #endregion Helper Methods
1193 #region Test Methods
1194 [TestMethod, TestCategory(TypeName)]
1198 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
ProbabilityWindow.
Tail(0.01), GetLayerViewComponent());
1200 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
ProbabilityWindow.
Tail(Math.PI / 4d), GetLayerViewComponent());
1201 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
new ProbabilityWindow(Math.PI / 4d, 1), GetLayerViewComponent());
1203 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
new ProbabilityWindow(0, 1.234556789E-12), GetLayerViewComponent());
1204 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
ProbabilityWindow.
Tail(1.234556789E-12), GetLayerViewComponent());
1207 [TestMethod, TestCategory(TypeName)]
1210 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
ProbabilityWindow.
All, GetPortfolioViewComponent());
1211 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
new ProbabilityWindow(0, 0.01), GetLayerViewComponent());
1213 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
new ProbabilityWindow(0, Math.PI / 4d), GetPortfolioViewComponent());
1214 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
new ProbabilityWindow(Math.PI / 4d, 1), GetPortfolioViewComponent());
1216 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
new ProbabilityWindow(0, 1.234556789E-12), GetPortfolioViewComponent());
1217 Test_IAPIResourceView_GET_CoMetrics_Succeeds(
ProbabilityWindow.
Tail(1.234556789E-12), GetPortfolioViewComponent());
1220 [TestMethod, TestCategory(TypeName)]
1223 void TestBadProbability(
double min,
double max)
1228 Test_IAPIResourceView_Action_Fails(
1229 arg => arg.GetSubResource<
WindowMetrics>($
"window_co_metrics/{min}_{max}/" +
1230 $
"?component_id={arg.id}&component_type=LayerView"),
1234 TestBadProbability(0, 0);
1235 TestBadProbability(1, 1);
1236 TestBadProbability(0, 1.00000000000001);
1237 TestBadProbability(0, 2);
1238 TestBadProbability(-.1, 0);
1239 TestBadProbability(0, Double.MaxValue);
1240 TestBadProbability(Double.MinValue, 0);
1241 TestBadProbability(0, Double.MinValue);
1242 TestBadProbability(Double.MaxValue, 0);
1243 TestBadProbability(.5, .4);
1244 TestBadProbability(1, 0);
1247 [TestMethod, TestCategory(TypeName)]
1255 Double probability = 0.25;
1259 queryParams.AddParameter(
"component_id", GetLayerViewComponent().ref_id, RestSharp.ParameterType.QueryString);
1260 queryParams.AddParameter(
"component_type",
"LayerView", RestSharp.ParameterType.QueryString);
1262 Method.GET, queryParams);
1273 #region Filter Tests
1274 [TestMethod, TestCategory(TypeName)]
1278 GetLayerViewComponent(), GetPortfolioViewComponent()
1282 List<IReference<LossFilter>> availableFilters =
1283 Reflection.Resolve(view.analysis_profile).loss_filters;
1287 string filterName =
Reflection.Resolve(lf).name;
1296 [TestMethod, TestCategory(TypeName)]
1299 Test_IAPIResourceView_GET_CoMetrics_Fails(
1304 [TestMethod, TestCategory(TypeName)]
1307 Test_IAPIResourceView_GET_CoMetrics_Fails(
1312 #endregion Filter Tests
1314 #region Perspective Tests
1334 [TestMethod, TestCategory(TypeName)]
1337 List<IReference<IAPIResourceView>> testComponents =
1338 new List<IReference<IAPIResourceView>> { GetLayerViewComponent(), GetPortfolioViewComponent() };
1341 TestGetCoMetricsForPerspective(view, component, perspective))));
1344 [TestMethod, TestCategory(TypeName)]
1345 [Obsolete(
"Tests an obsolete factory method for constructing legacy perspectives")]
1348 List<IReference<IAPIResourceView>> testComponents =
1349 new List<IReference<IAPIResourceView>> { GetLayerViewComponent(), GetPortfolioViewComponent() };
1352 TestGetCoMetricsForPerspective(view, component, perspective))));
1354 #endregion Perspective Tests
1356 [TestMethod, TestCategory(TypeName)]
1363 [TestMethod, TestCategory(TypeName)]
1366 Test_IAPIResourceView_GET_CoMetrics_Fails(
1371 [TestMethod, TestCategory(TypeName)]
1375 GetLayerViewComponent(),
new CoMetricsOptions(include_primary_metrics:
true),
1376 cometrics => Assert.IsNotNull(cometrics.primary_metrics));
1379 [TestMethod, TestCategory(TypeName)]
1383 GetLayerViewComponent(),
new CoMetricsOptions(include_primary_metrics:
false),
1384 cometrics => Assert.IsNull(cometrics.primary_metrics));
1387 [TestMethod, TestCategory(TypeName)]
1393 GetLayerViewComponent(),
new CoMetricsOptions(aggregation_method: aggMethod));
1397 [TestMethod, TestCategory(TypeName)]
1401 GetLayerViewComponent(),
new CoMetricsOptions(secondary_uncertainty:
true));
1404 GetLayerViewComponent(),
new CoMetricsOptions(secondary_uncertainty:
false));
1407 [TestMethod, TestCategory(TypeName)]
1415 [TestMethod, TestCategory(TypeName)]
1423 [TestMethod, TestCategory(TypeName)]
1430 GetLayerViewComponent(),
new CoMetricsOptions(apply_participation:
false));
1433 [TestMethod, TestCategory(TypeName)]
1436 DateTime now = DateTime.UtcNow;
1440 reporting_period:
new ReportingPeriod(now.AddYears(-1), now.AddYears(1)),
1441 component_reporting_period:
new ReportingPeriod(now, now.AddMonths(3))),
1451 [TestMethod, TestCategory(TypeName)]
1454 DateTime now = DateTime.UtcNow;
1459 component_reporting_period:
new ReportingPeriod(
null, now.AddMonths(3))),
1464 Assert.IsNull(result.context.reporting_period_end);
1469 reporting_period:
new ReportingPeriod(now.AddYears(-1), now.AddYears(1)),
1480 [TestMethod, TestCategory(TypeName)]
1483 DateTime now = DateTime.UtcNow;
1486 Test_IAPIResourceView_GET_CoMetrics_Fails(
1492 component_reporting_period:
new ReportingPeriod(
null, now.AddDays(-1))));
1493 Test_IAPIResourceView_GET_CoMetrics_Fails(
1497 component_reporting_period:
new ReportingPeriod(now.AddYears(2),
null)));
1500 [TestMethod, TestCategory(TypeName)]
1505 List<CoMetrics> result = view.co_metrics_blocking(
1506 new List<ProbabilityWindow> {
1515 Assert.AreEqual(4, result.Count,
"Expected 4 TailMetrics responses");
1526 [TestMethod, TestCategory(TypeName)]
1534 arg.co_metrics_blocking(
new[] { ProbabilityWindow.All }, arg.ToReference(), options);
1540 arg.ToReference(), options);
1541 arg.co_metrics(
new[] { ProbabilityWindow.All }, arg.ToReference(), options);
1547 arg.ToReference(), options);
1550 #endregion Test Methods
1552 #region Legacy Test Methods
1553 #region Helper Methods
1554 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1555 private void Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(
double probability,
1557 Action<CoMetrics> additionalAssertions =
null)
1561 CoMetrics response = GetCoMetricsLegacyAction(probability, component, options)(arg);
1562 additionalAssertions?.Invoke(response);
1566 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1567 private static Func<T, CoMetrics> GetCoMetricsLegacyAction(
double probability,
1572 CoMetrics result = view.co_metrics_blocking(
1577 RunCoMetricsContextAssertions(view, probability, component, options, result.
context);
1579 if (options?.include_primary_metrics ??
false)
1585 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1586 private static void RunCoMetricsContextAssertions(
1591 RunTailMetricsContextAssertions(view, probability, options, context);
1594 component, options, context);
1596 #endregion Helper Methods
1598 [TestMethod, TestCategory(TypeName)]
1599 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1602 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(1, GetLayerViewComponent());
1603 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(0.01, GetLayerViewComponent());
1605 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(Math.PI / 4d, GetLayerViewComponent());
1607 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(1.234556789E-12, GetLayerViewComponent());
1610 [TestMethod, TestCategory(TypeName)]
1611 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1614 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(1, GetPortfolioViewComponent());
1615 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(0.01, GetPortfolioViewComponent());
1617 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(Math.PI / 4d, GetPortfolioViewComponent());
1619 Test_IAPIResourceView_GET_CoMetrics_Legacy_Succeeds(1.234556789E-12, GetPortfolioViewComponent());
1622 [TestMethod, TestCategory(TypeName)]
1623 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1627 void TestBadProbability(
double probability) =>
1629 Test_IAPIResourceView_Action_Fails(
1633 TestBadProbability(0);
1634 TestBadProbability(1.00000000000001);
1635 TestBadProbability(2);
1636 TestBadProbability(-0.5);
1637 TestBadProbability(Double.MinValue);
1638 TestBadProbability(Double.MaxValue);
1641 [TestMethod, TestCategory(TypeName)]
1642 [Obsolete(
"Tests an obsolete method for backwards compatibility.")]
1647 List<CoMetrics> result = view.co_metrics_blocking(
1648 new List<double> { 0.1, 1, 0.5, 0.25 },
1652 Assert.AreEqual(4, result.Count,
"Expected 4 TailMetrics responses");
1655 #endregion Legacy Test Methods
1656 #endregion CoMetrics
1659 #region File Download Endpoints
1660 #region Legacy Back-Allocation
1661 [Obsolete(
"Tests the legacy back_allocations endpoint")]
1671 [TestMethod, TestCategory(TypeName), Obsolete(
"Tests the legacy back_allocations endpoint")]
1682 [TestMethod, TestCategory(TypeName), Obsolete(
"Tests the legacy back_allocations endpoint")]
1685 Test_IAPIResourceView_Action_Fails(view =>
1689 #endregion Legacy Back-Allocation
1692 [TestMethod, TestCategory(TypeName)]
1698 Assert.IsNotNull(result);
1707 [TestMethod, TestCategory(TypeName)]
1712 IRestResponse result = view.yelt.GetStream(stream =>
1714 using (StreamReader reader =
new StreamReader(stream))
1716 string fullYELT = reader.ReadToEnd();
1717 Assert.IsNotNull(fullYELT);
1718 Console.WriteLine(fullYELT);
1722 Assert.AreEqual(ResponseStatus.Completed, result.ResponseStatus);
1723 Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
1727 [TestMethod, TestCategory(TypeName)]
1732 IRestResponse result = view.yelt.GetStream(stream =>
1734 using (StreamReader reader =
new StreamReader(stream))
1737 for (
string line = reader.ReadLine(); line !=
null; line = reader.ReadLine())
1739 string trial = line.Split(
',').ElementAt(0);
1740 Assert.IsTrue(trial ==
"2" || trial ==
"3");
1743 },
new YELTOptions(start_trial: 2, end_trial: 3),
true);
1744 Assert.AreEqual(ResponseStatus.Completed, result.ResponseStatus);
1745 Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
1749 [TestMethod, TestCategory(TypeName)]
1758 IRestResponse result = view.yelt.GetStream(stream =>
1760 using (StreamReader reader =
new StreamReader(stream))
1762 string headerLine = reader.ReadLine();
1763 string[] headers = headerLine.Split(
',');
1764 Assert.IsTrue(additionalColumns.All(c => headers.Any(h => h.Contains(c.ToString(
"G")))));
1766 for (
string line = reader.ReadLine(); line !=
null; line = reader.ReadLine())
1768 int field_count = line.Count(c => c ==
',') + 1;
1769 Assert.AreEqual(4 + additionalColumns.Length, field_count);
1772 },
new YELTOptions(additional_columns: additionalColumns.Aggregate((l, r) => l | r)),
true);
1773 Assert.AreEqual(ResponseStatus.Completed, result.ResponseStatus);
1774 Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
1780 #endregion File Download Endpoints