Table of Contents

Class TestContext

Namespace
Bunit
Assembly
Bunit.Web.dll

A test context is a factory that makes it possible to create components under tests.

public class TestContext : TestContextBase, IDisposable
Inheritance
TestContext
Implements
Inherited Members
Extension Methods

Constructors

TestContext()

Initializes a new instance of the TestContext class.

public TestContext()

Properties

JSInterop

Gets bUnits JSInterop, that allows setting up handlers for InvokeAsync<TValue>(string, object[]) invocations that components under tests will issue during testing. It also makes it possible to verify that the invocations has happened as expected.

public BunitJSInterop JSInterop { get; }

Property Value

BunitJSInterop

Methods

BuildRenderTree(RenderTreeBuilder)

Dummy method required to allow Blazor's compiler to generate C# from .razor files.

protected virtual void BuildRenderTree(RenderTreeBuilder builder)

Parameters

builder RenderTreeBuilder

CreateTestRenderer()

Creates the renderer.

protected override ITestRenderer CreateTestRenderer()

Returns

ITestRenderer

Render(RenderFragment)

Renders the renderFragment and returns it as a IRenderedFragment.

public virtual IRenderedFragment Render(RenderFragment renderFragment)

Parameters

renderFragment RenderFragment

The render fragment to render.

Returns

IRenderedFragment

The IRenderedFragment.

RenderComponent<TComponent>(params ComponentParameter[])

Instantiates and performs a first render of a component of type TComponent.

public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters) where TComponent : IComponent

Parameters

parameters ComponentParameter[]

Parameters to pass to the component when it is rendered.

Returns

IRenderedComponent<TComponent>

The rendered TComponent.

Type Parameters

TComponent

Type of the component to render.

RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>?)

Instantiates and performs a first render of a component of type TComponent.

public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>? parameterBuilder = null) where TComponent : IComponent

Parameters

parameterBuilder Action<ComponentParameterCollectionBuilder<TComponent>>

The ComponentParameterBuilder action to add type safe parameters to pass to the component when it is rendered.

Returns

IRenderedComponent<TComponent>

The rendered TComponent.

Type Parameters

TComponent

Type of the component to render.

Render<TComponent>(RenderFragment)

Renders the renderFragment and returns the first TComponent in the resulting render tree.

public virtual IRenderedComponent<TComponent> Render<TComponent>(RenderFragment renderFragment) where TComponent : IComponent

Parameters

renderFragment RenderFragment

The render fragment to render.

Returns

IRenderedComponent<TComponent>

The IRenderedComponent<TComponent>.

Type Parameters

TComponent

The type of component to find in the render tree.

Remarks

Calling this method is equivalent to calling Render(renderFragment).FindComponent<TComponent>().

Progress Telerik

Premium sponsor: Progress Telerik.

Packt

Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.