Class RenderedFragmentWaitForHelperExtensions
- Namespace
- Bunit
- Assembly
- Bunit.Web.dll
Helper methods dealing with async rendering during testing.
public static class RenderedFragmentWaitForHelperExtensions
- Inheritance
-
RenderedFragmentWaitForHelperExtensions
- Inherited Members
Methods
WaitForAssertion(IRenderedFragmentBase, Action, TimeSpan?)
Wait until the provided assertion
passes (i.e. does not throw an
exception), or the timeout
is reached (default is one second).
The assertion
is attempted initially, and then each time the renderedFragment
renders.
[AssertionMethod]
public static void WaitForAssertion(this IRenderedFragmentBase renderedFragment, Action assertion, TimeSpan? timeout = null)
Parameters
renderedFragment
IRenderedFragmentBaseThe rendered fragment to wait for renders from and assert against.
assertion
ActionThe verification or assertion to perform.
timeout
TimeSpan?The maximum time to attempt the verification.
Exceptions
- WaitForFailedException
Thrown if the timeout has been reached. See the inner exception to see the captured assertion exception.
WaitForElement(IRenderedFragment, string)
Wait until an element matching the cssSelector
exists in the renderedFragment
,
or the timeout is reached (default is one second).
public static IElement WaitForElement(this IRenderedFragment renderedFragment, string cssSelector)
Parameters
renderedFragment
IRenderedFragmentThe render fragment or component find the matching element in.
cssSelector
stringThe CSS selector to use to search for the element.
Returns
- IElement
The AngleSharp.Dom.IElement.
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelector
within the default timeout. See the inner exception for details.
WaitForElement(IRenderedFragment, string, TimeSpan)
Wait until an element matching the cssSelector
exists in the renderedFragment
,
or the timeout
is reached.
public static IElement WaitForElement(this IRenderedFragment renderedFragment, string cssSelector, TimeSpan timeout)
Parameters
renderedFragment
IRenderedFragmentThe render fragment or component find the matching element in.
cssSelector
stringThe CSS selector to use to search for the element.
timeout
TimeSpanThe maximum time to wait for the element to appear.
Returns
- IElement
The AngleSharp.Dom.IElement.
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelector
within the default timeout. See the inner exception for details.
WaitForElements(IRenderedFragment, string)
Wait until at least one element matching the cssSelector
exists in the renderedFragment
,
or the timeout is reached (default is one second).
public static IRefreshableElementCollection<IElement> WaitForElements(this IRenderedFragment renderedFragment, string cssSelector)
Parameters
renderedFragment
IRenderedFragmentThe render fragment or component find the matching element in.
cssSelector
stringThe CSS selector to use to search for elements.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelector
within the default timeout.
WaitForElements(IRenderedFragment, string, int)
Wait until exactly matchElementCount
element(s) matching the cssSelector
exists in the renderedFragment
,
or the timeout is reached (default is one second).
public static IRefreshableElementCollection<IElement> WaitForElements(this IRenderedFragment renderedFragment, string cssSelector, int matchElementCount)
Parameters
renderedFragment
IRenderedFragmentThe render fragment or component find the matching element in.
cssSelector
stringThe CSS selector to use to search for elements.
matchElementCount
intThe exact number of elements to that the
cssSelector
should match.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelector
within the default timeout.
WaitForElements(IRenderedFragment, string, int, TimeSpan)
Wait until exactly matchElementCount
element(s) matching the cssSelector
exists in the renderedFragment
,
or the timeout
is reached.
public static IRefreshableElementCollection<IElement> WaitForElements(this IRenderedFragment renderedFragment, string cssSelector, int matchElementCount, TimeSpan timeout)
Parameters
renderedFragment
IRenderedFragmentThe render fragment or component find the matching element in.
cssSelector
stringThe CSS selector to use to search for elements.
matchElementCount
intThe exact number of elements to that the
cssSelector
should match.timeout
TimeSpanThe maximum time to wait for elements to appear.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelector
within the default timeout.
WaitForElements(IRenderedFragment, string, TimeSpan)
Wait until at least one element matching the cssSelector
exists in the renderedFragment
,
or the timeout
is reached.
public static IRefreshableElementCollection<IElement> WaitForElements(this IRenderedFragment renderedFragment, string cssSelector, TimeSpan timeout)
Parameters
renderedFragment
IRenderedFragmentThe render fragment or component find the matching element in.
cssSelector
stringThe CSS selector to use to search for elements.
timeout
TimeSpanThe maximum time to wait for elements to appear.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelector
within the default timeout.
WaitForState(IRenderedFragmentBase, Func<bool>, TimeSpan?)
Wait until the provided statePredicate
action returns true,
or the timeout
is reached (default is one second).
The statePredicate
is evaluated initially, and then each time
the renderedFragment
renders.
public static void WaitForState(this IRenderedFragmentBase renderedFragment, Func<bool> statePredicate, TimeSpan? timeout = null)
Parameters
renderedFragment
IRenderedFragmentBaseThe render fragment or component to attempt to verify state against.
statePredicate
Func<bool>The predicate to invoke after each render, which must returns
true
when the desired state has been reached.timeout
TimeSpan?The maximum time to wait for the desired state.
Remarks
If a debugger is attached the timeout is set to InfiniteTimeSpan, giving the possibility to debug without the timeout triggering.
Exceptions
- WaitForFailedException
Thrown if the
statePredicate
throw an exception during invocation, or if the timeout has been reached. See the inner exception for details.