C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_SimulationOptions.cs
Go to the documentation of this file.
1using System;
2using AnalyzeRe;
7
8#if MSTEST
9using Microsoft.VisualStudio.TestTools.UnitTesting;
10#elif NUNIT
11using NUnit.Framework;
12using TestClass = NUnit.Framework.TestFixtureAttribute;
13using TestMethod = NUnit.Framework.TestAttribute;
14using TestCategory = NUnit.Framework.CategoryAttribute;
15#endif
16
18{
21 [TestClass]
23 {
24 private const string Category = "SimulationOptions";
25
26 #region Reporting Period
27 private void AssertReportingPeriodMatches(SimulationOptions options, Context context)
28 {
29 // Check that reporting period matches within tolerance (if set)
32 }
33
34 private void TestAllMetricsResponses(SimulationOptions options)
35 {
37
39 Assert.Inconclusive("RUN_OFFLINE = true");
41 // Check that each request type correctly relays the expected reporting period
42 TailMetrics metrics = view.tail_metrics_blocking(1,
43 new MetricsOptions(options), simulationPolling);
44 AssertReportingPeriodMatches(options, metrics.context);
45 WindowMetrics windowMetrics = view.window_metrics_blocking(
46 ProbabilityWindow.All, new MetricsOptions(options), simulationPolling);
47 AssertReportingPeriodMatches(options, windowMetrics.context);
48 CoMetrics cometrics = view.co_metrics_blocking(ProbabilityWindow.All, view.ToReference(),
49 new CoMetricsOptions(options), simulationPolling);
50 AssertReportingPeriodMatches(options, cometrics.context);
51 ExceedanceProbability exprob = view.exceedance_probability_blocking(0,
52 new ExceedanceProbabilityOptions(options), simulationPolling);
53 AssertReportingPeriodMatches(options, exprob.context);
54 // YELT and YLT download don't have a context, so we have to trust those work too.
55 // TODO: Contrive data and a reporting period to assert that they do work.
56 }
57
58 [TestMethod, TestCategory(Category)]
60 {
61 TestAllMetricsResponses(new SimulationOptions(reporting_period:
62 new ReportingPeriod(DateTime.UtcNow)));
63 }
64
65 [TestMethod, TestCategory(Category)]
67 {
68 TestAllMetricsResponses(new SimulationOptions(reporting_period:
69 new ReportingPeriod(end: DateTime.UtcNow.AddDays(31))));
70 }
71
72 [TestMethod, TestCategory(Category)]
74 {
75 TestAllMetricsResponses(new SimulationOptions(reporting_period:
76 new ReportingPeriod(new DateTime(DateTime.MinValue.Ticks, DateTimeKind.Utc))));
77 }
78
79 [TestMethod, TestCategory(Category)]
81 {
82 TestAllMetricsResponses(new SimulationOptions(reporting_period:
83 new ReportingPeriod(end: new DateTime(DateTime.MaxValue.Ticks, DateTimeKind.Utc))));
84 }
85
86 [TestMethod, TestCategory(Category)]
88 {
89 TestAllMetricsResponses(new SimulationOptions(reporting_period:
90 new ReportingPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1))));
91 }
92
93 [TestMethod, TestCategory(Category)]
95 {
96 DateTime now = new DateTime(DateTime.UtcNow.Ticks, DateTimeKind.Unspecified);
97 TestAllMetricsResponses(new SimulationOptions(reporting_period:
98 new ReportingPeriod(new DateTimeOffset(now, TimeSpan.FromHours(1)).LocalDateTime,
99 new DateTimeOffset(now, TimeSpan.FromHours(-1)).LocalDateTime)));
100 }
101
102 [TestMethod, TestCategory(Category)]
104 {
105 DateTime now = DateTime.UtcNow;
106 AssertApi.ExceptionThrown(() =>
107 new SimulationOptions(reporting_period: new ReportingPeriod(now, now)),
108 (ArgumentException ex) => Assert.AreEqual("When both a begin and end date are specified, " +
109 "the begin date must be less than end date.", ex.Message));
110 }
111 #endregion Reporting Period
112 }
113}
Create a test class that takes care of setting the server URL and cleaning up after each unit test.
Exposes sample resource objects, with built-in methods for injecting dependencies.
Definition Samples.cs:14
IInjectableResource< ILayerView< CatXL > > LayerView_CatXL
Test the ReportingPeriod class to ensure ReportingPeriods instantiated in different ways can be succe...
Contains static helper methods for testing IAPIResourceView instances.
static readonly PollingOptions SimulationPolling
Settings used to ensure simulation requests are retried frequently and timeout after a reasonable amo...
static void DatesAreEqual(DateTime? dt1, DateTime? dt2, string propertyName="DateTime")
Asserts that two dates are equal within the supported precision. Analyze Re only supports a precision...
Definition AssertApi.cs:635
Retrieve settings from environment variables if they exist, or the project settings file otherwise.
static bool RUN_OFFLINE
Controls whether tests that normally require a connection to the server should be allowed to try to r...
Optional parameters which can be specified for co-metrics requests.
The structure returned when requesting Co-Metrics for a view.
Context context
The context of a co-metrics request, indicating what parameters were used in the simulation that prod...
Definition CoMetrics.cs:13
The common components of the context returned from any metrics request, indicating what parameters we...
Definition Context.cs:10
DateTime? reporting_period_begin
The reporting period starting DateTime (if it was set), which restricts results to only include losse...
Definition Context.cs:37
DateTime? reporting_period_end
The reporting period ending DateTime (if it was set), which restricts results to only include losses ...
Definition Context.cs:42
Optional parameters which can be specified for exceedance probability requests.
The structure returned when requesting Exceedance Probability for a view.
Context context
The context of a tail metrics request, indicating what parameters were used in the simulation that pr...
Optional parameters which can be specified for all metrics requests.
A reporting period which dictates optional begin and end dates to constrain what event losses are inc...
DateTime? end
(Optional) The exclusive end date of the reporting period. If specified, event losses occurring on or...
DateTime? begin
(Optional) The inclusive start date of the reporting period. If specified, event losses occurring bef...
Optional parameters which can be specified for all simulation result requests. Includes a variety of ...
ReportingPeriod reporting_period
A reporting period which dictates optional begin and end dates to constrain what event losses are inc...
The structure returned when requesting Tail Metrics for a view.
Context context
The context of a tail metrics request, indicating what parameters were used in the simulation that pr...
The structure returned when requesting Window Metrics for a view, containing the core window distribu...
Context context
The context of a window metrics request, indicating what parameters were used in the simulation that ...
Determines the behaviour of the API when automatically retrying a request whose result is not yet rea...
A probability range used to dictate the set of ordered trial losses in a loss distribution that shoul...
static ProbabilityWindow All
Returns a window representing the full probability range [0, 1], such that all trial losses will be i...
T Posted
The posted resource, ready to be referenced.
Represents the Analysis of a Layer.