Class RenderedFragmentWaitForHelperExtensions
- Namespace
- Bunit
- Assembly
- Bunit.Core.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
renderedFragmentIRenderedFragmentBaseThe rendered fragment to wait for renders from and assert against.
assertionActionThe verification or assertion to perform.
timeoutTimeSpan?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
renderedFragmentIRenderedFragmentThe render fragment or component find the matching element in.
cssSelectorstringThe 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
cssSelectorwithin 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
renderedFragmentIRenderedFragmentThe render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for the element.
timeoutTimeSpanThe 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
cssSelectorwithin 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
renderedFragmentIRenderedFragmentThe render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin 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
renderedFragmentIRenderedFragmentThe render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
matchElementCountintThe exact number of elements to that the
cssSelectorshould match.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin 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
renderedFragmentIRenderedFragmentThe render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
matchElementCountintThe exact number of elements to that the
cssSelectorshould match.timeoutTimeSpanThe maximum time to wait for elements to appear.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin 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
renderedFragmentIRenderedFragmentThe render fragment or component find the matching element in.
cssSelectorstringThe CSS selector to use to search for elements.
timeoutTimeSpanThe maximum time to wait for elements to appear.
Returns
- IRefreshableElementCollection<IElement>
Exceptions
- WaitForFailedException
Thrown if no elements is found matching the
cssSelectorwithin 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
renderedFragmentIRenderedFragmentBaseThe render fragment or component to attempt to verify state against.
statePredicateFunc<bool>The predicate to invoke after each render, which must returns
truewhen the desired state has been reached.timeoutTimeSpan?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
statePredicatethrow an exception during invocation, or if the timeout has been reached. See the inner exception for details.