C# Client Library
A C# Client Library for the AnalyzeRe REST API
AnalyzeReTesting.Utilities.Reflection Class Reference

Dirty, filthy hacks to populate some fields of APIResources objects of any type More...

Classes

class  RecursionContext
 Used to keep track of the recursive random generation process for objects and their attributes. When an object or its properties are being randomly generated, the recursion context indicates what the parent object (if any) is. When a property to generate has additional nested properties that must also be randomized, the recursion context will point back to the original root object. More...
 
class  TimedRequest
 Small class to track a few properties of a request. More...
 

Public Member Functions

 Reflection (Samples samplesInstance=null)
 
bool AnyAnalysisMatchesCriteria (IAPIAnalysis analysis, Func< IAPIAnalysis, bool > test)
 Recursively determines if the layer, or any inner layers it references match the specified criteria. More...
 
bool AnyLayerMatchesCriteria (ILayerSource rootlayerSource, Func< ILayer, bool > test, bool allocationSourcesOnly=false)
 Recursively determines if the layer, or any inner layers it references match the specified criteria. More...
 
bool AnyLayerSourceMatchesCriteria (ILayerSource rootLayerSource, Func< ILayerSource, bool > test, bool allocationSourcesOnly=false)
 Recursively determines if the layer, or any inner layers it references match the specified criteria. More...
 
bool AnyLossSetMatchesCriteria (LossSet root, Func< LossSet, bool > test)
 Recursively determines if the loss set, or any inner loss sets it references match the specified criteria. More...
 
IReference< IAPIResourceCacheResource (IAPIResource resource)
 Cache some known posted resource so that it can be reused. More...
 
IReference< T > CacheResource< T > (IReference< T > resource)
 Cache some known posted resource reference so that it can be reused. More...
 
object ChangePropertyValueRandomly (IAPIType obj, PropertyInfo prop, int max_attempts=Max_ReRandomize_Attempts, RecursionContext parentRecursionInfo=null)
 Randomly change the specified property to some different value. More...
 
object CreateRandomizedInstance (Type desiredType)
 Generates a new randomized object of the specified type. More...
 
object GenerateAttributeValue (AttributeFilter owner, PropertyInfo prop)
 
string GetRandomCurrency ()
 Random currency must be a 3-character currency. In most cases, it must also be a currency for which we have entries in the FX table, so we pull from a list of currencies in the sample FX table we upload. More...
 
IReference< IAPIResourceGetRandomExistingResource (Type T, RecursionContext currentRecursion)
 Tries to find an existing (POSTed) resource of the specified type without generating a new one. More...
 
IReference< IAPIResourceGetSampleOfType (Type T)
 Get a standard IInjectableResource<T> value matching the given type. More...
 
HashSet< string > GetValidCurrenciesForAnalysisProfile (AnalysisProfile analysis_profile)
 
bool LayerSourceIsValidForAnalysisProfile (ILayerSource to_validate, AnalysisProfile analysis_profile)
 Validate that this ILayerSource is compatible with the current analysis profile, including recursive checks of inner layer and loss set definitions. More...
 
bool LossSetIsValidForAnalysisProfile (LossSet to_validate, AnalysisProfile analysis_profile)
 Validate that this LossSet is compatible with the current analysis profile, including recursive checks of inner layer and loss set definitions. More...
 
string PickBackAllocatedLayerSourceId (IReference< ILayerSource > sinkReference)
 Finds a random source loss set or layer_view id within the specified sinkReference which can be used as a BackAllocatedLayer.source_id. More...
 
Resolve< T > (IReference< T > reference)
 Resolves a reference in a way that benefits from caching, so that the same reference value never has to be retrieved more than once within an integration test run. More...
 
bool ResourceIsValidForAnalysisProfile (IAPIResource to_validate, AnalysisProfile rootAp)
 Validate that the specified resource is compatible with the current analysis profile (e.g. that it doesn't reference any other event catalogs or loss filters). More...
 
TryGenerate< T > (Func< T > generator, Func< T, bool > validation_test, Func< string > get_error, PropertyInfo property, bool exception_on_failure=true)
 Attempt to generate a resource randomly, with some validation to see if the attempt was successful. Throws an exception if it fails. More...
 
void UploadResourceData (IAPIResource_WithDataEndpoint resource)
 If this resource has data endpoints, try uploading some data! More...
 

Static Public Member Functions

static IEnumerable< Type > GetAllInstantiableSubtypes (Type type)
 Creates a list of types that can be derived from a given type. More...
 
static ILayer GetLayerDefinition (ILayerSource layerSource)
 Convert the ILayerSource to a layer instance by extracting the ILayerView.layer property if it is a ILayerView. More...
 
static bool IsProperty< TPropertyOwner > (PropertyInfo property, Expression< Func< TPropertyOwner, object >> propertyExpression)
 Determines whether the object instance that returned the property is of the type TPropertyOwner and the property matches the specified propertyExpression. More...
 
static T LimitAttempts< T > (Func< T > generator, Func< T, bool > validation_test, Func< string > get_error, PropertyInfo property=null, int max_attempts=Max_ReRandomize_Attempts, bool exception_on_failure=true)
 Attempt to generate a resource randomly, with some validation to see if the attempt was successful. Limit the number of attempts, then return null if we continue to fail. More...
 

Properties

AnalysisProfile Target_AnalysisProfile [get, set]
 The default AnalysisProfile to use for various validation assurances. More...
 
bool Validation_Enabled [get, set]
 When true, randomly generated properties will be validated to verify that they can be POSTed successfully. If set to false, properties will be more random, validation will be ignored, and invalid resources may be generated. More...
 

Detailed Description

Dirty, filthy hacks to populate some fields of APIResources objects of any type

Definition at line 34 of file Reflection.cs.

Constructor & Destructor Documentation

AnalyzeReTesting.Utilities.Reflection.Reflection ( Samples  samplesInstance = null)
inline

Definition at line 75 of file Reflection.cs.

Member Function Documentation

bool AnalyzeReTesting.Utilities.Reflection.AnyAnalysisMatchesCriteria ( IAPIAnalysis  analysis,
Func< IAPIAnalysis, bool >  test 
)
inline

Recursively determines if the layer, or any inner layers it references match the specified criteria.

Parameters
analysisThe IAPIAnalysis object to recurse on.
testThe criteria to test against each object encountered.
Returns
True if any of the layer matches the criteria.

Definition at line 2109 of file Reflection.cs.

bool AnalyzeReTesting.Utilities.Reflection.AnyLayerMatchesCriteria ( ILayerSource  rootlayerSource,
Func< ILayer, bool >  test,
bool  allocationSourcesOnly = false 
)

Recursively determines if the layer, or any inner layers it references match the specified criteria.

Parameters
rootlayerSourceThe root layer or layer_view instance which may contain references to other layers.
testThe criteria to test against each layer encountered.
Returns
True if any of the layer matches the criteria.
Parameters
allocationSourcesOnlyIf set to true, only nested properties that qualify as allocation sources will be traversed.
bool AnalyzeReTesting.Utilities.Reflection.AnyLayerSourceMatchesCriteria ( ILayerSource  rootLayerSource,
Func< ILayerSource, bool >  test,
bool  allocationSourcesOnly = false 
)
inline

Recursively determines if the layer, or any inner layers it references match the specified criteria.

Parameters
rootLayerSourceThe root layer or layer_view instance which may contain references to other layers.
testThe criteria to test against each layerSource encountered.
allocationSourcesOnlyIf set to true, only nested properties that qualify as allocation sources will be traversed.
Returns
True if any of the layer matches the criteria.

TODO: The allocationSourcesOnly mechanic is scope creep, but it beats duplicating all the logic herein just to exclude "target" and "group" properties of the ValueAllocator layer. Think of other approaches.

Definition at line 2172 of file Reflection.cs.

bool AnalyzeReTesting.Utilities.Reflection.AnyLossSetMatchesCriteria ( LossSet  root,
Func< LossSet, bool >  test 
)
inline

Recursively determines if the loss set, or any inner loss sets it references match the specified criteria.

Parameters
rootThe root loss set which may contain references to other loss sets.
testThe criteria to test against each loss set encountered.
Returns
True if any of the loss sets matches the criteria.

Definition at line 2220 of file Reflection.cs.

IReference<IAPIResource> AnalyzeReTesting.Utilities.Reflection.CacheResource ( IAPIResource  resource)

Cache some known posted resource so that it can be reused.

Cache some known posted resource reference so that it can be reused.

Type Constraints
T :IAPIResource 
T :CacheResource 
T :resource.GetType() 
T :GetGenericArguments() 
T :resource 
object AnalyzeReTesting.Utilities.Reflection.ChangePropertyValueRandomly ( IAPIType  obj,
PropertyInfo  prop,
int  max_attempts = Max_ReRandomize_Attempts,
RecursionContext  parentRecursionInfo = null 
)
inline

Randomly change the specified property to some different value.

Parameters
objThe object whose property should be changed.
propThe property whose value should be randomly changed.
max_attemptsIf we randomly generate a value for this property which is equivalent to the initial value, or is otherwise invalid, we can attempt to generate a new value. This is the maximum number of times we should attempt to re-generate this property before raising an exception.
parentRecursionInfoThe recursion context (if applicable) indicating the parent object(s) owns the obj instance whose property is being randomized.
Returns
The new property value that has been set to the object (for convenience, so the caller doesn't need to invoke PropertyInfo.GetValue(Object).

Definition at line 1260 of file Reflection.cs.

object AnalyzeReTesting.Utilities.Reflection.CreateRandomizedInstance ( Type  desiredType)

Generates a new randomized object of the specified type.

Parameters
desiredTypeThe type of object to generate.
Returns
A new random object of the desired type.
object AnalyzeReTesting.Utilities.Reflection.GenerateAttributeValue ( AttributeFilter  owner,
PropertyInfo  prop 
)
inline

Definition at line 1617 of file Reflection.cs.

static IEnumerable<Type> AnalyzeReTesting.Utilities.Reflection.GetAllInstantiableSubtypes ( Type  type)
inlinestatic

Creates a list of types that can be derived from a given type.

Parameters
typeThe base type for which to get all instantiable sub-types.
Returns
A list of all instantiable sub-types assignable to the type T.

Definition at line 2085 of file Reflection.cs.

static ILayer AnalyzeReTesting.Utilities.Reflection.GetLayerDefinition ( ILayerSource  layerSource)
static

Convert the ILayerSource to a layer instance by extracting the ILayerView.layer property if it is a ILayerView.

string AnalyzeReTesting.Utilities.Reflection.GetRandomCurrency ( )
inline

Random currency must be a 3-character currency. In most cases, it must also be a currency for which we have entries in the FX table, so we pull from a list of currencies in the sample FX table we upload.

Definition at line 1686 of file Reflection.cs.

IReference<IAPIResource> AnalyzeReTesting.Utilities.Reflection.GetRandomExistingResource ( Type  T,
RecursionContext  currentRecursion 
)
inline

Tries to find an existing (POSTed) resource of the specified type without generating a new one.

Parameters
TThe type of resource to locate.
currentRecursionThe recursion context of the object generation routine that deferred to this helper method.
Returns
A random already posted resource, or null if none were found.

Definition at line 489 of file Reflection.cs.

IReference<IAPIResource> AnalyzeReTesting.Utilities.Reflection.GetSampleOfType ( Type  T)
inline

Get a standard IInjectableResource<T> value matching the given type.

Parameters
TThe type of resource to return a reference to.

Definition at line 571 of file Reflection.cs.

HashSet<string> AnalyzeReTesting.Utilities.Reflection.GetValidCurrenciesForAnalysisProfile ( AnalysisProfile  analysis_profile)
static bool AnalyzeReTesting.Utilities.Reflection.IsProperty< TPropertyOwner > ( PropertyInfo  property,
Expression< Func< TPropertyOwner, object >>  propertyExpression 
)
static

Determines whether the object instance that returned the property is of the type TPropertyOwner and the property matches the specified propertyExpression.

bool AnalyzeReTesting.Utilities.Reflection.LayerSourceIsValidForAnalysisProfile ( ILayerSource  to_validate,
AnalysisProfile  analysis_profile 
)
inline

Validate that this ILayerSource is compatible with the current analysis profile, including recursive checks of inner layer and loss set definitions.

Parameters
to_validateThe ILayerSource to validate.
analysis_profileThe analysis profile to validate against.
Returns
True if the resource is valid.

Definition at line 1889 of file Reflection.cs.

static T AnalyzeReTesting.Utilities.Reflection.LimitAttempts< T > ( Func< T >  generator,
Func< T, bool >  validation_test,
Func< string >  get_error,
PropertyInfo  property = null,
int  max_attempts = Max_ReRandomize_Attempts,
bool  exception_on_failure = true 
)
inlinestatic

Attempt to generate a resource randomly, with some validation to see if the attempt was successful. Limit the number of attempts, then return null if we continue to fail.

Template Parameters
TThe type of object being generated.
Parameters
generatorGenerates an object of type T.
validation_testDetermines if the object is valid.
get_errorReturns an error message if object is invalid.
propertyThe property information for logs and error messages.
max_attemptsThe maximum number of attempts before failing.
exception_on_failureWhether failure sure raise a PropertyGenerationException or simply return default(T)
Returns
The generated object.
Exceptions
PropertyGenerationExceptionGeneration fails and exception_on_failure is set to true.

Definition at line 1763 of file Reflection.cs.

bool AnalyzeReTesting.Utilities.Reflection.LossSetIsValidForAnalysisProfile ( LossSet  to_validate,
AnalysisProfile  analysis_profile 
)
inline

Validate that this LossSet is compatible with the current analysis profile, including recursive checks of inner layer and loss set definitions.

Parameters
to_validateThe LossSet to validate.
analysis_profileThe analysis profile to validate against.
Returns
True if the resource contains no invalid references.

Definition at line 1930 of file Reflection.cs.

string AnalyzeReTesting.Utilities.Reflection.PickBackAllocatedLayerSourceId ( IReference< ILayerSource sinkReference)
inline

Finds a random source loss set or layer_view id within the specified sinkReference which can be used as a BackAllocatedLayer.source_id.

Exceptions
PropertyGenerationExceptionIf no valid source_id can be found within the sink structure.

Definition at line 1699 of file Reflection.cs.

T AnalyzeReTesting.Utilities.Reflection.Resolve< T > ( IReference< T >  reference)
inline

Resolves a reference in a way that benefits from caching, so that the same reference value never has to be retrieved more than once within an integration test run.

Type Constraints
T :class 
T :IAPIResource 

Definition at line 630 of file Reflection.cs.

bool AnalyzeReTesting.Utilities.Reflection.ResourceIsValidForAnalysisProfile ( IAPIResource  to_validate,
AnalysisProfile  rootAp 
)
inline

Validate that the specified resource is compatible with the current analysis profile (e.g. that it doesn't reference any other event catalogs or loss filters).

Parameters
to_validateThe resource to validate.
rootApThe analysis profile to validate against.
Returns
True if the resource contains no invalid references.

TODO: We frequently need to add conditions to this test method to ensure randomly generated resources aren't known to be invalid for POST. This usually arises when selecting random existing references from the server to reference. We should create a suite of tests to ensure this method is correctly detecting each of the known scenarios that have arisen in the past so that we don't need to rely on Randomized tests only sporadically producing those scenarios.

Definition at line 1839 of file Reflection.cs.

T AnalyzeReTesting.Utilities.Reflection.TryGenerate< T > ( Func< T >  generator,
Func< T, bool >  validation_test,
Func< string >  get_error,
PropertyInfo  property,
bool  exception_on_failure = true 
)
inline

Attempt to generate a resource randomly, with some validation to see if the attempt was successful. Throws an exception if it fails.

Template Parameters
TThe type of object being generated.
Parameters
generatorGenerates an object of type T.
validation_testDetermines if the object is valid.
get_errorReturns an error message if object is invalid.
propertyThe property information for logs and error messages.
Returns
The generated object.
Parameters
exception_on_failureWhether failure sure raise a PropertyGenerationException or simply return default(T)
Exceptions
PropertyGenerationExceptionGeneration fails.

Definition at line 1741 of file Reflection.cs.

void AnalyzeReTesting.Utilities.Reflection.UploadResourceData ( IAPIResource_WithDataEndpoint  resource)
inline

If this resource has data endpoints, try uploading some data!

Parameters
resourceThe resource to try uploading data for.

Definition at line 727 of file Reflection.cs.

Property Documentation

AnalysisProfile AnalyzeReTesting.Utilities.Reflection.Target_AnalysisProfile
getset

The default AnalysisProfile to use for various validation assurances.

Definition at line 61 of file Reflection.cs.

bool AnalyzeReTesting.Utilities.Reflection.Validation_Enabled
getset

When true, randomly generated properties will be validated to verify that they can be POSTed successfully. If set to false, properties will be more random, validation will be ignored, and invalid resources may be generated.

Definition at line 72 of file Reflection.cs.


The documentation for this class was generated from the following file: