2using System.Diagnostics;
 
   17using Microsoft.VisualStudio.TestTools.UnitTesting;
 
   22using TestCategory = 
NUnit.Framework.CategoryAttribute;
 
   32        private const string TestCategory = 
"REST Methods";
 
   40                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
   43            Assert.IsNotNull(
options.features, 
"Options response was missing the features list.");
 
 
   51                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
   54                "Expected Optimization to be supported for integration tests.");
 
 
   65                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
 
   97        #region Type Resolution Tests 
  166        #endregion Type Resolution Tests 
  168        #region Test Helper Methods 
  174                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  187        #endregion Test Helper Methods 
  191        #region Type Resolution Tests 
  242        #endregion Type Resolution Tests 
  244        #region Test Helper Methods 
  250                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  263        #endregion Test Helper Methods 
  267        #region Type Resolution Tests 
  294        #endregion Type Resolution Tests 
  296        #region Test Helper Methods 
  302                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  316        #endregion Test Helper Methods 
  324        #region GetResourceList 
  341                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  345            Debug.WriteLine(
"Layers List contains this many items: " + result.items.Count());
 
 
  347        #endregion Basic Tests 
  351        #region Involving Inheritance 
  381        #endregion Involving Inheritance 
  386        #region Involving Generics 
  433        #endregion Involving Generics 
  435        #region Test Helper Methods 
  437        private static void PostAggXLandCatXLLayers(
out string aggId, 
out string catId)
 
  444        private static void PostAggXLandCatXLLayerViews(
out string aggId, 
out string catId)
 
  461                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  476            Debug.WriteLine(
$"Layer List contains this many items: " +
 
  477                $"{count1} (method 1)   {count2} (method 2)");
 
  479                "using equivalent method signatures.");
 
  482                typeof(
T).NiceTypeName() + 
"s to be returned. Got null instead.");
 
  485                typeof(
T).NiceTypeName() + 
"(s) posted not retrieved using compile-time types.");
 
  489                "(s) posted included using compile-time types that were explicitly meant to be ignored.");
 
  493                typeof(
T).NiceTypeName() + 
"(s) to be returned. Got null instead.");
 
  496                typeof(
T).NiceTypeName() + 
"(s) posted not retrieved using run-time types.");
 
  500                "(s) posted included using compile-time types that were explicitly meant to be ignored.");
 
  504        #endregion Test Helper Methods 
  505        #endregion GetResourceList 
  507        #region SearchResourceList 
  514                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  521                $"meta_data[key1]=\"val5\" AND meta_data[theGuid]=\"{myGuid}\"",
 
  528                posted.meta_data.Select(
kvp => 
$"{kvp.Key}: {kvp.Value.ToString()}"));
 
  533                $"posted.meta_data: {postedText}{Environment.NewLine}" +
 
  534                $"resultPortfolio.meta_data: {resultPortfolioText}");
 
 
  536        #endregion SearchResourceList 
  538        #region Batch Get Items By Id 
  543                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  550            Assert.AreEqual(2, result.meta.total_count, 
"Expected exactly two results.");
 
  551            Assert.AreEqual(1, result.items.Count(
ls => 
ls.id == 
ls1.id), 
"A loss set was not found.");
 
  552            Assert.AreEqual(1, result.items.Count(
ls => 
ls.id == 
ls2.id), 
"A loss set was not found.");
 
  556            Assert.AreEqual(2, 
result2.meta.total_count, 
"Expected exactly two results.");
 
  562            Assert.AreEqual(2, result.meta.total_count, 
"Expected exactly two results.");
 
  563            Assert.AreEqual(1, result.items.Count(
ls => 
ls.id == 
ls1.id), 
"A loss set was not found.");
 
  564            Assert.AreEqual(1, result.items.Count(
ls => 
ls.id == 
ls2.id), 
"A loss set was not found.");
 
  568            Assert.AreEqual(2, result.meta.total_count, 
"Expected exactly two results.");
 
  569            Assert.AreEqual(1, result.items.Count(
ls => 
ls.id == 
ls1.id), 
"A loss set was not found.");
 
  570            Assert.AreEqual(1, result.items.Count(
ls => 
ls.id == 
ls2.id), 
"A loss set was not found.");
 
 
  572        #endregion Batch Get Items By Id 
  581                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  601                            "Data from GET did not match data from stream.");
 
 
  609                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  620                copy.description = 
"Copy Of " + 
posted.description;
 
  622                copy.data_file = 
null;
 
  633                            "Data from copy did not match original data.");
 
 
  635        #endregion Get Stream 
  643                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  645            for (
int i = 1; 
i < 10000000; 
i = 
i * 7 - 1)
 
  648                Debug.WriteLine(
"Requesting metrics for return period " + 
i +
 
  649                    " (probability " + 
prob + 
")");
 
  653                    "The return period did not survive a round trip conversion to probability.");
 
 
  663                Assert.Inconclusive(
"RUN_OFFLINE = true");
 
  667                Debug.WriteLine(
$"Requesting metrics for threshold {threshold}");
 
  671                    "The threshold did not survive a round trip conversion to probability.");
 
 
 
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.
 
IInjectableResource< YELTLossSet > LossSet_YELTLossSet
 
IInjectableResource< ILayerView< AggXL > > LayerView_AggXL
 
IInjectableResource< StaticSimulation > Simulation_StaticSimulation
 
IInjectableResource< AggXL > Layer_AggXL
 
IInjectableResource< AnalysisProfile > AnalysisProfile
An analysis profile with one of each possible type of filter.
 
IInjectableResource< StaticPortfolio > Portfolio
 
IInjectableResource< CatXL > Layer_CatXL
 
IInjectableResource< YLTLossSet > LossSet_YLTLossSet
 
IInjectableResource< ILayerView< CatXL > > LayerView_CatXL
 
IInjectableResource< EventCatalog > EventCatalog
 
void Test_API_GetResourceList_GenericType_Interface()
Test an interface where the collection is first implemented in a generic type.
 
void Test_API_GET_NoParams_Basic()
Test the simplest use of GET using a non-derived, instantiable resource type.
 
void Test_API_PUT_SpecifiedType_AbstractBase()
Test PUT using a derived resource type, deserializing to an abstract base identifier.
 
void Test_API_GetResourceList_CollectionNameOverride()
Test GetResourceList using a manually specified collection name and base type.
 
void Test_API_GetResourceList_NoParams_Basic()
Test the simplest use of GetResourceList using a non-derived, instantiable resource type.
 
void Test_API_GET_Interface()
Test GET using a generic interface type, deserializing to a generic interface identifier with a speci...
 
void Test_API_PUT_NoParams_Basic()
Test the simplest use of PUT using a simple instantiable resource type.
 
void Test_API_GetResourceList_GenericType_GenericInterface()
Test a generic interface with a covariant generic parameter.
 
void Test_API_POST_GenericType_Interface()
Test POST using a generic resource type, deserializing to an interface identifier.
 
void Test_API_GetStream_Matches_Get()
Test use of GetStream - write to string stream, and assert it matches the results of a normal GET.
 
void Test_API_POST_SpecifiedType_AbstractBase()
Test POST using a derived resource type, deserializing to an abstract base identifier.
 
void Test_API_GetResourceList_SpecifiedType_Derived()
Can we retrieve the list for a derived instantiable type, and get back only results of that type?
 
void Test_API_OPTIONS_Optimization_Supported()
Test the OPTIONS method.
 
void Test_API_OPTIONS()
Test the OPTIONS method.
 
void Test_API_POST_GenericType_GenericInterface()
Test POST using a generic resource type, deserializing to a generic interface identifier with an inte...
 
void Test_API_GET_GenericType_GenericInterface()
Test GET using a generic resource type, deserializing to a generic interface identifier with an inter...
 
void Test_API_GET_SpecifiedType_Interface()
Test GET using a derived resource type, deserializing to an interface identifier.
 
void Test_API_GET_Exceedance_Probability_Thresholds()
Should be able to support a variety of thresholds without loss of precision.
 
void Test_API_POST_NoParams_Basic()
Test the simplest use of POST using a non-derived, instantiable resource type.
 
void Test_API_GetStream_ToLargeFileUpload()
Test ability to stream data from one resource to a new one being posted.
 
void Test_API_GetResourceList_SpecifiedType_UninstantiableInterface()
Can we retrieve the list for a non-instantiable resource type interface, and get back results that im...
 
void Test_API_GetResourceList_GenericType_GenericInterface_TypeSpecified()
Test a generic interface with an instantiable resource type parameter specified.
 
void Test_API_GET_GenericType_Interface()
Test GET using a generic resource type, deserializing to an interface identifier.
 
void Test_API_PUT_SpecifiedType_Interface()
Test PUT using a derived resource type, deserializing to an interface identifier.
 
void Test_API_GET_GenericType_GenericInterface_SpecifiedType()
Test GET using a generic resource type, deserializing to a generic interface identifier with a specif...
 
void Test_API_POST_GenericType_GenericInterface_SpecifiedType()
Test POST using a generic resource type, deserializing to a generic interface identifier with a speci...
 
void Test_API_GET_SpecifiedType_AbstractBase()
Test GET using a derived resource type, deserializing to an abstract base identifier.
 
void Test_API_GetResourceList_SpecifiedType_UninstantiableAbstractBase()
Can we retrieve the list for a non-instantiable abstract base type, and get back results that derive ...
 
void Test_API_GET_GenericInterface()
Test GET using a generic interface type, deserializing to a generic interface identifier with a speci...
 
void Test_API_GET_ResolveReferences()
Test the GET method with an HTTP header parameter that expands references.
 
void Test_API_POST_SpecifiedType_Interface()
Test POST using a derived resource type, deserializing to an interface identifier.
 
void Test_API_SearchResourceList()
Set some meta_data, POST it, invoke API.SearchResourceList<T> with a matching query and verify that t...
 
void Test_API_GET_Metrics_Probabilities()
Should be able to support every return period between 0 and 10 million without loss of precision on t...
 
void Test_API_GET_WithoutInstance()
Test the API.GET static method.
 
void Test_API_BatchListItems()
 
void Test_API_GetResourceList_GenericType_GenericType_CovariantlyInvalid()
Test a generic class with an interface type parameter specified.
 
void Test_API_GetResourceList_GenericType_GenericType_TypeSpecified()
Test a generic class with an instantiable resource type parameter specified.
 
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 ReferencesResolved(object obj)
 
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 custom exception class that includes the RestSharp.IRestResponse that generated the exception,...
 
Used to deserialize server OPTIONS response.
 
Describes a collection of resources which can be listed.
 
Dictionary< string, object > meta_data
Any user-defined metadata for this layer.
 
Parameters that can be added to your REST requests to access additional API features.
 
static RequestParameters Ids(IEnumerable< string > ids)
Can be added to your collection GET requests to return only the set of resources whose id matches one...
 
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 OptionsResponse Options(IEnumerable< Parameter > requestParameters=null, int? timeout=null)
Perform an OPTIONS request on the API, which returns a list of features supported for the current aut...
 
static readonly ResourceCollection< LossSet > LossSets
The collection of LossSets on the server.
 
static ICollectionResponse< IAPIResource > GetResourceList(Type resourceType, IEnumerable< Parameter > requestParameters=null, string collectionNameOverride=null, int? timeout=null)
Get a collection of resources from the server.
 
static ICollectionResponse< IAPIResource > SearchResourceList(Type resourceType, string searchTerms, IEnumerable< Parameter > requestParameters=null, string collectionNameOverride=null, int? timeout=null, SearchType searchType=SearchType.Basic)
Get a collection of resources from the server that match the specified search criteria.
 
static IAPIResource Get(Type resourceType, string id, IEnumerable< Parameter > requestParameters=null, int? timeout=null)
Get the selected resource by ID. The appropriate collection is automatically determined by the suppli...
 
SearchType
The search type determines the interpretation of the query string.
 
static ICollectionResponse< IAPIResource > BatchGet(Type resourceType, IEnumerable< string > ids, IEnumerable< Parameter > requestParameters=null, string collectionNameOverride=null, int? timeout=null)
Get a collection of resources from the server that match the set of resource ids specified.
 
A configuration of resources used to simulate a layer or portfolio.
 
Base class for all LossSet sub-types. A LossSet is a resource that generates sample (trial) losses wh...
 
Optional parameters which can be specified for exceedance probability requests.
 
static new ExceedanceProbabilityOptions Default
The default exceedance probability request options used when none are specified.
 
double threshold
The threshold parameter.
 
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.
 
static new MetricsOptions Default
The default metrics request options used when none are specified.
 
double probability
The probability determining where the tail distribution begins. Note that this is equal to the Window...
 
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...
 
Representation of a portfolio.
 
Helper class which makes it easier to build a set of request parameters.
 
Representation of a portfolio.
 
A pre-simulated representation of a Simulation (SimGrid).
 
IReference< T > AsReference
A reference to the posted resource.
 
T Unposted
The unPOSTed resource definition.
 
T Posted
The posted resource, ready to be referenced.
 
Interface for Base class used by all resources.
 
Represents the Analysis of a Layer.
 
string ref_id
The id of the object being referred to.