C# Client Library
A C# Client Library for the AnalyzeRe REST API
|
A collection of 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, int? seedForRandom=null) | |
Instantiate a class that can be used to generate random resources via reflection. | |
bool | AnyAnalysisMatchesCriteria (IAPIAnalysis analysis, Func< IAPIAnalysis, bool > test) |
Recursively determines if the layer, or any inner layers it references match the specified criteria. | |
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. | |
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. | |
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. | |
IReference< T > | CacheResource< T > (IReference< T > reference) |
Cache some known posted resource reference so that it can be reused. | |
IReference< T > | CacheResource< T > (T resource) |
Cache some known posted resource so that it can be reused. | |
object | ChangePropertyValueRandomly (IAPIType obj, PropertyInfo prop, int max_attempts=Max_ReRandomize_Attempts, RecursionContext parentRecursionInfo=null) |
Randomly change the specified property to some different value. | |
object | CreateRandomizedInstance (Type desiredType, RecursionContext parentRecursionInfo=null) |
Generates a new randomized object of the specified type. | |
T | CreateRandomizedInstance< T > (RecursionContext parentRecursionInfo=null) |
Overload of CreateRandomizedInstance that uses a compile-time type parameter and returns a strong type. | |
T | FinalizePostedResource< T > (T posted) |
Helper method for ensuring a newly posted resource is left in a finalized state. | |
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. | |
IReference< IAPIResource > | GetRandomExistingResource (Type T, RecursionContext currentRecursion) |
Tries to find an existing (POSTed) resource of the specified type without generating a new one. | |
IReference< IAPIResource > | GetSampleOfType (Type T) |
Get a standard IInjectableResource<T> value matching the given type. | |
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. | |
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. | |
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. | |
T | 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. | |
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). | |
T | TryGenerate< T > (Func< T > generator, Func< T, bool > validation_test, Func< string > get_error, PropertyInfo property, bool exception_on_failure=true, RecursionContext recursionInfo=null) |
Attempt to generate a resource randomly, with some validation to see if the attempt was successful. Throws an exception if it fails. | |
T | UploadResourceData< T > (T resource) |
If this resource has data endpoints, try uploading some data! | |
Static Public Member Functions | |
static IEnumerable< Type > | GetAllInstantiableSubtypes (Type type) |
Creates a list of types that can be derived from a given type. | |
static ILayer | GetLayerDefinition (ILayerSource layerSource) |
Convert the ILayerSource to a layer instance by extracting the ILayerView.layer property if it is a ILayerView. | |
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. | |
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, RecursionContext recursionInfo=null) |
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. | |
Properties | |
AnalysisProfile | Target_AnalysisProfile [get, set] |
The default AnalysisProfile to use for various validation assurances. | |
bool | Validation_Enabled = true [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. | |
A collection of filthy hacks to populate some fields of APIResources objects of any type.
TODO: This class and all that use it should implement disposable, since ThreadLocal{Random} thread_safe_random
is disposable. This isn't too important, since test classes only live as long as a test run.
Definition at line 40 of file Reflection.cs.
|
inline |
Instantiate a class that can be used to generate random resources via reflection.
samplesInstance | A Samples instance used to provide sample known valid resources and data to upload. |
seedForRandom | A seed to use when initializing the random number generator, which is used for all randomized behaviour. |
Note that if tests are being run in parallel, the order in which tests are called is not deterministic and will subvert any attempts to reproduce tests by supplying the same seed. There is also some server-generated random behaviour that cannot be controlled, such as ids assigned to POSTed resources, and parametric distribution values generated.
Definition at line 96 of file Reflection.cs.
|
inline |
Recursively determines if the layer, or any inner layers it references match the specified criteria.
analysis | The IAPIAnalysis object to recurse on. |
test | The criteria to test against each object encountered. |
Definition at line 2432 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.
rootlayerSource | The root layer or layer_view instance which may contain references to other layers. |
test | The criteria to test against each layer encountered. |
allocationSourcesOnly | If set to true, only nested properties that qualify as allocation sources will be traversed. |
|
inline |
Recursively determines if the layer, or any inner layers it references match the specified criteria.
rootLayerSource | The root layer or layer_view instance which may contain references to other layers. |
test | The criteria to test against each layerSource encountered. |
allocationSourcesOnly | If set to true, only nested properties that qualify as allocation sources will be traversed. |
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 2495 of file Reflection.cs.
|
inline |
Recursively determines if the loss set, or any inner loss sets it references match the specified criteria.
root | The root loss set which may contain references to other loss sets. |
test | The criteria to test against each loss set encountered. |
Definition at line 2545 of file Reflection.cs.
IReference< T > AnalyzeReTesting.Utilities.Reflection.CacheResource< T > | ( | IReference< T > | reference | ) |
Cache some known posted resource reference so that it can be reused.
T | : | IAPIResource | |
T | : | reference.ResourceType | |
T | : | typeof | |
T | : | T | |
T | : | CacheResource | |
T | : | typeof | |
T | : | T | |
T | : | reference | |
T | : | reference.resolved | |
T | : | CacheResource | |
T | : | reference.GetValue() | |
T | : | CacheResource | |
T | : | reference.ResourceType | |
T | : | reference |
IReference< T > AnalyzeReTesting.Utilities.Reflection.CacheResource< T > | ( | T | resource | ) |
Cache some known posted resource so that it can be reused.
T | : | IAPIResource | |
T | : | CacheResource | |
T | : | resource.GetType() | |
T | : | resource.ToReference | |
T | : | true |
|
inline |
Randomly change the specified property to some different value.
obj | The object whose property should be changed. |
prop | The property whose value should be randomly changed. |
max_attempts | If 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. (Some limit is recommended to avoid infinite loops caused by generation routines only generating one possible value.) |
parentRecursionInfo | The recursion context (if applicable) indicating the parent object(s) owns the obj instance whose property is being randomized. |
Definition at line 1449 of file Reflection.cs.
|
inline |
Generates a new randomized object of the specified type.
desiredType | The type of object to generate. |
parentRecursionInfo | A context object that informs the random generation routines what parent object this resource is being generated for, which can shape its decisions. |
Definition at line 178 of file Reflection.cs.
T AnalyzeReTesting.Utilities.Reflection.CreateRandomizedInstance< T > | ( | RecursionContext | parentRecursionInfo = null | ) |
Overload of CreateRandomizedInstance that uses a compile-time type parameter and returns a strong type.
Helper method for ensuring a newly posted resource is left in a finalized state.
T | : | IAPIResource |
Definition at line 781 of file Reflection.cs.
|
inline |
Definition at line 1934 of file Reflection.cs.
|
inlinestatic |
Creates a list of types that can be derived from a given type.
type | The base type for which to get all instantiable sub-types. |
Definition at line 2408 of file Reflection.cs.
|
static |
Convert the ILayerSource to a layer instance by extracting the ILayerView.layer property if it is a ILayerView.
|
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 2003 of file Reflection.cs.
|
inline |
Tries to find an existing (POSTed) resource of the specified type without generating a new one.
T | The type of resource to locate. |
currentRecursion | The recursion context of the object generation routine that deferred to this helper method. |
Definition at line 573 of file Reflection.cs.
|
inline |
Get a standard IInjectableResource<T> value matching the given type.
T | The type of resource to return a reference to. |
Definition at line 671 of file Reflection.cs.
HashSet< string > AnalyzeReTesting.Utilities.Reflection.GetValidCurrenciesForAnalysisProfile | ( | AnalysisProfile | analysis_profile | ) |
|
static |
Determines whether the object instance that returned the property is of the type TPropertyOwner and the property matches the specified propertyExpression.
|
inline |
Validate that this ILayerSource is compatible with the current analysis profile, including recursive checks of inner layer and loss set definitions.
to_validate | The ILayerSource to validate. |
analysis_profile | The analysis profile to validate against. |
Definition at line 2211 of file Reflection.cs.
|
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.
T | The type of object being generated. |
generator | Generates an object of type T. |
validation_test | Determines if the object is valid. |
get_error | Returns an error message if object is invalid. |
property | The property information for logs and error messages. |
max_attempts | The maximum number of attempts before failing. |
exception_on_failure | Whether failure sure raise a PropertyGenerationException or simply return default(T) |
recursionInfo | Recursion context used for logging. |
PropertyGenerationException | Generation fails and exception_on_failure is set to true. |
Definition at line 2083 of file Reflection.cs.
|
inline |
Validate that this LossSet is compatible with the current analysis profile, including recursive checks of inner layer and loss set definitions.
to_validate | The LossSet to validate. |
analysis_profile | The analysis profile to validate against. |
Definition at line 2253 of file Reflection.cs.
|
inline |
Finds a random source loss set or layer_view id within the specified sinkReference which can be used as a BackAllocatedLayer.source_id.
PropertyGenerationException | If no valid source_id can be found within the sink structure. |
Definition at line 2016 of file Reflection.cs.
|
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.
T | : | class | |
T | : | IAPIResource |
Definition at line 765 of file Reflection.cs.
|
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).
to_validate | The resource to validate. |
rootAp | The analysis profile to validate against. |
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 2161 of file Reflection.cs.
|
inline |
Attempt to generate a resource randomly, with some validation to see if the attempt was successful. Throws an exception if it fails.
T | The type of object being generated. |
generator | Generates an object of type T. |
validation_test | Determines if the object is valid. |
get_error | Returns an error message if object is invalid. |
property | The property information for logs and error messages. |
exception_on_failure | Whether failure sure raise a PropertyGenerationException or simply return default(T) |
recursionInfo | Recursion context used for logging. |
PropertyGenerationException | Generation fails. |
Definition at line 2059 of file Reflection.cs.
If this resource has data endpoints, try uploading some data!
resource | The resource to try uploading data for. |
T | : | IAPIResource_WithDataEndpoint |
Definition at line 799 of file Reflection.cs.
|
getset |
The default AnalysisProfile to use for various validation assurances.
Definition at line 71 of file Reflection.cs.
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 83 of file Reflection.cs.