2using System.Collections.Generic;
16using Microsoft.VisualStudio.TestTools.UnitTesting;
21using TestCategory =
NUnit.Framework.CategoryAttribute;
29 private const string TypeName =
"PortfolioView";
41 Assert.Inconclusive(
"RUN_OFFLINE = true");
64 Assert.Inconclusive(
"RUN_OFFLINE = true");
70 new[] { added.ToReference() },
83 #region Target Currency
88 Assert.Inconclusive(
"RUN_OFFLINE = true");
107 description =
"5 layers"
115 analysis_profile = analysis_profile,
119 pv =>
Assert.AreEqual(
"EUR",
pv.target_currency));
126 Assert.Inconclusive(
"RUN_OFFLINE = true");
133 baseLayer.description =
"Layer 2";
135 baseLayer.description =
"Layer 3";
137 baseLayer.description =
"Layer 4";
139 baseLayer.description =
"Layer 5";
144 #endregion Target Currency
150 #region Set Up and Configuration
151 private const string TypeName =
"PortfolioView";
154 #endregion Set Up and Configuration
185 name =
"All Layer Types",
186 description =
"All Layer Types",
194 #region MixedLossSetTypes
199 Assert.Inconclusive(
"RUN_OFFLINE = true");
203 layerNetAggDefinition.loss_sets =
210 name =
"Profile of Mixed Layer LossSet Types",
211 description =
"Profile of Mixed Layer LossSet Types",
215 layerNetAgg.AsReference
218 POST_ThenDoAction(TestResource.Change(
pv =>
pv.portfolio,
mixedPortfolio.AsReference),
226 Assert.Inconclusive(
"RUN_OFFLINE = true");
233 name =
"Profile of Mixed Layer LossSet Types",
234 description =
"Profile of Mixed Layer LossSet Types",
242 POST_ThenDoAction(TestResource.Change(
pv =>
pv.portfolio,
mixedPortfolio.AsReference),
245 #endregion MixedLossSetTypes
255 Console.WriteLine(
$"Test resource unposted: {TestResource.Serialize()}");
256 Console.WriteLine(
$"Test resource posted: {original.Serialize()}");
261 Assert.AreEqual(
original.ylt_id,
copy.ylt_id,
"Expected the same portfolio_view ylt_id " +
262 "regardless of whether it's created with a portfolio reference or layer_views.");
266 Assert.AreNotEqual(
original.id,
copy.id,
"Bug ARE-6210 changes the id even though the " +
267 "resources are identical. Let us know when this is no longer the case.");
271 .Change(
pv =>
pv.target_currency,
null).Change(
pv =>
pv.ylt_id,
null).Change(
pv =>
pv.id,
null);
274 Assert.AreEqual(
original.ylt_id,
copy.ylt_id,
"Expected the same portfolio_view ylt_id " +
275 "regardless of whether it's created with a portfolio reference or layer_views.");
277 "because all server generated properties were removed for ARE-6210.");
283 Assert.AreEqual(
original.ylt_id,
copy.ylt_id,
"Expected the same portfolio_view ylt_id " +
284 "regardless of whether it's created with a portfolio reference or layer_views.");
285 Assert.AreNotEqual(
original.id,
copy.id,
"The server currently does not return the " +
286 "same id when a portfolio_view is posted from the equivalent set of layer_views. " +
287 "If this changes, great! - we just want to know about it.");
296 #region Set Up and Configuration
297 private const string TypeName =
"PortfolioView";
300 #endregion Set Up and Configuration
333 Assert.Inconclusive(
"RUN_OFFLINE = true");
340 #endregion layer_views
342 #region MixedLossSetTypes
347 Assert.Inconclusive(
"RUN_OFFLINE = true");
352 layerNetAgg.loss_sets =
358 analysis_profile = analysis_profile
363 layerViewNetAgg.AsReference
365 POST_ThenDoAction(TestResource.Change(
pv =>
pv.layer_views,
references),
375 Assert.Inconclusive(
"RUN_OFFLINE = true");
383 description =
"Gross Loss of 1",
387 loss_type = LossType.LossGross
391 qsLayer.description =
"Simple 1 loss layer";
398 description =
"Simple nested layer",
410 new PortfolioView { layer_views = layer_views, analysis_profile = analysis_profile }.Post();
413 #endregion MixedLossSetTypes
417 #region Abstract Base Test Class
421 private const string TypeName =
"PortfolioView";
429 Console.WriteLine(
$"PortfolioView Premium: {portfolioView.premium}");
435 .Select(
l =>
$"- Premium: {l.premium} Share: {l.participation}")));
440 "Expected all constituent layer premiums to have the same currency. Test cannot proceed.");
446 #region BackAllocations
447 [
TestMethod, TestCategory(TypeName),
Obsolete(
"Tests the legacy back_allocations endpoint")]
451 Skip.
Indefinitely(
"ARE-5129: 'Source not found' erroneously raised when back-allocating to self.");
452 base.Test_IAPIResourceView_GET_BackAllocations_Self();
455 [
TestMethod, TestCategory(TypeName),
Obsolete(
"Tests the legacy back_allocations endpoint")]
465 #endregion BackAllocations
467 #region PostMarginalPortfolioView
472 Assert.Inconclusive(
"RUN_OFFLINE = true");
476 .Post().ToReference();
486 [
TestMethod, TestCategory(TypeName), TestCategory(
"Skipped")]
490 "Support Duplicate Layers in Portfolios and LayerViews in PortfolioViews");
506 Assert.Inconclusive(
"RUN_OFFLINE = true");
521 AssertApi.ExceptionThrown(() => TestResource_Existing.PostMarginalPortfolio(),
523 "You must specify either layers to add or layers to remove, or both.",
ex.Message));
529 AssertApi.ExceptionThrown(() => TestResource.PostMarginalPortfolio(),
531 "The referenced base portfolio_view reference has no id.",
ex.Message));
533 #endregion PostMarginalPortfolioView
535 #endregion Abstract Base Test Class
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.
IReference< T > AsReference
A reference to the posted resource.
Exposes sample resource objects, with built-in methods for injecting dependencies.
IInjectableResource< ILayerView< Generic > > LayerView_Generic
IInjectableResource< AggXL > Layer_AggXL
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< AnalysisProfile > AnalysisProfile
An analysis profile with one of each possible type of filter.
IInjectableResource< StaticPortfolio > Portfolio
IInjectableResource< PortfolioView > PortfolioView_WithLayerViews
static string Valid_NonExistant_UUID
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< QuotaShare > Layer_QuotaShare
IInjectableResource< PortfolioView > PortfolioView_WithPortfolio
Contains static helper methods for testing IAPIResourceView instances.
void Test_IAPIResourceView_Action_Succeeds(Action< T > action)
static void Test_IAPIResourceView_Metrics_MixedLossTypes(T posted, Perspective leastGranularPerspective=null)
void VerifyBackAllocationSuccess(BackAllocations result)
static readonly PollingOptions SimulationPolling
Settings used to ensure simulation requests are retried frequently and timeout after a reasonable amo...
void Test_PortfolioView_TargetCurrency_MatchesLayerViews()
void Test_PortfolioView_BothLayerViewsAndPortfolio()
void Test_PortfolioView_POST_Marginal()
Test that the API.PortfolioViewMarginals collection (which behaves unlike any other root endpoint to ...
override IResourceCollection< PortfolioView > collection_source
void Test_PortfolioView_TargetCurrency_MatchesPortfolioLayers()
override void Test_Resource_PUT_BadlyFormed()
Bug ARE-6381: The server returns the wrong status on PUT when the id is malformed.
override bool PUT_Allowed
void Test_PortfolioView_POST_LayerViews_LossGross_NestedLayer()
void Test_PortfolioView_POST_LayerViews_Empty()
void Test_PortfolioView_POST_LayerView_AllLayerTypes()
void Test_PortfolioView_POST_LayerViews_Invalid()
override IInjectableResource< PortfolioView > TestInjectableResource
void Test_PortfolioView_POST_LayerViews_BadlyFormed()
void Test_PortfolioView_POST_LayerViews_Null()
void Test_PortfolioView_POST_LayerViews_MixedLossSetTypes()
void Test_PortfolioView_POST_Portfolio_Null()
void Test_PortfolioView_POST_Portfolio_Reference_AllLayerTypes()
override IInjectableResource< PortfolioView > TestInjectableResource
void Test_PortfolioView_POST_Portfolio_Reference_Layers_MixedLossSetTypes()
void Test_PortfolioView_POST_Portfolio_Reference_EmptyStringId()
void Test_PortfolioView_POST_Portfolio_Reference_NullId()
override void Test_Resource_POST_ExistingId()
Special case for PortfolioView: Can't just re-POST the object returned from the server,...
void Test_PortfolioView_POST_Portfolio_Reference_NonExistantId()
void Test_PortfolioView_POST_Portfolio_Reference_OneLayer_MixedLossSetTypes()
void Test_PortfolioView_POST_Marginal_AddDuplicateLayerView()
void Test_PortfolioView_POST_Marginal_AddLayerView()
void Test_PortfolioView_POST_Marginal_NoId()
void Test_PortfolioView_POST_Marginal_RemoveLayerView()
virtual void Test_PortfolioView_GET_BackAllocations_ToLayer()
override void Test_IAPIResourceView_GET_BackAllocations_Self()
virtual void Test_PortfolioView_Premium()
void Test_PortfolioView_POST_Marginal_NoChange()
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.
Describes a collection of resources which can be listed.
Represents the endpoint on the server for requesting marginal portfolios.
static IReference< PortfolioView > Post(IReference< PortfolioView > basePortfolio, IEnumerable< IReference< ILayerView > > layerViewsToAdd=null, IEnumerable< IReference< ILayerView > > layerViewsToRemove=null, IEnumerable< Parameter > requestParameters=null, int? timeout=null)
Construct a "marginal" PortfolioView by adding and/or removing one or more LayerViews to/from some ba...
API methods / requests made available to the user.
static readonly ResourceCollection< PortfolioView > PortfolioViews
The collection of PortfolioViews on the server.
Describes a distribution that always returns the same value. This distribution can be used as either ...
Representation of an Aggregate Catastrophe Excess of Loss layer.
Representation of a Catastrophe Excess of Loss (CatXL) layer.
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 Parametric loss set.
The structure returned when requesting back-allocated metrics for a view.
Representation of a monetary value with a currency.
Represents the Analysis of a Portfolio.
HashSet< IReference< ILayerView > > layer_views
The LayerViews included in this PortfolioView. Must be supplied when posting a new PortfolioView,...
Representation of a portfolio.
IReference< T > AsReference
A reference to the posted resource.
T Unposted
The unPOSTed resource definition.
T Posted
The posted resource, ready to be referenced.
Represents the Analysis of a Layer.
Abstract representation of a layer with terms.
Abstract representation of a layer with terms.
@ currency
Reinstatement values represent a fixed dollar amount.