Table of Contents

Class BunitJSInteropSetupExtensions

Namespace
Bunit
Assembly
Bunit.Web.dll

Helper methods for creating invocation handlers and adding the to a BunitJSInterop.

public static class BunitJSInteropSetupExtensions
Inheritance
BunitJSInteropSetupExtensions
Inherited Members

Methods

SetupModule(BunitJSInterop)

Configure a catch all JSObjectReferenceInvocationHandler invocation handler for any module load and invocations on those modules.

public static BunitJSModuleInterop SetupModule(this BunitJSInterop jsInterop)

Parameters

jsInterop BunitJSInterop

The JSInterop to setup the handler for.

Returns

BunitJSModuleInterop

A BunitJSModuleInterop.

Remarks

The returned BunitJSInterop can be used to setup handlers for InvokeAsync<TValue>(string, object?[]?)" calls to the module, using either SetupModule(BunitJSInterop, string) or Setup calls.

Exceptions

ArgumentNullException

Thrown when jsInterop is null.

SetupModule(BunitJSInterop, InvocationMatcher, bool)

Setup a handler for a IJSRuntime.InvokeAsync<IJSObjectReference>() call whose input parameters is matched by the provided invocationMatcher.

public static BunitJSModuleInterop SetupModule(this BunitJSInterop jsInterop, InvocationMatcher invocationMatcher, bool isCatchAllHandler = false)

Parameters

jsInterop BunitJSInterop

The JSInterop to setup the handler for.

invocationMatcher InvocationMatcher

The matcher to use to match JSRuntimeInvocation's with.

isCatchAllHandler bool

Set to true if the created handler is a catch all handler, that should only be used if there are no other non-catch all handlers available.

Returns

BunitJSModuleInterop

A BunitJSModuleInterop.

Remarks

The returned BunitJSInterop can be used to setup handlers for InvokeAsync<TValue>(string, object?[]?)" calls to the module, using either SetupModule(BunitJSInterop, string) or Setup calls.

Exceptions

ArgumentNullException

Thrown when jsInterop is null.

ArgumentNullException

Thrown when invocationMatcher is null.

SetupModule(BunitJSInterop, string)

Setup a handler for a IJSRuntime.InvokeAsync<IJSObjectReference>("import", moduleName) call.

public static BunitJSModuleInterop SetupModule(this BunitJSInterop jsInterop, string moduleName)

Parameters

jsInterop BunitJSInterop

The JSInterop to setup the handler for.

moduleName string

The name of the JavaScript module to handle invocations for.

Returns

BunitJSModuleInterop

A BunitJSModuleInterop.

Remarks

The returned BunitJSInterop can be used to setup handlers for InvokeAsync<TValue>(string, object?[]?)" calls to the module, using either SetupModule(BunitJSInterop, string) or Setup calls.

Exceptions

ArgumentNullException

Thrown when jsInterop is null.

ArgumentException

Thrown when moduleName is null or whitespace.

SetupModule(BunitJSInterop, string, InvocationMatcher)

Setup a handler for a IJSRuntime.InvokeAsync<IJSObjectReference>() call whose input parameters is matched by the provided invocationMatcher and the identifier.

public static BunitJSModuleInterop SetupModule(this BunitJSInterop jsInterop, string identifier, InvocationMatcher invocationMatcher)

Parameters

jsInterop BunitJSInterop

The JSInterop to setup the handler for.

identifier string

The identifier to setup a response for.

invocationMatcher InvocationMatcher

The matcher to use to match JSRuntimeInvocation's with.

Returns

BunitJSModuleInterop

A BunitJSModuleInterop.

Remarks

The returned BunitJSInterop can be used to setup handlers for InvokeAsync<TValue>(string, object?[]?)" calls to the module, using either SetupModule(BunitJSInterop, string) or Setup calls.

Exceptions

ArgumentNullException

Thrown when jsInterop is null.

ArgumentNullException

Thrown when invocationMatcher is null.

SetupModule(BunitJSInterop, string, object?[])

Setup a handler for a IJSRuntime.InvokeAsync<IJSObjectReference>(identifier, arguments) call.

public static BunitJSModuleInterop SetupModule(this BunitJSInterop jsInterop, string identifier, object?[] arguments)

Parameters

jsInterop BunitJSInterop

The JSInterop to setup the handler for.

identifier string

The identifier to setup a response for.

arguments object[]

The arguments that an invocation to identifier should match. Use Array.Empty<object?>() for none.

Returns

BunitJSModuleInterop

A BunitJSModuleInterop.

Remarks

The returned BunitJSInterop can be used to setup handlers for InvokeAsync<TValue>(string, object?[]?)" calls to the module, using either SetupModule(BunitJSInterop, string) or Setup calls.

Exceptions

ArgumentNullException

Thrown when jsInterop is null.

ArgumentException

Thrown when identifier is null or whitespace.

SetupVoid(BunitJSInterop)

Configure a catch all JSInterop invocation handler, that should not receive any result.

public static JSRuntimeInvocationHandler SetupVoid(this BunitJSInterop jsInterop)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

Returns

JSRuntimeInvocationHandler

A JSRuntimeInvocationHandler.

SetupVoid(BunitJSInterop, InvocationMatcher, bool)

Configure a JSInterop invocation handler for an InvokeVoidAsync call with arguments passing the invocationMatcher test, that should not receive any result.

public static JSRuntimeInvocationHandler SetupVoid(this BunitJSInterop jsInterop, InvocationMatcher invocationMatcher, bool isCatchAllHandler = false)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

invocationMatcher InvocationMatcher

A matcher that is passed an JSRuntimeInvocation. If it returns true the invocation is matched.

isCatchAllHandler bool

Set to true if the created handler is a catch all handler, that should only be used if there are no other non-catch all handlers available.

Returns

JSRuntimeInvocationHandler

A JSRuntimeInvocationHandler.

SetupVoid(BunitJSInterop, string, InvocationMatcher)

Configure a JSInterop invocation handler with the identifier and arguments passing the invocationMatcher test, that should not receive any result.

public static JSRuntimeInvocationHandler SetupVoid(this BunitJSInterop jsInterop, string identifier, InvocationMatcher invocationMatcher)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

identifier string

The identifier to setup a response for.

invocationMatcher InvocationMatcher

A matcher that is passed an JSRuntimeInvocation associated with theidentifier. If it returns true the invocation is matched.

Returns

JSRuntimeInvocationHandler

A JSRuntimeInvocationHandler.

SetupVoid(BunitJSInterop, string, params object?[]?)

Configure a JSInterop invocation handler with the identifier and arguments, that should not receive any result.

public static JSRuntimeInvocationHandler SetupVoid(this BunitJSInterop jsInterop, string identifier, params object?[]? arguments)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

identifier string

The identifier to setup a response for.

arguments object[]

The arguments that an invocation to identifier should match.

Returns

JSRuntimeInvocationHandler

A JSRuntimeInvocationHandler.

Setup<TResult>(BunitJSInterop)

Configure a catch all JSInterop invocation handler for a specific return type. This will match only on the TResult, and any arguments passed to InvokeAsync<TValue>(string, object[]).

public static JSRuntimeInvocationHandler<TResult> Setup<TResult>(this BunitJSInterop jsInterop)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

Returns

JSRuntimeInvocationHandler<TResult>

A JSRuntimeInvocationHandler<TResult>.

Type Parameters

TResult

The result type of the invocation.

Setup<TResult>(BunitJSInterop, InvocationMatcher, bool)

Configure a JSInterop invocation handler for an InvokeAsync<TResult> call with arguments passing the invocationMatcher test.

public static JSRuntimeInvocationHandler<TResult> Setup<TResult>(this BunitJSInterop jsInterop, InvocationMatcher invocationMatcher, bool isCatchAllHandler = false)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

invocationMatcher InvocationMatcher

A matcher that is passed an JSRuntimeInvocation. If it returns true the invocation is matched.

isCatchAllHandler bool

Set to true if the created handler is a catch all handler, that should only be used if there are no other non-catch all handlers available.

Returns

JSRuntimeInvocationHandler<TResult>

A JSRuntimeInvocationHandler<TResult>.

Type Parameters

TResult

The result type of the invocation.

Setup<TResult>(BunitJSInterop, string, InvocationMatcher)

Configure a JSInterop invocation handler with the identifier and arguments passing the invocationMatcher test.

public static JSRuntimeInvocationHandler<TResult> Setup<TResult>(this BunitJSInterop jsInterop, string identifier, InvocationMatcher invocationMatcher)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

identifier string

The identifier to setup a response for.

invocationMatcher InvocationMatcher

A matcher that is passed an JSRuntimeInvocation associated with theidentifier. If it returns true the invocation is matched.

Returns

JSRuntimeInvocationHandler<TResult>

A JSRuntimeInvocationHandler<TResult>.

Type Parameters

TResult

The result type of the invocation.

Setup<TResult>(BunitJSInterop, string, params object?[]?)

Configure a JSInterop invocation handler with the identifier and arguments.

public static JSRuntimeInvocationHandler<TResult> Setup<TResult>(this BunitJSInterop jsInterop, string identifier, params object?[]? arguments)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

identifier string

The identifier to setup a response for.

arguments object[]

The arguments that an invocation to identifier should match.

Returns

JSRuntimeInvocationHandler<TResult>

A JSRuntimeInvocationHandler<TResult>.

Type Parameters

TResult

The type of value to match with in a InvokeAsync<TResult> call.

TryGetInvokeHandler<TResult>(BunitJSInterop, string, params object?[]?)

Looks through the registered handlers and returns the latest registered that can handle the provided identifier and arguments, and that will return TResult.

public static JSRuntimeInvocationHandler<TResult>? TryGetInvokeHandler<TResult>(this BunitJSInterop jsInterop, string identifier, params object?[]? arguments)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

identifier string

The identifier the handler should match with.

arguments object[]

The arguments that an invocation to identifier should match.

Returns

JSRuntimeInvocationHandler<TResult>

Returns the JSRuntimeInvocationHandler<TResult> or null if no one is found.

Type Parameters

TResult

The result type of the invocation.

TryGetInvokeVoidHandler(BunitJSInterop, string, params object?[]?)

Looks through the registered handlers and returns the latest registered that can handle the provided identifier and arguments, and that returns a "void" result.

public static JSRuntimeInvocationHandler? TryGetInvokeVoidHandler(this BunitJSInterop jsInterop, string identifier, params object?[]? arguments)

Parameters

jsInterop BunitJSInterop

The bUnit JSInterop to setup the invocation handling with.

identifier string

The identifier the handler should match with.

arguments object[]

The arguments that an invocation to identifier should match.

Returns

JSRuntimeInvocationHandler

Returns the JSRuntimeInvocationHandler or null if no one is found.

TryGetModuleJSInterop(BunitJSInterop, string, params object?[]?)

Looks through the registered handlers and returns the latest registered that can handle the provided identifier and arguments, and that will return IJSObjectReference.

public static BunitJSModuleInterop? TryGetModuleJSInterop(this BunitJSInterop jsInterop, string identifier, params object?[]? arguments)

Parameters

jsInterop BunitJSInterop

The JSInterop to setup the handler for.

identifier string

The identifier the handler should match with.

arguments object[]

The arguments that an invocation to identifier should match.

Returns

BunitJSModuleInterop

A BunitJSModuleInterop or null if no one is found.

Progress Telerik

Premium sponsor: Progress Telerik.

Packt

Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.