-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathByTextElementFactory.cs
More file actions
31 lines (24 loc) · 935 Bytes
/
ByTextElementFactory.cs
File metadata and controls
31 lines (24 loc) · 935 Bytes
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
using AngleSharp.Dom;
using Bunit.Web.AngleSharp;
namespace Bunit;
internal sealed class ByTextElementFactory : IElementWrapperFactory
{
private readonly IRenderedComponent<IComponent> testTarget;
private readonly string searchText;
private readonly ByTextOptions options;
public Action? OnElementReplaced { get; set; }
public ByTextElementFactory(IRenderedComponent<IComponent> testTarget, string searchText, ByTextOptions options)
{
this.testTarget = testTarget;
this.searchText = searchText;
this.options = options;
testTarget.OnMarkupUpdated += FragmentsMarkupUpdated;
}
private void FragmentsMarkupUpdated(object? sender, EventArgs args)
=> OnElementReplaced?.Invoke();
public TElement GetElement<TElement>() where TElement : class, IElement
{
var element = testTarget.FindByTextInternal(searchText, options) as TElement;
return element ?? throw new ElementRemovedFromDomException(searchText);
}
}