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
renderedComponentActivator
IRenderedComponentActivatorservices
TestServiceProviderloggerFactory
ILoggerFactory
TestRenderer(IRenderedComponentActivator, TestServiceProvider, ILoggerFactory, IComponentActivator)
Initializes a new instance of the TestRenderer class.
public TestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory, IComponentActivator componentActivator)
Parameters
renderedComponentActivator
IRenderedComponentActivatorservices
TestServiceProviderloggerFactory
ILoggerFactorycomponentActivator
IComponentActivator
Properties
Dispatcher
public override Dispatcher Dispatcher { 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
eventHandlerId
ulongThe AttributeEventHandlerId value from the original event attribute.
fieldInfo
EventFieldInfoInformation that the renderer can use to update the state of the existing render tree to match the UI.
eventArgs
EventArgsArguments 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
eventHandlerId
ulongThe AttributeEventHandlerId value from the original event attribute.
fieldInfo
EventFieldInfoInformation that the renderer can use to update the state of the existing render tree to match the UI.
eventArgs
EventArgsArguments to be passed to the event handler.
ignoreUnknownEventHandlers
boolSet 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)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
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 : IComponent
Parameters
parentComponent
IRenderedFragmentBaseParent 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 : IComponent
Parameters
parentComponent
IRenderedFragmentBaseParent component to search.
Returns
- IReadOnlyList<IRenderedComponentBase<TComponent>>
Type Parameters
TComponent
Type of components to find.
HandleException(Exception)
protected override void HandleException(Exception exception)
Parameters
exception
Exception
ProcessPendingRender()
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 : IComponent
Parameters
parameters
ComponentParameterCollectionThe 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
renderFragment
RenderFragmentThe RenderFragment to render.
Returns
- IRenderedFragmentBase
A IRenderedFragmentBase that provides access to the rendered
renderFragment
.
ResolveComponentForRenderMode(Type, int?, IComponentActivator, IComponentRenderMode)
protected override IComponent ResolveComponentForRenderMode(Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode)
Parameters
componentType
TypeparentComponentId
int?componentActivator
IComponentActivatorrenderMode
IComponentRenderMode
Returns
UpdateDisplayAsync(in RenderBatch)
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
Parameters
renderBatch
RenderBatch