66namespace Bunit . Rendering ;
77
88/// <summary>
9- /// Represents a bUnit <see cref="TestRenderer "/> used to render Blazor components and fragments during bUnit tests.
9+ /// Represents a bUnit <see cref="BunitRenderer "/> used to render Blazor components and fragments during bUnit tests.
1010/// </summary>
11- public sealed class TestRenderer : Renderer
11+ public sealed class BunitRenderer : Renderer
1212{
1313 [ UnsafeAccessor ( UnsafeAccessorKind . Field , Name = "_isBatchInProgress" ) ]
14- extern static ref bool GetIsBatchInProgressField ( Renderer renderer ) ;
14+ private static extern ref bool GetIsBatchInProgressField ( Renderer renderer ) ;
1515
1616 [ UnsafeAccessor ( UnsafeAccessorKind . Method , Name = "SetDirectParameters" ) ]
17- extern static void CallSetDirectParameters ( ComponentState componentState , ParameterView parameters ) ;
17+ private static extern void CallSetDirectParameters ( ComponentState componentState , ParameterView parameters ) ;
1818
1919 private readonly object renderTreeUpdateLock = new ( ) ;
2020 private readonly Dictionary < int , RenderedFragment > renderedComponents = new ( ) ;
2121 private readonly List < RootComponent > rootComponents = new ( ) ;
22- private readonly ILogger < TestRenderer > logger ;
22+ private readonly ILogger < BunitRenderer > logger ;
2323 private readonly IRenderedComponentActivator activator ;
2424 private bool disposed ;
2525 private TaskCompletionSource < Exception > unhandledExceptionTsc = new ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
@@ -39,7 +39,10 @@ private bool IsBatchInProgress
3939 }
4040 }
4141
42- /// <inheritdoc/>
42+ /// <summary>
43+ /// Gets a <see cref="Task{Exception}"/>, which completes when an unhandled exception
44+ /// is thrown during the rendering of a component, that is caught by the renderer.
45+ /// </summary>
4346 public Task < Exception > UnhandledException => unhandledExceptionTsc . Task ;
4447
4548 /// <inheritdoc/>
@@ -51,32 +54,41 @@ private bool IsBatchInProgress
5154 internal int RenderCount { get ; private set ; }
5255
5356 /// <summary>
54- /// Initializes a new instance of the <see cref="TestRenderer "/> class.
57+ /// Initializes a new instance of the <see cref="BunitRenderer "/> class.
5558 /// </summary>
56- public TestRenderer ( IRenderedComponentActivator renderedComponentActivator , TestServiceProvider services , ILoggerFactory loggerFactory )
59+ public BunitRenderer ( IRenderedComponentActivator renderedComponentActivator , TestServiceProvider services , ILoggerFactory loggerFactory )
5760 : base ( services , loggerFactory , new BunitComponentActivator ( services . GetRequiredService < ComponentFactoryCollection > ( ) , null ) )
5861 {
59- logger = loggerFactory . CreateLogger < TestRenderer > ( ) ;
62+ logger = loggerFactory . CreateLogger < BunitRenderer > ( ) ;
6063 activator = renderedComponentActivator ;
6164 ElementReferenceContext = new WebElementReferenceContext ( services . GetRequiredService < IJSRuntime > ( ) ) ;
6265 }
6366
6467 /// <summary>
65- /// Initializes a new instance of the <see cref="TestRenderer "/> class.
68+ /// Initializes a new instance of the <see cref="BunitRenderer "/> class.
6669 /// </summary>
67- public TestRenderer ( IRenderedComponentActivator renderedComponentActivator , TestServiceProvider services , ILoggerFactory loggerFactory , IComponentActivator componentActivator )
70+ public BunitRenderer ( IRenderedComponentActivator renderedComponentActivator , TestServiceProvider services , ILoggerFactory loggerFactory , IComponentActivator componentActivator )
6871 : base ( services , loggerFactory , new BunitComponentActivator ( services . GetRequiredService < ComponentFactoryCollection > ( ) , componentActivator ) )
6972 {
70- logger = loggerFactory . CreateLogger < TestRenderer > ( ) ;
73+ logger = loggerFactory . CreateLogger < BunitRenderer > ( ) ;
7174 activator = renderedComponentActivator ;
7275 ElementReferenceContext = new WebElementReferenceContext ( services . GetRequiredService < IJSRuntime > ( ) ) ;
7376 }
7477
75- /// <inheritdoc/>
78+ /// <summary>
79+ /// Renders the <paramref name="renderFragment"/>.
80+ /// </summary>
81+ /// <param name="renderFragment">The <see cref="Microsoft.AspNetCore.Components.RenderFragment"/> to render.</param>
82+ /// <returns>A <see cref="RenderedFragment"/> that provides access to the rendered <paramref name="renderFragment"/>.</returns>
7683 public RenderedFragment RenderFragment ( RenderFragment renderFragment )
7784 => Render ( renderFragment , id => activator . CreateRenderedFragment ( id ) ) ;
7885
79- /// <inheritdoc/>
86+ /// <summary>
87+ /// Renders a <typeparamref name="TComponent"/> with the <paramref name="parameters"/> passed to it.
88+ /// </summary>
89+ /// <typeparam name="TComponent">The type of component to render.</typeparam>
90+ /// <param name="parameters">The parameters to pass to the component.</param>
91+ /// <returns>A <see cref="RenderedComponent{TComponent}"/> that provides access to the rendered component.</returns>
8092 public RenderedComponent < TComponent > RenderComponent < TComponent > ( ComponentParameterCollection parameters )
8193 where TComponent : IComponent
8294 {
@@ -86,14 +98,26 @@ public RenderedComponent<TComponent> RenderComponent<TComponent>(ComponentParame
8698 return Render ( renderFragment , id => activator . CreateRenderedComponent < TComponent > ( id ) ) ;
8799 }
88100
89- /// <inheritdoc/>
101+ /// <summary>
102+ /// Notifies the renderer that an event has occurred.
103+ /// </summary>
104+ /// <param name="eventHandlerId">The <see cref="RenderTreeFrame.AttributeEventHandlerId"/> value from the original event attribute.</param>
105+ /// <param name="fieldInfo">Information that the renderer can use to update the state of the existing render tree to match the UI.</param>
106+ /// <param name="eventArgs">Arguments to be passed to the event handler.</param>
107+ /// <returns>A <see cref="Task"/> which will complete once all asynchronous processing related to the event has completed.</returns>
90108 public new Task DispatchEventAsync (
91109 ulong eventHandlerId ,
92110 EventFieldInfo fieldInfo ,
93111 EventArgs eventArgs ) => DispatchEventAsync ( eventHandlerId , fieldInfo , eventArgs , ignoreUnknownEventHandlers : false ) ;
94112
95- /// <exception cref="ObjectDisposedException"></exception>
96- /// <inheritdoc/>
113+ /// <summary>
114+ /// Notifies the renderer that an event has occurred.
115+ /// </summary>
116+ /// <param name="eventHandlerId">The <see cref="RenderTreeFrame.AttributeEventHandlerId"/> value from the original event attribute.</param>
117+ /// <param name="fieldInfo">Information that the renderer can use to update the state of the existing render tree to match the UI.</param>
118+ /// <param name="eventArgs">Arguments to be passed to the event handler.</param>
119+ /// <param name="ignoreUnknownEventHandlers">Set to true to ignore the <see cref="UnknownEventHandlerIdException"/>.</param>
120+ /// <returns>A <see cref="Task"/> which will complete once all asynchronous processing related to the event has completed.</returns>
97121 public new Task DispatchEventAsync (
98122 ulong eventHandlerId ,
99123 EventFieldInfo fieldInfo ,
@@ -142,7 +166,11 @@ public RenderedComponent<TComponent> RenderComponent<TComponent>(ComponentParame
142166 }
143167 }
144168
145- /// <inheritdoc/>
169+ /// <summary>
170+ /// Performs a depth-first search for the first <typeparamref name="TComponent"/> child component of the <paramref name="parentComponent"/>.
171+ /// </summary>
172+ /// <typeparam name="TComponent">Type of component to find.</typeparam>
173+ /// <param name="parentComponent">Parent component to search.</param>
146174 public RenderedComponent < TComponent > FindComponent < TComponent > ( RenderedFragment parentComponent )
147175 where TComponent : IComponent
148176 {
@@ -152,12 +180,18 @@ public RenderedComponent<TComponent> FindComponent<TComponent>(RenderedFragment
152180 : throw new ComponentNotFoundException ( typeof ( TComponent ) ) ;
153181 }
154182
155- /// <inheritdoc/>
183+ /// <summary>
184+ /// Performs a depth-first search for all <typeparamref name="TComponent"/> child components of the <paramref name="parentComponent"/>.
185+ /// </summary>
186+ /// <typeparam name="TComponent">Type of components to find.</typeparam>
187+ /// <param name="parentComponent">Parent component to search.</param>
156188 public IReadOnlyList < RenderedComponent < TComponent > > FindComponents < TComponent > ( RenderedFragment parentComponent )
157189 where TComponent : IComponent
158190 => FindComponents < TComponent > ( parentComponent , int . MaxValue ) ;
159191
160- /// <inheritdoc />
192+ /// <summary>
193+ /// Disposes all components rendered by the <see cref="BunitRenderer" />.
194+ /// </summary>
161195 public void DisposeComponents ( )
162196 {
163197 ObjectDisposedException . ThrowIf ( disposed , this ) ;
@@ -225,7 +259,7 @@ internal Task SetDirectParametersAsync(RenderedFragment renderedComponent, Param
225259
226260 return result ;
227261
228- static void SetDirectParametersViaComponentState ( TestRenderer renderer , int componentId , in ParameterView parameters )
262+ static void SetDirectParametersViaComponentState ( BunitRenderer renderer , int componentId , in ParameterView parameters )
229263 {
230264 var componentState = renderer . GetComponentState ( componentId ) ;
231265 CallSetDirectParameters ( componentState , parameters ) ;
@@ -534,8 +568,10 @@ private ArrayRange<RenderTreeFrame> GetOrLoadRenderTreeFrame(RenderTreeFrameDict
534568 }
535569
536570 /// <inheritdoc/>
537- protected override void HandleException ( [ NotNull ] Exception exception )
571+ protected override void HandleException ( Exception exception )
538572 {
573+ ArgumentNullException . ThrowIfNull ( exception ) ;
574+
539575 if ( disposed )
540576 return ;
541577
0 commit comments