-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathRenderedComponentInvokeAsyncExtension.cs
More file actions
44 lines (40 loc) · 1.79 KB
/
RenderedComponentInvokeAsyncExtension.cs
File metadata and controls
44 lines (40 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Text;
using System.Threading.Tasks;
using Bunit.Rendering;
using Microsoft.AspNetCore.Components;
namespace Bunit
{
/// <summary>
/// InvokeAsync extensions methods on <see cref="IRenderedComponentBase{TComponent}"/>.
/// </summary>
public static class RenderedComponentInvokeAsyncExtensions
{
/// <summary>
/// Invokes the given <paramref name="callback"/> in the context of the associated <see cref="ITestRenderer"/>.
/// </summary>
/// <param name="renderedComponent">The rendered component whose dispatcher to invoke with.</param>
/// <param name="callback"></param>
/// <returns>A <see cref="Task"/> that will be completed when the action has finished executing or is suspended by an asynchronous operation.</returns>
public static Task InvokeAsync<TComponent>(this IRenderedComponentBase<TComponent> renderedComponent, Action callback)
where TComponent : IComponent
{
if (renderedComponent is null)
throw new ArgumentNullException(nameof(renderedComponent));
return renderedComponent.Renderer.Dispatcher.InvokeAsync(callback);
}
/// <summary>
/// Invokes the given <paramref name="callback"/> in the context of the associated <see cref="ITestRenderer"/>.
/// </summary>
/// <param name="renderedComponent">The rendered component whose dispatcher to invoke with.</param>
/// <param name="callback"></param>
/// <returns>A <see cref="Task"/> that will be completed when the action has finished executing.</returns>
public static Task InvokeAsync<TComponent>(this IRenderedComponentBase<TComponent> renderedComponent, Func<Task> callback)
where TComponent : IComponent
{
if (renderedComponent is null)
throw new ArgumentNullException(nameof(renderedComponent));
return renderedComponent.Renderer.Dispatcher.InvokeAsync(callback);
}
}
}