Table of Contents

Class MockSharedWorkflowContext

Namespace
Restate.Sdk.Testing
Assembly
Restate.Sdk.Testing.dll

A mock SharedWorkflowContext for unit testing shared workflow handlers. Provides read-only in-memory state and durable promise operations (peek/resolve/reject). Side effects execute inline. Calls and sends are recorded.

public sealed class MockSharedWorkflowContext : SharedWorkflowContext, ISharedWorkflowContext, ISharedObjectContext, IContext
Inheritance
MockSharedWorkflowContext
Implements
Inherited Members

Constructors

MockSharedWorkflowContext(string, string?)

Creates a new mock shared workflow context with the given key.

public MockSharedWorkflowContext(string key = "test-key", string? invocationId = null)

Parameters

key string
invocationId string

Properties

Calls

All recorded Call invocations.

public IReadOnlyList<RecordedCall> Calls { get; }

Property Value

IReadOnlyList<RecordedCall>

Cancellations

All recorded CancelInvocation calls (invocation IDs that were cancelled).

public IReadOnlyList<string> Cancellations { get; }

Property Value

IReadOnlyList<string>

Key

The key of the virtual object instance.

public override string Key { get; }

Property Value

string

Sends

All recorded Send invocations.

public IReadOnlyList<RecordedSend> Sends { get; }

Property Value

IReadOnlyList<RecordedSend>

Sleeps

All recorded Sleep invocations with their requested durations.

public IReadOnlyList<RecordedSleep> Sleeps { get; }

Property Value

IReadOnlyList<RecordedSleep>

StateEntryNames

The entry names passed to named state operations, in call order.

public IReadOnlyList<string> StateEntryNames { get; }

Property Value

IReadOnlyList<string>

Methods

GetPromiseRejection(string)

Gets the rejection reason of a promise for verification.

public string? GetPromiseRejection(string name)

Parameters

name string

Returns

string

GetPromiseValue<T>(string)

Gets the resolved value of a promise for verification.

public T? GetPromiseValue<T>(string name)

Parameters

name string

Returns

T

Type Parameters

T

GetStateValue<T>(string)

Gets the current value of a state key for verification.

public T? GetStateValue<T>(string key)

Parameters

key string

Returns

T

Type Parameters

T

Get<T>(StateKey<T>)

Gets the value for the given state key, or default if not set.

public override ValueTask<T?> Get<T>(StateKey<T> key)

Parameters

key StateKey<T>

Returns

ValueTask<T>

Type Parameters

T

Get<T>(StateKey<T>, string?)

Gets the value for the given state key, or default if not set, labelling the journal entry with entryName so it reads as that name in the Restate UI. The name is observability only: it does not change what is read. The default implementation drops the name and reads through Get<T>(StateKey<T>), so contexts that predate entry names keep working.

public override ValueTask<T?> Get<T>(StateKey<T> key, string? entryName)

Parameters

key StateKey<T>
entryName string

Returns

ValueTask<T>

Type Parameters

T

HasState(string)

Verifies whether a state key exists.

public bool HasState(string key)

Parameters

key string

Returns

bool

IsPromiseRejected(string)

Checks whether a promise has been rejected.

public bool IsPromiseRejected(string name)

Parameters

name string

Returns

bool

IsPromiseResolved(string)

Checks whether a promise has been resolved.

public bool IsPromiseResolved(string name)

Parameters

name string

Returns

bool

PeekPromise<T>(string)

Peeks at a workflow promise without blocking. Returns default if not yet resolved.

public override ValueTask<T?> PeekPromise<T>(string name)

Parameters

name string

Returns

ValueTask<T>

Type Parameters

T

RegisterClient<TClient>(TClient)

Registers a typed client instance to be returned by typed client methods.

public void RegisterClient<TClient>(TClient client) where TClient : class

Parameters

client TClient

Type Parameters

TClient

RejectPromise(string, string)

Rejects a workflow promise with a reason.

public override void RejectPromise(string name, string reason)

Parameters

name string
reason string

ResolvePromise<T>(string, T)

Resolves a workflow promise with a payload.

public override void ResolvePromise<T>(string name, T payload)

Parameters

name string
payload T

Type Parameters

T

SetupAwakeable<T>(T)

Enqueues a value to be returned by the next Awakeable<T>(ISerde<T>?) call.

public void SetupAwakeable<T>(T result)

Parameters

result T

Type Parameters

T

SetupCallFailure(string, string, TerminalException)

Configures a Call to the given service/handler to throw a TerminalException.

public void SetupCallFailure(string service, string handler, TerminalException exception)

Parameters

service string
handler string
exception TerminalException

SetupCallFailure(string, string, string, TerminalException)

Configures a Call to the given service/key/handler to throw a TerminalException.

public void SetupCallFailure(string service, string key, string handler, TerminalException exception)

Parameters

service string
key string
handler string
exception TerminalException

SetupCall<T>(string, string, string, T)

Configures the return value for a Call to the given service/key/handler.

public void SetupCall<T>(string service, string key, string handler, T result)

Parameters

service string
key string
handler string
result T

Type Parameters

T

SetupCall<T>(string, string, T)

Configures the return value for a Call to the given service/handler.

public void SetupCall<T>(string service, string handler, T result)

Parameters

service string
handler string
result T

Type Parameters

T

SetupPromise<T>(string, T)

Pre-resolves a promise so that PeekPromise<T>(string) returns the value.

public void SetupPromise<T>(string name, T value)

Parameters

name string
value T

Type Parameters

T

SetupState<T>(StateKey<T>, T)

Pre-populates a state key for testing.

public void SetupState<T>(StateKey<T> key, T value)

Parameters

key StateKey<T>
value T

Type Parameters

T

SetupState<T>(string, T)

Pre-populates a state key by name.

public void SetupState<T>(string key, T value)

Parameters

key string
value T

Type Parameters

T

StateKeys()

Lists all state keys for this virtual object instance.

public override ValueTask<string[]> StateKeys()

Returns

ValueTask<string[]>

StateKeys(string?)

Lists all state keys for this virtual object instance, labelling the journal entry with entryName. The name is observability only; the default implementation drops it and reads through StateKeys().

public override ValueTask<string[]> StateKeys(string? entryName)

Parameters

entryName string

Returns

ValueTask<string[]>