Table of Contents

Class ActivityEnvironment

Namespace
Temporalio.Testing
Assembly
Temporalio.dll

Testing environment which populates the ActivityExecutionContext for test code.

public record ActivityEnvironment : IEquatable<ActivityEnvironment>
Inheritance
ActivityEnvironment
Implements
Inherited Members

Fields

DefaultInfo

Default activity info.

public static readonly ActivityInfo DefaultInfo

Field Value

ActivityInfo

Properties

CancelReason

Gets or sets the cancel reason. Callers may prefer Cancel(ActivityCancelReason) instead.

public ActivityCancelReason CancelReason { get; set; }

Property Value

ActivityCancelReason

CancellationTokenSource

Gets or inits the cancellation token source.

public CancellationTokenSource CancellationTokenSource { get; init; }

Property Value

CancellationTokenSource

Heartbeater

Gets or inits the heartbeat callback. Default is a no-op callback.

public Action<object?[]> Heartbeater { get; init; }

Property Value

Action<object[]>

Info

Gets or inits the activity info. Default is DefaultInfo.

public ActivityInfo Info { get; init; }

Property Value

ActivityInfo

Logger

Gets or inits the logger. Default is a no-op logger.

public ILogger Logger { get; init; }

Property Value

ILogger

MetricMeter

Gets or inits the metric meter for this activity. If unset, a noop meter is used.

public MetricMeter? MetricMeter { get; init; }

Property Value

MetricMeter

PayloadConverter

Gets or inits the payload converter. Default is default converter.

public IPayloadConverter PayloadConverter { get; init; }

Property Value

IPayloadConverter

WorkerShutdownTokenSource

Gets or inits the worker shutdown token source.

public CancellationTokenSource WorkerShutdownTokenSource { get; init; }

Property Value

CancellationTokenSource

Methods

Cancel(ActivityCancelReason)

If cancellation not already requested, set the cancel reason and cancel the token source.

public void Cancel(ActivityCancelReason reason = ActivityCancelReason.CancelRequested)

Parameters

reason ActivityCancelReason

Cancel reason.

RunAsync(Action)

Run the given activity with a context.

public Task RunAsync(Action activity)

Parameters

activity Action

Activity to run.

Returns

Task

Task for activity completion.

RunAsync(Func<Task>)

Run the given activity with a context.

public Task RunAsync(Func<Task> activity)

Parameters

activity Func<Task>

Activity to run.

Returns

Task

Task for activity completion.

RunAsync<T>(Func<Task<T>>)

Run the given activity with a context.

public Task<T> RunAsync<T>(Func<Task<T>> activity)

Parameters

activity Func<Task<T>>

Activity to run.

Returns

Task<T>

Activity result.

Type Parameters

T

Return type.

RunAsync<T>(Func<T>)

Run the given activity with a context.

public Task<T> RunAsync<T>(Func<T> activity)

Parameters

activity Func<T>

Activity to run.

Returns

Task<T>

Activity result.

Type Parameters

T

Return type.