Table of Contents

Class WorkflowEnvironment

Namespace
Temporalio.Testing
Assembly
Temporalio.dll

Workflow environment for testing with Temporal.

public class WorkflowEnvironment : IAsyncDisposable
Inheritance
WorkflowEnvironment
Implements
Inherited Members

Remarks

This class is NOT thread safe and not safe for use by concurrent tests. Time skipping is locked/unlocked at an environment level, so while reuse is supported, independent concurrent use can have side effects.

In modern versions of .NET, this implements IAsyncDisposable which means it can be used in an await using block.

Constructors

WorkflowEnvironment(ITemporalClient)

Initializes a new instance of the WorkflowEnvironment class for the given client that does not support time skipping.

public WorkflowEnvironment(ITemporalClient client)

Parameters

client ITemporalClient

Client to use for this environment.

Properties

Client

Gets the client for this workflow environment.

public ITemporalClient Client { get; protected init; }

Property Value

ITemporalClient

Logger

Gets a logger for this environment.

protected ILogger<WorkflowEnvironment> Logger { get; }

Property Value

ILogger<WorkflowEnvironment>

SupportsTimeSkipping

Gets a value indicating whether this environment supports time skipping.

public virtual bool SupportsTimeSkipping { get; }

Property Value

bool

Methods

DelayAsync(int, CancellationToken?)

Sleep in this environment.

public Task DelayAsync(int millisecondsDelay, CancellationToken? cancellationToken = null)

Parameters

millisecondsDelay int

Number of milliseconds to sleep.

cancellationToken CancellationToken?

If present, cancellation token for the sleep.

Returns

Task

Completion task.

Remarks

In non-time-skipping environments, this is just Delay(int, CancellationToken), but in time-skipping environments this may simply fast forward time.

DelayAsync(TimeSpan, CancellationToken?)

Sleep in this environment.

public virtual Task DelayAsync(TimeSpan delay, CancellationToken? cancellationToken = null)

Parameters

delay TimeSpan

Amount of time to sleep.

cancellationToken CancellationToken?

If present, cancellation token for the sleep.

Returns

Task

Completion task.

Remarks

In non-time-skipping environments, this is just Delay(TimeSpan, CancellationToken), but in time-skipping environments this may simply fast forward time.

DisposeAsync()

Shutdown and dispose this server.

public ValueTask DisposeAsync()

Returns

ValueTask

Completion task.

GetCurrentTimeAsync()

Get the current time for the environment.

public virtual Task<DateTime> GetCurrentTimeAsync()

Returns

Task<DateTime>

The current time for the environment.

Remarks

For non-time-skipping environments this is just Now, but in time-skipping environments this may be a different time.

ShutdownAsync()

Shutdown this server.

public virtual Task ShutdownAsync()

Returns

Task

Completion task.

Remarks

This has no effect for workflow environments constructed with a simple client.

StartLocalAsync(WorkflowEnvironmentStartLocalOptions?)

Start a local test server with full Temporal capabilities but no time skipping.

public static Task<WorkflowEnvironment> StartLocalAsync(WorkflowEnvironmentStartLocalOptions? options = null)

Parameters

options WorkflowEnvironmentStartLocalOptions

Options for the server.

Returns

Task<WorkflowEnvironment>

The started environment.

Remarks

By default this lazily downloads a server from the internet if not already present.

StartTimeSkippingAsync(WorkflowEnvironmentStartTimeSkippingOptions?)

Start a local test server with time skipping but limited Temporal capabilities.

public static Task<WorkflowEnvironment> StartTimeSkippingAsync(WorkflowEnvironmentStartTimeSkippingOptions? options = null)

Parameters

options WorkflowEnvironmentStartTimeSkippingOptions

Options for the server.

Returns

Task<WorkflowEnvironment>

The started environment.

Remarks

By default this lazily downloads a server from the internet if not already present.

WithAutoTimeSkippingDisabled(Action)

Run a function with automatic time skipping disabled.

public void WithAutoTimeSkippingDisabled(Action func)

Parameters

func Action

Function to run.

Remarks

This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.

WithAutoTimeSkippingDisabledAsync(Func<Task>)

Run a function with automatic time skipping disabled.

public Task WithAutoTimeSkippingDisabledAsync(Func<Task> func)

Parameters

func Func<Task>

Function to run.

Returns

Task

Task for completion.

Remarks

This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.

WithAutoTimeSkippingDisabledAsync<T>(Func<Task<T>>)

Run a function with automatic time skipping disabled.

public virtual Task<T> WithAutoTimeSkippingDisabledAsync<T>(Func<Task<T>> func)

Parameters

func Func<Task<T>>

Function to run.

Returns

Task<T>

Task with resulting value.

Type Parameters

T

Type of result.

Remarks

This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.

WithAutoTimeSkippingDisabled<T>(Func<T>)

Run a function with automatic time skipping disabled.

public T WithAutoTimeSkippingDisabled<T>(Func<T> func)

Parameters

func Func<T>

Function to run.

Returns

T

Resulting value.

Type Parameters

T

Type of result.

Remarks

This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.