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
ComponentFactoryCollectionThe 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
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/orfactory
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
ComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
factory
Func<TComponent>The component factory to use to create substitute components with.
Returns
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/orfactory
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
ComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
instance
TComponentThe instance of the replacement component.
Returns
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/orinstance
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
ComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
Returns
Type Parameters
TComponent
Type of component to replace.
TSubstituteComponent
Type of component to substitute with.
Exceptions
- ArgumentNullException
Thrown when
factories
is null.