Class AzureFunctionTestHostBuilder

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

Fluently builds a dependency-injection host for isolated-worker function tests.

public sealed class AzureFunctionTestHostBuilder
Inheritance
AzureFunctionTestHostBuilder
Inherited Members
Extension Methods

Methods

AddFunction<TFunction>()

Adds a function class that can be resolved from the test host.

public AzureFunctionTestHostBuilder AddFunction<TFunction>() where TFunction : class

Returns

AzureFunctionTestHostBuilder

This builder, for chaining.

Type Parameters

TFunction

The reference-type function class registered with transient lifetime.

Build()

Creates the configured function test host.

public AzureFunctionTestHost Build()

Returns

AzureFunctionTestHost

A new host that owns its service provider and must be disposed. Registered singleton and scoped disposable services are released with the host or invocation scope respectively.

ConfigureServices(Action<IServiceCollection>)

Configures dependencies used by function instances and invocation contexts.

public AzureFunctionTestHostBuilder ConfigureServices(Action<IServiceCollection> configure)

Parameters

configure Action<IServiceCollection>

A non-null callback invoked synchronously once with the builder-owned mutable service collection. It may add, remove, or replace registrations but must not retain the collection.

Returns

AzureFunctionTestHostBuilder

This builder, for chaining.

UseMiddleware(Func<FunctionContext, FunctionExecutionDelegate, Task>)

Adds inline middleware to the test invocation pipeline.

public AzureFunctionTestHostBuilder UseMiddleware(Func<FunctionContext, FunctionExecutionDelegate, Task> middleware)

Parameters

middleware Func<FunctionContext, FunctionExecutionDelegate, Task>

A non-null asynchronous delegate retained by the host and invoked once per invocation in registration order. It may short-circuit by not invoking the supplied next delegate.

Returns

AzureFunctionTestHostBuilder

This builder, for chaining.

UseMiddleware<TMiddleware>()

Adds isolated-worker middleware to the test invocation pipeline.

public AzureFunctionTestHostBuilder UseMiddleware<TMiddleware>() where TMiddleware : class, IFunctionsWorkerMiddleware

Returns

AzureFunctionTestHostBuilder

This builder, for chaining. Middleware executes in registration order.

Type Parameters

TMiddleware

The middleware class registered transiently and resolved once per invocation from its scope.

UseScenarioResource(string, ITestScenarioResource)

Registers borrowed mutable state for scenario reset and failure diagnostics.

public AzureFunctionTestHostBuilder UseScenarioResource(string name, ITestScenarioResource resource)

Parameters

name string

A non-empty, case-insensitively unique name other than the reserved $Invocation.

resource ITestScenarioResource

The non-null resource. The caller owns and disposes it.

Returns

AzureFunctionTestHostBuilder

This builder, for chaining.

Remarks

Resources are reset before and after explicit scenarios. Register them separately in DI if functions need them.