Table of Contents

Class TakeValue

Namespace
Acuit.Pinpoint.Workflows.Testing.Activities
Assembly
Acuit.Pinpoint.Workflows.Testing.dll

Takes a test value, optionally recording it as a test data item, and optionally failing the test when invalid.

public class TakeValue : Activity<IDataValue>, IActivity
Inheritance
TakeValue
Implements
Inherited Members

Remarks

When the activity executes, it will:

  1. If a ITestLog service is available, log an entry like: "Taking {Name}"
  2. Take the value via Value.
  3. If Validator is specified, apply the validation, replacing any previous validation result that may have existing on the data value provided in the previous step.
  4. If a ITestLog service is available, log an entry like: "{Name} = {Value}", or "{Name} ({DataItemName}) = {Value}" if a DataItemName is specified. If the data value contains a validation result, "{Value}" will contain the validation criteria.
  5. If DataItemName is specified, record the test value to a test data item.
  6. If FailTestIfInvalid is true and the data value contains a validation result indicating a failed validation, throw a TestFailedException.

The activity result value will be the test value.

This activity requires an IActiveTest service, which is normally provided by placing this activity within the body of a RecordTest activity.

Properties

DataItemName

Gets or sets the optional test data item name under which to record the test value.

public ValueSource<string> DataItemName { get; set; }

Property Value

ValueSource<string>

Remarks

If the test value implements IDataValue, then its Descriptor.Units will be used as the additional details in the test data item.

FailReason

Gets or sets an optional reason to use for failed tests, as a format string where the first parameter will be the Name value. If this is not specified, then "Invalid {0}" will be used. This is not evaluated until the validation fails and the test about to be failed.

public ValueSource<string> FailReason { get; set; }

Property Value

ValueSource<string>

Remarks

To configure a value that starts with "{0}" in XAML, this pattern should be used: FailReason="{}{0} too low"

FailTestIfInvalid

Gets or sets whether to fail the test if the test value is invalid. This is required and defaults to true.

public ValueSource<bool> FailTestIfInvalid { get; set; }

Property Value

ValueSource<bool>

Remarks

The test value is invalid if the value obtained from Value implements IValidatedDataValue and IsValid is false.

Name

Gets or sets the value name, which is used in test log entries (e.g., "{Name} = 2.34 A"). This is required.

public ValueSource<string> Name { get; set; }

Property Value

ValueSource<string>

Validator

Gets or sets an optional validator used to validate the test value.

public IDataValueValidator Validator { get; set; }

Property Value

IDataValueValidator

Value

Gets or sets the value to use as the test value. This is required, but it can evaluate to null.

public ValueSource Value { get; set; }

Property Value

ValueSource

Remarks

This can come from a variety of sources, including:

  • A C# expression.
  • A reading.
  • A sampler that monitors one or more readings over time.

Methods

OnExecuteAsync(ActivityContext, CancellationToken)

Derived classes must implement this to perform the activity.

protected override Task<IDataValue> OnExecuteAsync(ActivityContext context, CancellationToken cancellationToken)

Parameters

context ActivityContext

The activity context.

cancellationToken CancellationToken

The cancellation token used to request canceling the activity.

Returns

Task<IDataValue>

A task that represents the asynchronous operation. The value of its Result property contains the result.

Exceptions

ArgumentNullException

context is null.

InvalidOperationException

A service required by the activity is not available, or a required activity property value is not set. This will only occur asynchronously, wrapped in an AggregateException as the faulted task's Exception.

Exception

An error occurred while performing the activity. This will only occur asynchronously, wrapped in an AggregateException as the faulted task's Exception.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Remarks

This is expected to produce a string suitable for labeling this activity in a workflow diagram. It should be as specific as possible, but while keeping it very short. In general, it should be the short name of the class (as that is how it would typically be defined in the workflow XAML), optionally followed by other property values of interest in a diagram. The default implementation returns the short name of the class.