Class BunitRenderer
Represents a bUnit BunitRenderer used to render Blazor components and fragments during bUnit tests.
public sealed class BunitRenderer : Renderer, IDisposable, IAsyncDisposable
- Inheritance
-
BunitRenderer
- Implements
- Inherited Members
- Extension Methods
Constructors
BunitRenderer(BunitServiceProvider, ILoggerFactory)
Initializes a new instance of the BunitRenderer class.
public BunitRenderer(BunitServiceProvider services, ILoggerFactory loggerFactory)
Parameters
servicesBunitServiceProviderloggerFactoryILoggerFactory
BunitRenderer(BunitServiceProvider, ILoggerFactory, IComponentActivator)
Initializes a new instance of the BunitRenderer class.
public BunitRenderer(BunitServiceProvider services, ILoggerFactory loggerFactory, IComponentActivator componentActivator)
Parameters
servicesBunitServiceProviderloggerFactoryILoggerFactorycomponentActivatorIComponentActivator
Properties
Dispatcher
Gets the Dispatcher associated with this Renderer.
public override Dispatcher Dispatcher { get; }
Property Value
RendererInfo
Gets the RendererInfo associated with this Renderer.
protected override RendererInfo RendererInfo { get; }
Property Value
UnhandledException
Gets a Task<TResult>, which completes when an unhandled exception is thrown during the rendering of a component, that is caught by the renderer.
public Task<Exception> UnhandledException { get; }
Property Value
Methods
AddPendingTask(ComponentState?, Task)
Notifies the renderer that there is a pending task associated with a component. The renderer is regarded as quiescent when all such tasks have completed.
protected override void AddPendingTask(ComponentState? componentState, Task task)
Parameters
componentStateComponentStateThe ComponentState for the component associated with this pending task, if any.
taskTaskThe Task.
CreateComponentState(int, IComponent, ComponentState?)
Creates a ComponentState instance to track state associated with a newly-instantiated component. This is called before the component is initialized and tracked within the Renderer. Subclasses may override this method to use their own subclasses of ComponentState.
protected override ComponentState CreateComponentState(int componentId, IComponent component, ComponentState? parentComponentState)
Parameters
componentIdintThe ID of the newly-created component.
componentIComponentThe component instance.
parentComponentStateComponentStateThe ComponentState associated with the parent component, or null if this is a root component.
Returns
- ComponentState
A ComponentState for the new component.
DispatchEventAsync(ulong, EventFieldInfo, EventArgs)
Notifies the renderer that an event has occurred.
public Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)
Parameters
eventHandlerIdulongThe AttributeEventHandlerId value from the original event attribute.
fieldInfoEventFieldInfoInformation that the renderer can use to update the state of the existing render tree to match the UI.
eventArgsEventArgsArguments to be passed to the event handler.
Returns
- Task
A Task which will complete once all asynchronous processing related to the event has completed.
DispatchEventAsync(ulong, EventFieldInfo, EventArgs, bool)
Notifies the renderer that an event has occurred.
public Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs, bool ignoreUnknownEventHandlers)
Parameters
eventHandlerIdulongThe AttributeEventHandlerId value from the original event attribute.
fieldInfoEventFieldInfoInformation that the renderer can use to update the state of the existing render tree to match the UI.
eventArgsEventArgsArguments to be passed to the event handler.
ignoreUnknownEventHandlersboolSet to true to ignore the UnknownEventHandlerIdException.
Returns
- Task
A Task which will complete once all asynchronous processing related to the event has completed.
Dispose(bool)
Releases all resources currently used by this Renderer instance.
protected override void Dispose(bool disposing)
Parameters
DisposeComponents()
Disposes all components rendered by the BunitRenderer.
public Task DisposeComponents()
Returns
FindComponent<TComponent>(IRenderedComponent<IComponent>)
Performs a depth-first search for the first TComponent child component of the parentComponent.
public IRenderedComponent<TComponent> FindComponent<TComponent>(IRenderedComponent<IComponent> parentComponent) where TComponent : IComponent
Parameters
parentComponentIRenderedComponent<IComponent>Parent component to search.
Returns
- IRenderedComponent<TComponent>
Type Parameters
TComponentType of component to find.
FindComponents<TComponent>(IRenderedComponent<IComponent>)
Performs a depth-first search for all TComponent child components of the parentComponent.
public IReadOnlyList<IRenderedComponent<TComponent>> FindComponents<TComponent>(IRenderedComponent<IComponent> parentComponent) where TComponent : IComponent
Parameters
parentComponentIRenderedComponent<IComponent>Parent component to search.
Returns
- IReadOnlyList<IRenderedComponent<TComponent>>
Type Parameters
TComponentType of components to find.
GetComponentRenderMode(IComponent)
Gets the IComponentRenderMode for a given component if available.
protected override IComponentRenderMode? GetComponentRenderMode(IComponent component)
Parameters
componentIComponentThe component type
Returns
HandleException(Exception)
Allows derived types to handle exceptions during rendering. Defaults to rethrowing the original exception.
protected override void HandleException(Exception exception)
Parameters
ProcessPendingRender()
Processes pending renders requests from components if there are any.
protected override void ProcessPendingRender()
RenderFragment(RenderFragment)
Renders the renderFragment.
public IRenderedComponent<IComponent> RenderFragment(RenderFragment renderFragment)
Parameters
renderFragmentRenderFragmentThe RenderFragment to render.
Returns
- IRenderedComponent<IComponent>
A IRenderedComponent<TComponent> that provides access to the rendered
renderFragment.
Render<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>?)
Renders a TComponent with the parameters build with the parameterBuilder passed to it.
public IRenderedComponent<TComponent> Render<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>? parameterBuilder = null) where TComponent : IComponent
Parameters
parameterBuilderAction<ComponentParameterCollectionBuilder<TComponent>>The a builder to create parameters to pass to the component.
Returns
- IRenderedComponent<TComponent>
A RenderedComponent<TComponent> that provides access to the rendered component.
Type Parameters
TComponentThe type of component to render.
ResolveComponentForRenderMode(Type, int?, IComponentActivator, IComponentRenderMode)
Determines how to handle an IComponentRenderMode when obtaining a component instance. This is only called when a render mode is specified either at the call site or on the component type.
Subclasses may override this method to return a component of a different type, or throw, depending on whether the renderer supports the render mode and how it implements that support.
protected override IComponent ResolveComponentForRenderMode(Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode)
Parameters
componentTypeTypeThe type of component that was requested.
parentComponentIdint?The parent component ID, or null if it is a root component.
componentActivatorIComponentActivatorAn IComponentActivator that should be used when instantiating component objects.
renderModeIComponentRenderModeThe IComponentRenderMode declared on
componentTypeor at the call site (for example, by the parent component).
Returns
- IComponent
An IComponent instance.
SetRendererInfo(RendererInfo?)
public void SetRendererInfo(RendererInfo? rendererInfo)
Parameters
rendererInfoRendererInfo
UpdateDisplayAsync(in RenderBatch)
Updates the visible UI.
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
Parameters
renderBatchRenderBatchThe changes to the UI since the previous call.