Table of Contents

Class ComponentFactoryCollectionExtensions

Namespace
Bunit
Assembly
Bunit.Core.dll

Extension methods for using component doubles.

public static class ComponentFactoryCollectionExtensions
Inheritance
ComponentFactoryCollectionExtensions
Inherited Members

Methods

Add(ComponentFactoryCollection, Predicate<Type>, Func<Type, IComponent>)

Configures bUnit to substitute components whose type matches the condition, with components created by the provided component factory.

public static ComponentFactoryCollection Add(this ComponentFactoryCollection factories, Predicate<Type> condition, Func<Type, IComponent> factory)

Parameters

factories ComponentFactoryCollection

The bUnit ComponentFactoryCollection to configure.

condition Predicate<Type>

The condition that must be met for the factory to be used.

factory Func<Type, IComponent>

The factory to use to create substitute components with.

Returns

ComponentFactoryCollection

A ComponentFactoryCollection.

Remarks

The provided factory must return unique instances each time it is called. Blazor does not allow the same component to exists in multiple places in a render tree.

Exceptions

ArgumentNullException

Thrown when factories, condition, and/or factory is null.

Add<TComponent>(ComponentFactoryCollection, Func<TComponent>)

Configures bUnit to substitute components of type TComponent with one created by the provided component factory.

public static ComponentFactoryCollection Add<TComponent>(this ComponentFactoryCollection factories, Func<TComponent> factory) where TComponent : IComponent

Parameters

factories ComponentFactoryCollection

The bUnit ComponentFactoryCollection to configure.

factory Func<TComponent>

The component factory to use to create substitute components with.

Returns

ComponentFactoryCollection

A ComponentFactoryCollection.

Type Parameters

TComponent

Type of component to substitute.

Remarks

The provided factory must return unique instances each time it is called. Blazor does not allow the same component to exists in multiple places in a render tree.

Exceptions

ArgumentNullException

Thrown when factories and/or factory is null.

Add<TComponent>(ComponentFactoryCollection, TComponent)

Configures bUnit to substitute a component of type TComponent with the provided instance.

public static ComponentFactoryCollection Add<TComponent>(this ComponentFactoryCollection factories, TComponent instance) where TComponent : IComponent

Parameters

factories ComponentFactoryCollection

The bUnit ComponentFactoryCollection to configure.

instance TComponent

The instance of the replacement component.

Returns

ComponentFactoryCollection

A ComponentFactoryCollection.

Type Parameters

TComponent

Type of component to substitute.

Remarks

Only one TComponent component can be substituted with the component (instance). If there are two or more TComponent components in the render tree, an exception is thrown.

Exceptions

ArgumentNullException

Thrown when factories and/or instance is null.

Add<TComponent, TSubstituteComponent>(ComponentFactoryCollection)

Configures bUnit to substitute all components of type TComponent with components of type TSubstituteComponent.

public static ComponentFactoryCollection Add<TComponent, TSubstituteComponent>(this ComponentFactoryCollection factories) where TComponent : IComponent where TSubstituteComponent : IComponent

Parameters

factories ComponentFactoryCollection

The bUnit ComponentFactoryCollection to configure.

Returns

ComponentFactoryCollection

A ComponentFactoryCollection.

Type Parameters

TComponent

Type of component to replace.

TSubstituteComponent

Type of component to substitute with.

Exceptions

ArgumentNullException

Thrown when factories is null.

Progress Telerik

Premium sponsor: Progress Telerik.

Packt

Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.