Class ComponentState
Wrapper around the renderer state used by FastMoq's Blazor helpers.
Inherited Members
Namespace: FastMoq.Web.Blazor.Models
Assembly: FastMoq.Web.dll
Syntax
public class ComponentState
Remarks
FastMoq uses this wrapper instead of exposing raw renderer internals directly because bUnit 2 changed the shape of the renderer state it stores for rendered components. Consumers should prefer GetOrCreateRenderedComponent(Type) or GetOrCreateRenderedComponent<T>() over reflecting on renderer state objects themselves.
Constructors
ComponentState(object?, BunitRenderer, IRenderedComponent<IComponent>?)
Initializes a new instance of the ComponentState class.
Declaration
public ComponentState(object? obj, BunitRenderer renderer, IRenderedComponent<IComponent>? rootComponent = null)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The raw renderer state object. |
| BunitRenderer | renderer | The renderer. |
| IRenderedComponent<IComponent> | rootComponent | The rendered root component used for nested component lookups when needed. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | renderer |
Properties
Component
Gets the component.
Declaration
public IComponent? Component { get; }
Property Value
| Type | Description |
|---|---|
| IComponent | The component. |
ComponentId
Gets the component identifier.
Declaration
public int ComponentId { get; }
Property Value
| Type | Description |
|---|---|
| int | The component identifier. |
ComponentType
Gets or sets the type of the component.
Declaration
protected Type ComponentType { get; set; }
Property Value
| Type | Description |
|---|---|
| Type | The type of the component. |
CurrentRenderTree
Gets the current render tree.
Declaration
public RenderTreeBuilder? CurrentRenderTree { get; }
Property Value
| Type | Description |
|---|---|
| RenderTreeBuilder | The current render tree. |
IsComponentBase
Gets a value indicating whether this instance is component base.
Declaration
public bool IsComponentBase { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
ParentComponentState
Gets the state of the parent component.
Declaration
public ComponentState? ParentComponentState { get; }
Property Value
| Type | Description |
|---|---|
| ComponentState | The state of the parent component. |
Methods
GetOrCreateRenderedComponent(Type)
Gets the or create rendered component.
Declaration
public IRenderedComponent<IComponent>? GetOrCreateRenderedComponent(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
Returns
| Type | Description |
|---|---|
| IRenderedComponent<IComponent> | System ofNullable<IRenderedComponent<IComponent>> of the or create rendered component. |
Remarks
This method understands both direct rendered-component state values and the fallback lookup path required by bUnit 2's renderer state dictionary.
GetOrCreateRenderedComponent<T>()
Gets the or create rendered component.
Declaration
public virtual IRenderedComponent<T>? GetOrCreateRenderedComponent<T>() where T : ComponentBase
Returns
| Type | Description |
|---|---|
| IRenderedComponent<T> | System ofNullable<IRenderedComponent<T>> of the or create rendered component. |
Type Parameters
| Name | Description |
|---|---|
| T | The component type. |
Examples
var state = GetAllComponents<FetchData>().First().Value as ComponentState<FetchData>;
var rendered = state?.GetOrCreateRenderedComponent<FetchData>();