Table of Contents

Class TestContextBase

Namespace
Bunit
Assembly
Bunit.Core.dll

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

public abstract class TestContextBase : IDisposable
Inheritance
TestContextBase
Implements
Derived
Inherited Members
Extension Methods

Constructors

TestContextBase()

Initializes a new instance of the TestContextBase class.

protected TestContextBase()

Properties

ComponentFactories

Gets the ComponentFactoryCollection. Factories added to it will be used to create components during testing, starting with the last added factory. If no factories in the collection can create a requested component, then the default Blazor factory is used.

public ComponentFactoryCollection ComponentFactories { get; }

Property Value

ComponentFactoryCollection

DefaultWaitTimeout

Gets or sets the default wait timeout used by "WaitFor" operations, i.e. WaitForAssertion(IRenderedFragmentBase, Action, TimeSpan?).

public static TimeSpan DefaultWaitTimeout { get; set; }

Property Value

TimeSpan

Remarks

The default is 1 second.

RenderTree

Gets the RootRenderTree that all components rendered with the RenderComponent<TComponent>() methods, are rendered inside.

public RootRenderTree RenderTree { get; }

Property Value

RootRenderTree

Remarks

Use this to add default layout- or root-components which a component under test should be rendered under.

Renderer

Gets the renderer used by the test context.

public ITestRenderer Renderer { get; }

Property Value

ITestRenderer

Services

Gets the service collection and service provider that is used when a component is rendered by the test context.

public TestServiceProvider Services { get; }

Property Value

TestServiceProvider

Methods

CreateTestRenderer()

Creates the renderer.

protected abstract ITestRenderer CreateTestRenderer()

Returns

ITestRenderer

Dispose()

public void Dispose()

Dispose(bool)

Disposes of the test context resources, in particular it disposes the Services service provider. Any async services registered with the service provider will disposed first, but their disposal will not be awaited..

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Set to true if called from Dispose(), false if called from a finalizer.f.

Remarks

The disposing parameter should be false when called from a finalizer, and true when called from the Dispose() method. In other words, it is true when deterministically called and false when non-deterministically called.

DisposeComponents()

Disposes all components rendered via this TestContextBase.

public void DisposeComponents()
Progress Telerik

Premium sponsor: Progress Telerik.

Packt

Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.