Class TestRenderer
Represents a bUnit ITestRenderer used to render Blazor components and fragments during bUnit tests.
public class TestRenderer : Renderer, IDisposable, IAsyncDisposable, ITestRenderer- Inheritance
- 
      
      
      TestRenderer
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
TestRenderer(IRenderedComponentActivator, TestServiceProvider, ILoggerFactory)
Initializes a new instance of the TestRenderer class.
public TestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory)Parameters
- renderedComponentActivatorIRenderedComponentActivator
- servicesTestServiceProvider
- loggerFactoryILoggerFactory
TestRenderer(IRenderedComponentActivator, TestServiceProvider, ILoggerFactory, IComponentActivator)
Initializes a new instance of the TestRenderer class.
public TestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory, IComponentActivator componentActivator)Parameters
- renderedComponentActivatorIRenderedComponentActivator
- servicesTestServiceProvider
- loggerFactoryILoggerFactory
- componentActivatorIComponentActivator
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
DispatchEventAsync(ulong, EventFieldInfo, EventArgs)
Notifies the renderer that an event has occurred.
public Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)Parameters
- eventHandlerIdulong
- The AttributeEventHandlerId value from the original event attribute. 
- fieldInfoEventFieldInfo
- Information that the renderer can use to update the state of the existing render tree to match the UI. 
- eventArgsEventArgs
- Arguments 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
- eventHandlerIdulong
- The AttributeEventHandlerId value from the original event attribute. 
- fieldInfoEventFieldInfo
- Information that the renderer can use to update the state of the existing render tree to match the UI. 
- eventArgsEventArgs
- Arguments to be passed to the event handler. 
- ignoreUnknownEventHandlersbool
- Set 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 ITestRenderer.
public void DisposeComponents()FindComponent<TComponent>(IRenderedFragmentBase)
Performs a depth-first search for the first TComponent child component of the parentComponent.
public IRenderedComponentBase<TComponent> FindComponent<TComponent>(IRenderedFragmentBase parentComponent) where TComponent : IComponentParameters
- parentComponentIRenderedFragmentBase
- Parent component to search. 
Returns
- IRenderedComponentBase<TComponent>
Type Parameters
- TComponent
- Type of component to find. 
FindComponents<TComponent>(IRenderedFragmentBase)
Performs a depth-first search for all TComponent child components of the parentComponent.
public IReadOnlyList<IRenderedComponentBase<TComponent>> FindComponents<TComponent>(IRenderedFragmentBase parentComponent) where TComponent : IComponentParameters
- parentComponentIRenderedFragmentBase
- Parent component to search. 
Returns
- IReadOnlyList<IRenderedComponentBase<TComponent>>
Type Parameters
- TComponent
- Type of components to find. 
GetComponentRenderMode(IComponent)
Gets the IComponentRenderMode for a given component if available.
protected override IComponentRenderMode? GetComponentRenderMode(IComponent component)Parameters
- componentIComponent
- The 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()RenderComponent<TComponent>(ComponentParameterCollection)
Renders a TComponent with the parameters passed to it.
public IRenderedComponentBase<TComponent> RenderComponent<TComponent>(ComponentParameterCollection parameters) where TComponent : IComponentParameters
- parametersComponentParameterCollection
- The parameters to pass to the component. 
Returns
- IRenderedComponentBase<TComponent>
- A IRenderedComponentBase<TComponent> that provides access to the rendered component. 
Type Parameters
- TComponent
- The type of component to render. 
RenderFragment(RenderFragment)
Renders the renderFragment.
public IRenderedFragmentBase RenderFragment(RenderFragment renderFragment)Parameters
- renderFragmentRenderFragment
- The RenderFragment to render. 
Returns
- IRenderedFragmentBase
- A IRenderedFragmentBase that provides access to the rendered - renderFragment.
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
- componentTypeType
- The type of component that was requested. 
- parentComponentIdint?
- The parent component ID, or null if it is a root component. 
- componentActivatorIComponentActivator
- An IComponentActivator that should be used when instantiating component objects. 
- renderModeIComponentRenderMode
- The IComponentRenderMode declared on - componentTypeor at the call site (for example, by the parent component).
Returns
- IComponent
- An IComponent instance. 
SetRendererInfo(RendererInfo?)
Sets the RendererInfo for the renderer.
public void SetRendererInfo(RendererInfo? rendererInfo)Parameters
- rendererInfoRendererInfo
UpdateDisplayAsync(in RenderBatch)
Updates the visible UI.
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)Parameters
- renderBatchRenderBatch
- The changes to the UI since the previous call.