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
factoriesComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
conditionPredicate<Type>The condition that must be met for the
factoryto be used.factoryFunc<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/orfactoryis 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
factoriesComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
factoryFunc<TComponent>The component factory to use to create substitute components with.
Returns
Type Parameters
TComponentType 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
factoriesand/orfactoryis 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
factoriesComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
instanceTComponentThe instance of the replacement component.
Returns
Type Parameters
TComponentType 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
factoriesand/orinstanceis 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
factoriesComponentFactoryCollectionThe bUnit ComponentFactoryCollection to configure.
Returns
Type Parameters
TComponentType of component to replace.
TSubstituteComponentType of component to substitute with.
Exceptions
- ArgumentNullException
Thrown when
factoriesis null.