2using System.Collections.Generic;
 
    4using System.Linq.Expressions;
 
    6using System.Reflection;
 
   24using Microsoft.VisualStudio.TestTools.UnitTesting;
 
   30using TestCategory = 
NUnit.Framework.CategoryAttribute;
 
   35    #region Base LayerView Class Tests 
   40        private const string TypeName = 
"LayerView";
 
   52                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
 
   65                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
   73            badCatalog.description = 
"A Different Event Catalog";
 
   91                .Change(
a => 
a.yelt_loss_set_simulation_filtering, 
true)
 
   98            double el = 
catXl.tail_metrics_blocking(1,
 
  100            Assert.AreNotEqual(
el, 0, 
"Expected not zero EL.");
 
  109                .Change(
a => 
a.round_sequences, 
true)
 
  116            double el = 
catXl.tail_metrics_blocking(1,
 
  118            Assert.AreNotEqual(
el, 0, 
"Expected not zero EL.");
 
 
  122    #endregion Base LayerView Class Tests 
  124    #region Instantiable LayerView Types Tests 
  129        #region Set Up and Configuration 
  131        private const string TypeName = 
"LayerView<AggXL>";
 
  137            l => 
l.aggregate_limit;
 
  139        #endregion Set Up and Configuration 
 
  145        #region Set Up and Configuration 
  147        private const string TypeName = 
"LayerView<CatXL>";
 
  155        #endregion Set Up and Configuration 
 
  161        #region Set Up and Configuration 
  163        private const string TypeName = 
"LayerView<Generic>";
 
  169            l => 
l.aggregate_limit;
 
  171        #endregion Set Up and Configuration 
 
  177        #region Set Up and Configuration 
  179        private const string TypeName = 
"LayerView<QuotaShare>";
 
  187        #endregion Set Up and Configuration 
 
  193        #region Set Up and Configuration 
  195        private const string TypeName = 
"LayerView<AggregateQuotaShare>";
 
  201            l => 
l.aggregate_limit;
 
  203        #endregion Set Up and Configuration 
 
  209        #region Set Up and Configuration 
  211        private const string TypeName = 
"LayerView<SurplusShare>";
 
  217            l => 
l.retained_line;
 
  219        #endregion Set Up and Configuration 
 
  225        #region Set Up and Configuration 
  227        private const string TypeName = 
"LayerView<IndustryLossWarranty>";
 
  235        #endregion Set Up and Configuration 
 
  241        #region Set Up and Configuration 
  243        private const string TypeName = 
"LayerView<Nested>";
 
  248        #endregion Set Up and Configuration 
  250        #region Overidden Tests 
  292        #endregion Overidden Tests 
  294        #region Additional LayerView Nested Layer Type Tests 
  299            Test_LayerView_Nested_POST_EverySinkAndSourceType(
false);
 
 
  305            Test_LayerView_Nested_POST_EverySinkAndSourceType(
true);
 
 
  309        private void Test_LayerView_Nested_POST_EverySinkAndSourceType(
bool useInlinedObjects)
 
  318                    Console.WriteLine(
"Skipping sink layer reference test of un-saveable layer type " +
 
  319                        sinkLayer.UnderlyingType.NiceTypeName());
 
  326                current.description = 
"Sink";
 
  345                .ValidSinkLayerTypesTestList.Select(layer => 
Samples.GetInjectableLayerView(layer)))
 
 
  362                    layer.AsReference), 
false);
 
  365                    layer.AsInlinedReference), 
false);
 
  368                    Samples.GetInjectableLayerView(layer).AsReference), 
false);
 
 
  394                    Samples.GetInjectableNestedLayer(Samples.Layer_AggXL,
 
  395                        new List<IInjectableResource<ILayer>> { Samples.Layer_CatXL }, 
true)
 
 
  405            layerNetAggDefinition.loss_sets =
 
  413            POST_ThenDoAction(
Samples.GetInjectableLayerView(
nested).Unposted,
 
 
  424                description = 
"Nested layer with mixed reference types",
 
  425                sink = Samples.Layer_CatXL.Unposted.ToReference(),
 
  426                sources = new Nested.Sources(
 
  427                    Samples.Layer_AggXL.Posted.ToReference(),
 
  428                    Samples.Layer_Generic.Unposted.ToReference(),
 
  429                    Samples.LayerView_Nested.Posted.ToReference())
 
 
  445        #endregion Additional LayerView Nested Layer Type Tests 
 
  451        #region Set Up and Configuration 
  453        private const string TypeName = 
"LayerView<ValueAllocator>";
 
  458        #endregion Set Up and Configuration 
  460        #region Overidden Tests 
  470                    new QuotaShare { event_limit = new MonetaryUnit(1, 
"CAD") }.ToReference())
 
 
  498        #endregion Overidden Tests 
  500        #region Additional LayerView ValueAllocator Layer Type Tests 
  530                    Samples.GetInjectableLayerView(layer).AsReference;
 
 
  550        #endregion Additional LayerView ValueAllocator Layer Type Tests 
 
  556        #region Set Up and Configuration 
  558        private const string TypeName = 
"LayerView<BackAllocatedLayer>";
 
  563        #endregion Set Up and Configuration 
  565        #region Overidden Tests 
  577                    event_limit = new MonetaryUnit(1, 
"CAD"),
 
  578                    loss_sets = new List<IReference<LossSet>> { Samples.LossSet_ELTLossSet.AsReference }
 
 
  610        #endregion Overidden Tests 
  612        #region Additional LayerView BackAllocatedLayer Layer Type Tests 
  629                    Console.WriteLine(
$"Skipping tests for type {layer.UnderlyingType} until ARE-7212");
 
  648                    Samples.GetInjectableLayerView(layer).AsReference;
 
 
  667        [
Obsolete(
"This tests a now obsolete class (NestedLayerLossSet) for backwards compatibility purposes.")]
 
  677                sink = sink.ToReference(),
 
 
  692                sink = sink.ToReference(),
 
 
  697        #endregion Additional LayerView BackAllocatedLayer Layer Type Tests 
 
  703        #region Set Up and Configuration 
  705        private const string TypeName = 
"LayerView<Filter>";
 
  710        #endregion Set Up and Configuration 
  712        #region Additional LayerView Filter Layer Type Tests 
  732                    unfiltered.invert = 
true;
 
  749                        "that reduces losses but not to 0.");
 
  756                        "The filtered EL (" + 
filtered_el + 
") is exactly half of the " +
 
  757                        "original unfiltered EL (" + 
original_el + 
"). This makes it " +
 
  758                        "impossible to assert that the inverted filter is working " +
 
  759                        "correctly. Please revise the test data or filter used to ensure " +
 
  760                        "it doesn't match exactly half of the total losses.");
 
  764                        "the inverted filter returned the same EL as the original filter. " +
 
  765                        "This indicates that the 'invert' property is not working.");
 
  769                        "Expected filtered ELs to add up to the unfiltered EL.");
 
  775                        Console.WriteLine(
"\n\nAn error occurred. Dumping detailed logs.");
 
  781                        Console.WriteLine(
"\n\nFilter LayerView Definition:\n" +
 
  783                        Console.WriteLine(
"\nEmpty Filter Full Definition:\n" +
 
  785                        Console.WriteLine(
"\nInverted Filter Full Definition:\n" +
 
  789                        Console.WriteLine(
"\n\nFilter Definition:\n" +
 
  791                        Console.WriteLine(
"\nFull Loss Set Data:\n" +
 
  793                        Console.WriteLine(
"\n\nAnalysis Profile Definition:\n" +
 
  796                        Console.WriteLine(
"\nFull Catalog Data:\n" +
 
  797                            filteredLayerView.analysis_profile.GetValue().event_catalogs.First().GetValue().data.Get());
 
  801                        Console.WriteLine(
"\nAnother error occurred while dumping detailed logs.");
 
  804                    Console.WriteLine(
"\nRe-throwing original error.");
 
 
  810        #endregion Additional LayerView Filter Layer Type Tests 
 
  817        #region Set Up and Configuration 
  819        private const string TypeName = 
"LayerView<FixedRateCurrencyConverter>";
 
  825            TargetCurrencyProperty => 
l => 
l.out_currency;
 
  827        #endregion Set Up and Configuration 
  834                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  840            Console.WriteLine(
$"Original mean is: {original_mean} {original_metrics.context.currency}");
 
  844            string out_currency = 
"ZZZ";
 
  846            Console.WriteLine(
$"Rate is: {rate} {out_currency} to 1 {in_currency}");
 
  851                sink = new FixedRateCurrencyConverter
 
  853                    in_currency = in_currency,
 
  854                    out_currency = out_currency,
 
 
 
  876        #region Set Up and Configuration 
  878        private const string TypeName = 
"LayerView<LossRank>";
 
  883        #endregion Set Up and Configuration 
 
  889        #region Set Up and Configuration 
  891        private const string TypeName = 
"LayerView<NoClaimsBonus>";
 
  897            l => 
l.payout_amount;
 
  899        #endregion Set Up and Configuration 
  901        #region Overidden Tests 
  903        [
TestMethod, TestCategory(TypeName), 
Obsolete(
"Tests the legacy back_allocations endpoint")]
 
  906            Skip.
Indefinitely(
"ARE-4335 - Back Allocation of NoClaimsBonus with ELT Loss Set Results in Error");
 
  908            base.Test_IAPIResourceView_GET_BackAllocations_Self();
 
 
  911        #endregion Overidden Tests 
 
  917        #region Set Up and Configuration 
  919        private const string TypeName = 
"LayerView<DelayedPayment>";
 
  924        #endregion Set Up and Configuration 
 
  930        #region Set Up and Configuration 
  932        private const string TypeName = 
"LayerView<FixedDatePayment>";
 
  937        #endregion Set Up and Configuration 
 
  940    #endregion Instantiable LayerView Types Tests 
  942    #region Abstract Base LayerView Tests 
  948        #region Set Up and Configuration 
  950        private const string TypeName = 
"LayerView";
 
  952        #endregion Set Up and Configuration 
  978            if (TargetCurrencyProperty == 
null)
 
  980                AssertTargetCurrencyMatchesAnalysisProfile();
 
  988                .Where(
pi => 
pi.PropertyType == 
typeof(
string)).ToArray();
 
  992            allUSD.target_currency = 
null;
 
 1002                Assert.AreEqual(
"USD", 
postResult.target_currency, 
"Expected a target currency of USD");
 
 1009                    modified.layer = modified.
layer.ShallowCopy();
 
 1010                    modified.target_currency = 
null;
 
 1023                                property.Name + 
" currency to have no impact on the target currency.");
 
 1026                            "The TargetCurrencyDefault attribute failed to predict the correct currency");
 
 
 1033        private void AssertTargetCurrencyMatchesAnalysisProfile()
 
 1036                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
 1039                TestResource.analysis_profile).exchange_rate_profile).exchange_rate_table).base_currency;
 
 1053                    .Post().ToReference())
 
 1075                    surplusShare.number_of_lines = 0;
 
 1077                    layer.participation = 0.0;
 
 1083            double threshold = 1.0;
 
 1089                    () => 
_ = 
view.exceedance_probability_blocking(threshold, 
options, SimulationPolling),
 
 1093                Test_IAPIResourceView_GET_ExceedanceProbability_Succeeds(threshold, 
options);
 
 
 1096        [
TestMethod, TestCategory(TypeName), 
Obsolete(
"Tests the legacy back_allocations endpoint")]
 
 1101                Skip.
Indefinitely(
"ARE-7212: BackAllocating Payment Patterns cause Internal Server Errors");
 
 1103                    view => 
view.back_allocations_blocking(
view.id, SimulationPolling),
 
 1107                base.Test_IAPIResourceView_GET_BackAllocations_Self();
 
 
 1110        [
TestMethod, TestCategory(TypeName), 
Obsolete(
"Tests the legacy back_allocations endpoint")]
 
 1114                Skip.
Indefinitely(
"ARE-7212: BackAllocating Payment Patterns cause Internal Server Errors");
 
 1115            base.Test_IAPIResourceView_GET_BackAllocations_SourceID_Invalid();
 
 
 
 1119    #endregion Abstract Base LayerView Tests 
 
 
Tests for a collection (or base resource type) which do not require an instance of that resource to b...
 
A class containing a resource that can be Posted with dependencies.
 
Exposes the various sample CSV files as strings.
 
static string Exchange_Rate_Table
 
Exposes sample resource objects, with built-in methods for injecting dependencies.
 
IInjectableResource< ILayerView< FixedDatePayment > > LayerView_FixedDatePayment
 
static readonly PollingOptions DataPollingOptions
Polling options to use when uploading a data file.
 
List< IInjectableResource< ILayerView > > AllLayerViewTypesTestList
A list of one of each type of layer.
 
IInjectableResource< YELTLossSet > LossSet_YELTLossSet
 
IInjectableResource< Nested > Layer_Nested
A simple nested layer retaining a CatXL source's losses to an AggXL sink.
 
IInjectableResource< ILayerView< DelayedPayment > > LayerView_DelayedPayment
 
IInjectableResource< ILayerView< Generic > > LayerView_Generic
 
IInjectableResource< ILayerView< AggXL > > LayerView_AggXL
 
IInjectableResource< ILayerView< BackAllocatedLayer > > LayerView_BackAllocatedLayer
 
IInjectableResource< AggXL > Layer_AggXL
 
IInjectableResource< ILayerView< Nested > > LayerView_Nested
 
IInjectableResource< ILayerView< QuotaShare > > LayerView_QuotaShare
 
IInjectableResource< ILayerView< FixedRateCurrencyConverter > > LayerView_FixedRateCurrencyConverter
 
List< IInjectableResource< ILayer > > AllSaveableLayerTypesTestList
A list of one of each type of layer that can be POSTed. Layer types that cannot be posted on their ow...
 
IInjectableResource< ExchangeRateProfile > ExchangeRateProfile
 
IInjectableResource< ILayerView< NoClaimsBonus > > LayerView_NoClaimsBonus
 
IInjectableResource< AnalysisProfile > AnalysisProfile
An analysis profile with one of each possible type of filter.
 
IInjectableResource< BackAllocatedLayer > Layer_BackAllocatedLayer
 
IInjectableResource< NestedLayerLossSet > LossSet_NestedLayerLossSet
A simple NestedLayerLossSet retaining a CatXL layer's losses.
 
IInjectableResource< ILayerView< Filter > > LayerView_Filter
 
IInjectableResource< ILayerView< LossRank > > LayerView_LossRank
 
IInjectableResource< ExchangeRateTable > ExchangeRateTable
 
IInjectableResource< ILayerView< SurplusShare > > LayerView_SurplusShare
 
IInjectableResource< ValueAllocator > Layer_ValueAllocator
 
IInjectableResource< CatXL > Layer_CatXL
 
List< IInjectableResource< LossSet > > AllLossSetTypesTestList
One sample of each loss set type, all with the loss_type set to LossType.LossGross to maximize potent...
 
List< IInjectableResource< ILayer > > AllLayerTypesTestList
A list of one of each type of layer.
 
IInjectableResource< Nested > GetInjectableNestedLayer(IInjectableResource< ILayerSource > sink, IEnumerable< IInjectableResource< ILayerSource > > sources, bool inline=false)
Factory for producing injectable NestedLayers using a POSTable injectable Layer for use in testing.
 
IInjectableResource< ILayerView< IndustryLossWarranty > > LayerView_IndustryLossWarranty
 
IInjectableResource< ILayerView< CatXL > > LayerView_CatXL
 
IInjectableResource< AnalysisProfile > AnalysisProfile_OneFilter
An analysis profile containing only an AnyFilter.
 
IInjectableResource< AnyFilter > LossFilter_AnyFilter
 
IInjectableResource< ILayerView< AggregateQuotaShare > > LayerView_AggregateQuotaShare
 
IInjectableResource< QuotaShare > Layer_QuotaShare
 
IInjectableResource< ILayerView< ValueAllocator > > LayerView_ValueAllocator
 
IInjectableResource< EventCatalog > EventCatalog
 
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...
 
override IInjectableResource< ILayerView< AggXL > > TestInjectableResource
 
override Expression< Func< AggXL, object > > TargetCurrencyProperty
 
override Expression< Func< AggregateQuotaShare, object > > TargetCurrencyProperty
 
override IInjectableResource< ILayerView< AggregateQuotaShare > > TestInjectableResource
 
void Test_LayerView_BackAllocatedLayer_POST_ARE_6439()
 
void Test_LayerView_BackAllocatedLayer_POST_EveryReferenceType()
Test what happens when a LayerView's BackAllocatedLayer layer definition has its sink property set to...
 
override void Test_LayerView_POST_TargetCurrencyDefault()
Check that the target currency is determined by the expected property for each layer type.
 
void Test_LayerView_BackAllocatedLayer_POST_MismatchedLayerViewAnalysisProfiles()
Test what happens when a LayerView's BackAllocatedLayer layer definition references another LayerView...
 
void Test_LayerView_BackAllocatedLayer_POST_ARE_6437()
 
override void Test_Resource_PUT_BadlyFormed()
Bug ARE-6381: The server returns the wrong status on PUT when the id is malformed.
 
override IResourceCollection< ILayerView > collection_source
 
void Test_LayerView_LossSet_EventCatalog_Mismatch()
The API should forbid posting a layer_view containing a loss set whose event catalog doesn't match th...
 
override bool PUT_Allowed
 
void Test_LayerView_GET_SequencesRounding()
 
void Test_LayerView_GET_YeltLossSetFiltering()
 
override Expression< Func< CatXL, object > > TargetCurrencyProperty
 
override IInjectableResource< ILayerView< CatXL > > TestInjectableResource
 
void Test_LayerView_Filter_Metrics_Decrease()
 
void Test_LayerView_FixedRateCurrencyConverter_Results()
Demonstrate that the fixed rate is used for conversion.
 
override IInjectableResource< ILayerView< Generic > > TestInjectableResource
 
override Expression< Func< Generic, object > > TargetCurrencyProperty
 
override Expression< Func< IndustryLossWarranty, object > > TargetCurrencyProperty
 
override IInjectableResource< ILayerView< IndustryLossWarranty > > TestInjectableResource
 
override IInjectableResource< ILayerView< Nested > > TestInjectableResource
 
void Test_LayerView_Nested_POST_Sink_InlinedNested()
 
void Test_LayerView_Nested_POST_Mixed_SourceAndSink_MixedReferenceTypes()
 
void Test_LayerView_Nested_POST_EverySinkAndSourceType_Referenced()
 
void Test_LayerView_Nested_POST_MismatchedLayerViewAnalysisProfiles()
 
void Test_LayerView_Nested_POST_EverySinkAndSourceType_LayerViewReferences()
 
override void Test_LayerView_POST_TargetCurrencyDefault()
Check that the target currency is determined by the expected property for each layer type.
 
void Test_LayerView_Nested_POST_Sink_InvalidType()
 
void Test_LayerView_Nested_POST_Mixed_SourceAndSink_MixedLossSetTypes()
 
void Test_LayerView_Nested_POST_Source_InlinedNested()
 
void Test_LayerView_Nested_POST_EverySinkAndSourceType_Inlined()
 
override void Test_IAPIResourceView_GET_BackAllocations_Self()
 
override IInjectableResource< ILayerView< QuotaShare > > TestInjectableResource
 
override Expression< Func< QuotaShare, object > > TargetCurrencyProperty
 
override IInjectableResource< ILayerView< SurplusShare > > TestInjectableResource
 
override Expression< Func< SurplusShare, object > > TargetCurrencyProperty
 
void Test_LayerView_ValueAllocator_POST_EveryReferenceType()
Test what happens when a LayerView's ValueAllocator layer definition has source, target,...
 
override void Test_LayerView_POST_TargetCurrencyDefault()
Check that the target currency is determined by the expected property for each layer type.
 
void Test_LayerView_ValueAllocator_POST_MismatchedLayerViewAnalysisProfiles()
Test what happens when a LayerView's ValueAllocator layer definition references another LayerView wit...
 
override void Test_IAPIResourceView_GET_BackAllocations_Self()
 
virtual void Test_LayerView_POST_Layer_MixedLossSetTypes()
 
virtual void Test_LayerView_GET_ExceedanceProbability_Filter_ZeroParticipation()
 
override void Test_IAPIResourceView_GET_BackAllocations_SourceID_Invalid()
 
virtual void Test_LayerView_POST_TargetCurrencyDefault()
Check that the target currency is determined by the expected property for each layer type.
 
static HashSet< Type > UnsupportedBackAllocatedLayerSinkTypes
Types that cannot be the sink of a Back-Allocated layer.
 
static IEnumerable< Type > PaymentPatternTypes
A list of "PaymentPattern" layer types for convenience (because they comes up in a lot of validation ...
 
static IEnumerable< IInjectableResource< ILayer > > ForbiddenSinkLayerTypesTestList
A set of injectable test layers that are not valid to use as a sink.
 
static IEnumerable< IInjectableResource< ILayer > > ValidSinkLayerTypesTestList
A set of injectable test layers that are valid to use as a sink.
 
static bool AlmostEquals(double d1, double d2, double tolerance=DEFAULT_DOUBLE_EQUIVALENCE_TOLERANCE)
Determines if two doubles are equivalent within the specified tolerance.
 
static Action< APIRequestException > ApiExceptionTest(HttpStatusCode expectedStatusCode)
Generate a function that will test a REST request exception in a standard way.
 
static void DoublesAreEqual(double expected, double actual, Func< string > message, double? relative_tolerance=null)
Determines if two doubles are equivalent within the accepted tolerance.
 
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...
 
Generic Unit test implementations that will test REST methods on arbitrary resources.
 
A collection of filthy hacks to populate some fields of APIResources objects of any type.
 
Class used in unit tests to mark tests as skipped by using Assert.Inconclusive() method.
 
static void Indefinitely(string ticket=null)
Skip the specified test.
 
Attribute used to define the default value assigned to the target_currency property by the server whe...
 
static string GetDefaultTargetCurrency(IAPIResource resource)
Determine what the default target currency will be based on the resource type and properties.
 
Describes a collection of resources which can be listed.
 
Parameters that can be added to your REST requests to access additional API features.
 
static RequestParameters ExpandReferences()
Can be added to your GET requests to recursively resolve resource references in the response....
 
API methods / requests made available to the user.
 
static readonly ResourceCollection< ILayerView > LayerViews
The collection of LayerViews on the server.
 
A configuration of resources used to simulate a layer or portfolio.
 
Indicates that while the current APIResource-derived class can be constructed and potentially inlined...
 
Representation of an event catalog. The event catalog may cover multiple region/perils,...
 
Representation of an Aggregate Catastrophe Excess of Loss layer.
 
Acts as a replacement for IAPIResourceView.back_allocations. Computes the proportion of some sink str...
 
Filter is like a layer whose 'terms' are to filter events out of the loss sources....
 
A wrapper for a List<T> of IReference<ILayerSource> references that simplifies the construction and u...
 
Allows one or more source layers or layer_views to be attached as loss sources to some other layer de...
 
Representation of a Quota Share contract.
 
Representation of a Surplus Share contract.
 
Representation of a Nested layer loss set, which represents any loss set whose losses are derived fro...
 
Optional parameters which can be specified for exceedance probability requests.
 
Optional parameters which can be specified for all metrics requests.
 
static new MetricsOptions Default
The default metrics request options used when none are specified.
 
The structure returned when requesting Tail Metrics for a view.
 
Representation of a monetary value with a currency.
 
The loss perspective determines what factors to include when computing a distribution.
 
static readonly Perspective LossGross
Construct a distribution from the structure's gross losses.
 
Represents the Analysis of a Portfolio.
 
Utilities that reflect on a type or property expression.
 
IReference< T > AsReference
A reference to the posted resource.
 
T Unposted
The unPOSTed resource definition.
 
T Posted
The posted resource, ready to be referenced.
 
string target_currency
The default currency results are returned in. If not specified, the server will automatically select ...
 
Describes an APIResource class that adds a "/data" sub-resource, since this functionality is common t...
 
Represents the Analysis of a Layer.
 
ILayer layer
The layer contained in this LayerView.
 
Abstract representation of a layer.
 
Abstract representation of a layer with terms.
 
Abstract representation of a layer with terms.