Class AzureFunctionTestHost

Namespace
XBullet.EasyTesting.AzureFunctions
Assembly
XBullet.EasyTesting.AzureFunctions.dll

Provides function instances and fluent trigger data backed by one service provider.

public sealed class AzureFunctionTestHost : IDisposable, IAsyncDisposable
Inheritance
AzureFunctionTestHost
Implements
Inherited Members

Remarks

Methods

BlobTrigger()

Starts a fluent Blob Storage trigger definition.

public static BlobTriggerBuilder BlobTrigger()

Returns

BlobTriggerBuilder

A new mutable builder with binding name blob and empty binary content.

CreateBuilder()

Starts a function test-host definition.

public static AzureFunctionTestHostBuilder CreateBuilder()

Returns

AzureFunctionTestHostBuilder

A new mutable builder with logging and web-default JSON worker serialization configured.

CreateContext(string, CancellationToken)

Creates a minimal isolated-worker invocation context.

public TestFunctionContext CreateContext(string functionName, CancellationToken cancellationToken = default)

Parameters

functionName string

The non-empty friendly name and identifier assigned to the function.

cancellationToken CancellationToken

The token exposed through the context. The default token does not request cancellation.

Returns

TestFunctionContext

A new mutable context backed initially by the host's root services.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

EventGridTrigger()

Starts a fluent Event Grid trigger definition.

public static EventGridTriggerBuilder EventGridTrigger()

Returns

EventGridTriggerBuilder

A new mutable builder populated with deterministic test defaults except for generated ID and current event time.

EventHubsTrigger()

Starts a fluent Event Hubs trigger definition.

public static EventHubsTriggerBuilder EventHubsTrigger()

Returns

EventHubsTriggerBuilder

A new mutable builder with binding name events and an empty batch.

GetRequiredService<T>()

Resolves a registered function or dependency.

public T GetRequiredService<T>() where T : notnull

Returns

T

The required registered service. The host retains disposal ownership.

Type Parameters

T

The non-null service type to resolve from the host's root provider.

HttpRequest(string, CancellationToken)

Starts a fluent HTTP-trigger request for a function.

public TestHttpRequestBuilder HttpRequest(string functionName, CancellationToken cancellationToken = default)

Parameters

functionName string

The non-empty friendly name assigned to the invocation context.

cancellationToken CancellationToken

The token exposed through the request's function context. The default does not request cancellation.

Returns

TestHttpRequestBuilder

A new mutable HTTP request builder and invocation context.

InvokeAsync<TFunction>(TestFunctionContext, Func<TFunction, TestFunctionContext, Task>)

Executes a function delegate through configured worker middleware.

public Task<TestFunctionInvocationResult> InvokeAsync<TFunction>(TestFunctionContext context, Func<TFunction, TestFunctionContext, Task> invoke) where TFunction : notnull

Parameters

context TestFunctionContext

The non-null mutable test context used by middleware and the function. It is retained by the result and remains caller-owned.

invoke Func<TFunction, TestFunctionContext, Task>

A non-null asynchronous callback invoked at most once with the scoped function instance and context if middleware reaches the terminal delegate. It must not retain scoped services.

Returns

Task<TestFunctionInvocationResult>

A task whose result reports the context and whether middleware reached the function. The invocation scope is disposed before completion.

Type Parameters

TFunction

The registered function or service type resolved in a fresh invocation scope.

InvokeAsync<TFunction, TTrigger>(string, TestTriggerData<TTrigger>, Func<TFunction, TTrigger, TestFunctionContext, Task>, CancellationToken)

Creates a context, captures trigger input, and invokes a function through middleware.

public Task<TestFunctionInvocationResult> InvokeAsync<TFunction, TTrigger>(string functionName, TestTriggerData<TTrigger> trigger, Func<TFunction, TTrigger, TestFunctionContext, Task> invoke, CancellationToken cancellationToken = default) where TFunction : notnull

Parameters

functionName string

The non-empty friendly function name.

trigger TestTriggerData<TTrigger>

The non-null trigger value and binding metadata to apply to the new context.

invoke Func<TFunction, TTrigger, TestFunctionContext, Task>

A non-null callback invoked at most once with the scoped function, trigger value, and context. It must not retain scoped services.

cancellationToken CancellationToken

The token exposed through the new context. The default does not request cancellation.

Returns

Task<TestFunctionInvocationResult>

A task whose result reports whether middleware reached the function and exposes the context.

Type Parameters

TFunction

The registered function type resolved in a fresh invocation scope.

TTrigger

The trigger parameter type.

InvokeAsync<TFunction, TResult>(TestFunctionContext, Func<TFunction, TestFunctionContext, Task<TResult>>)

Executes a value-returning function delegate and captures all returned output properties.

public Task<TestFunctionInvocationResult<TResult>> InvokeAsync<TFunction, TResult>(TestFunctionContext context, Func<TFunction, TestFunctionContext, Task<TResult>> invoke) where TFunction : notnull

Parameters

context TestFunctionContext

The non-null mutable context retained by the result and owned by the caller.

invoke Func<TFunction, TestFunctionContext, Task<TResult>>

A non-null asynchronous callback invoked at most once if middleware reaches the terminal delegate. It must not retain the scoped function or services.

Returns

Task<TestFunctionInvocationResult<TResult>>

A task whose result contains the returned value and captured outputs, or the default TResult value when middleware short-circuits. The scope is disposed first.

Type Parameters

TFunction

The registered function or service type resolved in a fresh invocation scope.

TResult

The function return type whose public output properties are captured.

InvokeAsync<TFunction, TTrigger, TResult>(string, TestTriggerData<TTrigger>, Func<TFunction, TTrigger, TestFunctionContext, Task<TResult>>, CancellationToken)

Creates a context, captures trigger input and returned outputs, and invokes a function through middleware.

public Task<TestFunctionInvocationResult<TResult>> InvokeAsync<TFunction, TTrigger, TResult>(string functionName, TestTriggerData<TTrigger> trigger, Func<TFunction, TTrigger, TestFunctionContext, Task<TResult>> invoke, CancellationToken cancellationToken = default) where TFunction : notnull

Parameters

functionName string

The non-empty friendly function name.

trigger TestTriggerData<TTrigger>

The non-null trigger value and binding metadata to apply to the new context.

invoke Func<TFunction, TTrigger, TestFunctionContext, Task<TResult>>

A non-null callback invoked at most once with the scoped function, trigger value, and context. It must not retain scoped services.

cancellationToken CancellationToken

The token exposed through the new context. The default does not request cancellation.

Returns

Task<TestFunctionInvocationResult<TResult>>

A task whose result contains the function value and captured outputs, or the default result value when middleware short-circuits.

Type Parameters

TFunction

The registered function type resolved in a fresh invocation scope.

TTrigger

The trigger parameter type.

TResult

The function return type whose output properties are captured.

QueueTrigger()

Starts a fluent Queue Storage trigger definition.

public static QueueTriggerBuilder QueueTrigger()

Returns

QueueTriggerBuilder

A new mutable builder with binding name message and an empty body.

ServiceBusTrigger()

Starts a fluent Service Bus trigger definition.

public static ServiceBusTriggerBuilder ServiceBusTrigger()

Returns

ServiceBusTriggerBuilder

A new mutable builder with binding name message and an empty body.

Timer()

Starts a fluent timer-trigger data definition.

public static TestTimerInfoBuilder Timer()

Returns

TestTimerInfoBuilder

A new mutable timer builder with an on-time invocation and no schedule status.