FastMoq
Search Results for

    Show / Hide Table of Contents

    Class MockerBlazorTestBase<T>

    Base class for bUnit component tests that integrates FastMoq auto-mocking, service setup, and helper methods for Blazor interaction.

    Inheritance
    object
    TestContextBase
    TestContext
    MockerBlazorTestBase<T>
    Implements
    IDisposable
    IMockerBlazorTestHelpers<T>
    Inherited Members
    TestContext.RenderComponent<TComponent>(params ComponentParameter[])
    TestContext.RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>>)
    TestContext.Render<TComponent>(RenderFragment)
    TestContext.Render(RenderFragment)
    TestContext.BuildRenderTree(RenderTreeBuilder)
    TestContext.CreateTestRenderer()
    TestContext.JSInterop
    TestContextBase.Dispose()
    TestContextBase.DisposeComponents()
    TestContextBase.DefaultWaitTimeout
    TestContextBase.Renderer
    TestContextBase.Services
    TestContextBase.RenderTree
    TestContextBase.ComponentFactories
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastMoq.Web.Blazor
    Assembly: FastMoq.Web.dll
    Syntax
    public abstract class MockerBlazorTestBase<T> : TestContext, IDisposable, IMockerBlazorTestHelpers<T> where T : ComponentBase
    Type Parameters
    Name Description
    T

    The Blazor component under test.

    Examples

    Start with a realistic page-level test that configures services, mocks, and assertions in one place.

    public class OrdersPageTests : MockerBlazorTestBase<OrdersPage>
    {
        protected override Action<TestServiceProvider, IConfiguration, Mocker> ConfigureServices => (services, _, _) =>
            services.AddSingleton<IClock>(new FixedClock(new DateTimeOffset(2026, 4, 4, 12, 0, 0, TimeSpan.Zero)));
    
    protected override Action<Mocker> SetupComponent => mocker =>
    {
        mocker.GetOrCreateMock<IOrdersClient>()
            .Setup(x => x.GetOpenOrdersAsync())
            .ReturnsAsync(new[]
            {
                new OrderSummary { Id = 42, CustomerName = "Contoso", Total = 125.50m }
            });
    };
    
    [Fact]
    public void LoadsOpenOrdersOnFirstRender()
    {
        Component.Markup.Should().Contain("Contoso");
        Mocks.Verify<IOrdersClient>(x => x.GetOpenOrdersAsync(), TimesSpec.Once);
    }
    

    }

    Use authorization and navigation helpers together when a component renders actions conditionally.

    protected override MockerObservableCollection<string> AuthorizedRoles => new() { "Orders.Read", "Orders.Submit" };
    

    [Fact] public void ClickingSubmitNavigatesToReview() { ClickButton("button[type='submit']", () => NavigationManager.History.Count == 1);

    NavigationManager.Uri.Should().Contain("/orders/review");
    

    }

    Constructors

    MockerBlazorTestBase()

    Initializes a new instance of the Bunit.TestContext class.

    Declaration
    protected MockerBlazorTestBase()

    MockerBlazorTestBase(bool, InvocationMatcher?, bool)

    Initializes a new instance of the MockerBlazorTestBase<T> class.

    Declaration
    protected MockerBlazorTestBase(bool skipSetup, InvocationMatcher? jsInvocationMatcher = null, bool isCatchAllMatcher = false)
    Parameters
    Type Name Description
    bool skipSetup

    if set to true [skip setup].

    InvocationMatcher jsInvocationMatcher

    Optional invocation matcher for JSInterop.

    bool isCatchAllMatcher

    Indicates if the invocationMatches is also a catch-all.

    Properties

    AuthContext

    Gets the authentication context.

    Declaration
    protected TestAuthorizationContext AuthContext { get; }
    Property Value
    Type Description
    TestAuthorizationContext

    The authentication context.

    Examples

    Set not authorized.

    AuthContext.SetNotAuthorized()

    Set authorized user.

    AuthContext.SetAuthorized("username")
    See Also
    AuthorizedClaims
    AuthorizedPolicies
    AuthorizedRoles
    AuthUsername

    AuthUsername

    Gets or sets the authentication username.

    Declaration
    [ExcludeFromCodeCoverage]
    protected virtual string AuthUsername { get; set; }
    Property Value
    Type Description
    string

    The authentication username.

    Examples

    Set authorized user.

    AuthContext.SetAuthorized("username")
    AuthUsername = "TestUser";
    See Also
    AuthorizedClaims
    AuthorizedPolicies
    AuthorizedRoles
    AuthContext
    AuthUsername

    AuthorizedClaims

    Gets the authorized claims.

    Declaration
    protected virtual MockerObservableCollection<Claim> AuthorizedClaims { get; }
    Property Value
    Type Description
    MockerObservableCollection<Claim>

    The authorized claims.

    See Also
    AuthorizedPolicies
    AuthorizedRoles
    AuthContext
    AuthUsername

    AuthorizedPolicies

    Gets the authorized policies.

    Declaration
    protected virtual MockerObservableCollection<string> AuthorizedPolicies { get; }
    Property Value
    Type Description
    MockerObservableCollection<string>

    The authorized policies.

    Examples

    Setup Policies.

    protected override MockerObservableCollection<string> AuthorizedPolicies => new MockerObservableCollection<string>() { "Policy1", "Policy2"}
    See Also
    AuthorizedClaims
    AuthorizedRoles
    AuthContext
    AuthUsername

    AuthorizedRoles

    Gets the authorized roles.

    Declaration
    protected virtual MockerObservableCollection<string> AuthorizedRoles { get; }
    Property Value
    Type Description
    MockerObservableCollection<string>

    The authorized roles.

    Examples

    Setup Roles.

    protected override MockerObservableCollection<string> AuthorizedRoles => new MockerObservableCollection<string>() { "Role1", "Role2"}
    See Also
    AuthorizedPolicies
    AuthorizedClaims
    AuthContext
    AuthUsername

    Component

    Gets or sets the component under test.

    Declaration
    protected IRenderedComponent<T>? Component { get; set; }
    Property Value
    Type Description
    IRenderedComponent<T>

    The component under test.

    ConfigureServices

    Gets the configure services.

    Declaration
    [ExcludeFromCodeCoverage]
    protected virtual Action<TestServiceProvider, IConfiguration, Mocker> ConfigureServices { get; set; }
    Property Value
    Type Description
    Action<TestServiceProvider, IConfiguration, Mocker>

    The configure services.

    Examples

    Setup Services.

    protected override Action<TestServiceProvider, IConfiguration, Mocker> ConfigureServices => (services, c, m) => services.AddSingleton<IWeatherForecastService, WeatherForecastService>();

    Instance

    Gets the instance.

    Declaration
    protected T? Instance { get; }
    Property Value
    Type Description
    T

    The instance.

    Mocks

    Gets the mock controller.

    Declaration
    protected Mocker Mocks { get; }
    Property Value
    Type Description
    Mocker

    The mocks controller.

    See Also
    Mocker

    NavigationManager

    Gets the navigation manager.

    Declaration
    protected FakeNavigationManager NavigationManager { get; }
    Property Value
    Type Description
    FakeNavigationManager

    The navigation manager.

    Examples

    Click Button by class, tag, or id and check the navigation manager for changes.

    NavigationManager.History.Count.Should().Be(2);

    RenderParameters

    Gets the list of parameters used when rendering. This is used to setup a component before the test constructor runs.

    Declaration
    [ExcludeFromCodeCoverage]
    protected virtual List<ComponentParameter> RenderParameters { get; }
    Property Value
    Type Description
    List<ComponentParameter>

    The render parameters.

    SetupComponent

    Gets or sets the setup component action. This is used to setup a component before the test constructor runs.

    Declaration
    [ExcludeFromCodeCoverage]
    protected virtual Action<Mocker> SetupComponent { get; set; }
    Property Value
    Type Description
    Action<Mocker>

    The setup component.

    TokenSource

    Gets the token source.

    Declaration
    protected CancellationTokenSource TokenSource { get; }
    Property Value
    Type Description
    CancellationTokenSource

    The token source.

    Methods

    ClickButton(IElement, Func<bool>, TimeSpan?)

    Clicks the button element.

    Declaration
    public IMockerBlazorTestHelpers<T> ClickButton(IElement button, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    IElement button

    The button.

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    ClickButton(Func<IElement, bool>, Func<bool>, TimeSpan?)

    Clicks the button element.

    Declaration
    public IMockerBlazorTestHelpers<T> ClickButton(Func<IElement, bool> cssSelector, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    Func<IElement, bool> cssSelector

    The CSS selector.

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Exceptions
    Type Condition
    ArgumentNullException

    cssSelector

    ClickButton(string, Func<bool>, TimeSpan?)

    Clicks the button element.

    Declaration
    public IMockerBlazorTestHelpers<T> ClickButton(string cssSelector, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    ClickButton<TComponent>(string, Func<bool>, IRenderedComponent<TComponent>, TimeSpan?)

    Clicks the button element.

    Declaration
    public IMockerBlazorTestHelpers<T> ClickButton<TComponent>(string cssSelector, Func<bool> waitFunc, IRenderedComponent<TComponent> startingComponent, TimeSpan? waitTimeout = null) where TComponent : class, IComponent
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    Func<bool> waitFunc

    The wait function.

    IRenderedComponent<TComponent> startingComponent

    The starting component.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    ClickButton<TComponent>(string, Func<bool>, TimeSpan?)

    Clicks the button element.

    Declaration
    public IMockerBlazorTestHelpers<T> ClickButton<TComponent>(string cssSelector, Func<bool> waitFunc, TimeSpan? waitTimeout = null) where TComponent : class, IComponent
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Exceptions
    Type Condition
    ArgumentNullException

    cssSelector

    ClickDropdownItem<TComponent>(IRenderedComponent<TComponent>, string, string, Func<bool>)

    Clicks the dropdown item.

    Declaration
    public IRenderedComponent<TComponent> ClickDropdownItem<TComponent>(IRenderedComponent<TComponent> component, string cssSelector, string propName, Func<bool> waitFunc) where TComponent : class, IComponent
    Parameters
    Type Name Description
    IRenderedComponent<TComponent> component

    The component.

    string cssSelector

    The CSS selector.

    string propName

    Name of the property.

    Func<bool> waitFunc

    The wait function.

    Returns
    Type Description
    IRenderedComponent<TComponent>

    IRenderedComponent<TComponent>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    ClickDropdownItem<TComponent>(string, Func<bool>, string)

    Clicks the dropdown item.

    Declaration
    public IRenderedComponent<TComponent> ClickDropdownItem<TComponent>(string propName, Func<bool> waitFunc, string itemCssSelector = "a.dropdown-item") where TComponent : class, IComponent
    Parameters
    Type Name Description
    string propName

    Name of the property.

    Func<bool> waitFunc

    The wait function.

    string itemCssSelector
    Returns
    Type Description
    IRenderedComponent<TComponent>

    IRenderedComponent<DropdownList<TKey, TValue>>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Exceptions
    Type Condition
    ArgumentNullException

    Component

    Dispose(bool)

    Disposes of the test context resources, in particular it disposes the Bunit.TestContextBase.Services service provider. Any async services registered with the service provider will disposed first, but their disposal will not be awaited..

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    Set to true if called from Bunit.TestContextBase.Dispose(), false if called from a finalizer.f.

    Overrides
    TestContextBase.Dispose(bool)
    Remarks

    The disposing parameter should be false when called from a finalizer, and true when called from the Bunit.TestContextBase.Dispose() method. In other words, it is true when deterministically called and false when non-deterministically called.

    FindAllByTag(string)

    Finds all by tag.

    Declaration
    public IEnumerable<IElement> FindAllByTag(string tagName)
    Parameters
    Type Name Description
    string tagName

    Name of the tag.

    Returns
    Type Description
    IEnumerable<IElement>

    IEnumerable<IElement>.

    FindById(string)

    Finds the by identifier.

    Declaration
    public IElement? FindById(string id)
    Parameters
    Type Name Description
    string id

    The identifier.

    Returns
    Type Description
    IElement

    IElement.

    GetAllComponents()

    Gets all components, regardless of render tree.

    Declaration
    protected Dictionary<ComponentBase, ComponentState> GetAllComponents()
    Returns
    Type Description
    Dictionary<ComponentBase, ComponentState>

    Dictionary<IComponent, ComponentState>.

    GetAllComponents<TComponent>()

    Gets all components from the renderer and their state.

    Declaration
    protected Dictionary<TComponent, ComponentState> GetAllComponents<TComponent>() where TComponent : ComponentBase
    Returns
    Type Description
    Dictionary<TComponent, ComponentState>

    Dictionary<TComponent, ComponentState> of all components.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Exceptions
    Type Condition
    ArgumentException

    Unable to get the renderer for this component.

    GetComponent<TComponent>()

    Gets the component.

    Declaration
    public IRenderedComponent<TComponent> GetComponent<TComponent>() where TComponent : class, IComponent
    Returns
    Type Description
    IRenderedComponent<TComponent>

    IRenderedComponent<TComponent>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Examples
    var comp = GetComponent<FetchData>();

    GetComponent<TComponent>(Func<IElement, bool>)

    Gets the component.

    Declaration
    public IRenderedComponent<TComponent> GetComponent<TComponent>(Func<IElement, bool> predicate) where TComponent : class, IComponent
    Parameters
    Type Name Description
    Func<IElement, bool> predicate

    The predicate.

    Returns
    Type Description
    IRenderedComponent<TComponent>

    IRenderedComponent<TComponent>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Examples
    var comp = GetComponent<FetchData>(element => element.InnerHtml.Contains("hello"));

    GetComponent<TComponent>(Func<IRenderedComponent<TComponent>, bool>)

    Gets the component.

    Declaration
    public IRenderedComponent<TComponent> GetComponent<TComponent>(Func<IRenderedComponent<TComponent>, bool> predicate) where TComponent : class, IComponent
    Parameters
    Type Name Description
    Func<IRenderedComponent<TComponent>, bool> predicate

    The predicate.

    Returns
    Type Description
    IRenderedComponent<TComponent>

    IRenderedComponent<TComponent>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Examples

    Filter rendered components by component state.

    var comp = GetComponent<FetchData>(x => x.ComponentId == 1234);

    Filter rendered components by instance values.

    var comp = GetComponent<FetchData>(x => x.Instance.IsRunning);

    GetComponents<TOfType>(Func<IElement, bool>?)

    Gets the components.

    Declaration
    public List<IRenderedComponent<TOfType>> GetComponents<TOfType>(Func<IElement, bool>? predicate = null) where TOfType : class, IComponent
    Parameters
    Type Name Description
    Func<IElement, bool> predicate

    The predicate.

    Returns
    Type Description
    List<IRenderedComponent<TOfType>>

    List<IRenderedComponent<TComponent>>.

    Type Parameters
    Name Description
    TOfType
    Examples
    var list = GetComponents<FetchData>(element => element.InnerHtml.Contains("hello"));

    GetComponents<TOfType>(Func<IRenderedComponent<TOfType>, bool>?)

    Gets the components.

    Declaration
    public IReadOnlyList<IRenderedComponent<TOfType>> GetComponents<TOfType>(Func<IRenderedComponent<TOfType>, bool>? predicate = null) where TOfType : class, IComponent
    Parameters
    Type Name Description
    Func<IRenderedComponent<TOfType>, bool> predicate

    The where function.

    Returns
    Type Description
    IReadOnlyList<IRenderedComponent<TOfType>>

    List<IRenderedComponent<TComponent>>.

    Type Parameters
    Name Description
    TOfType
    Examples

    Get all rendered FetchData components with a matching component id.

    var list = GetComponents<FetchData>(x => x.ComponentId == 1234);

    Get all rendered FetchData components with a matching instance state.

    var list = GetComponents<FetchData>(x => x.Instance.IsRunning);

    GetInjections(Type)

    Gets the injections.

    Declaration
    public IEnumerable<PropertyInfo> GetInjections(Type type)
    Parameters
    Type Name Description
    Type type

    The type.

    Returns
    Type Description
    IEnumerable<PropertyInfo>

    IEnumerable<PropertyInfo>.

    GetInjections(Type, Type)

    Gets the injections.

    Declaration
    public IEnumerable<PropertyInfo> GetInjections(Type type, Type injectAttribute)
    Parameters
    Type Name Description
    Type type

    The type.

    Type injectAttribute

    The inject attribute.

    Returns
    Type Description
    IEnumerable<PropertyInfo>

    IEnumerable<PropertyInfo>.

    GetInjections<TComponent>()

    Gets the injections.

    Declaration
    public IEnumerable<PropertyInfo> GetInjections<TComponent>()
    Returns
    Type Description
    IEnumerable<PropertyInfo>

    IEnumerable<PropertyInfo>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    InjectComponent(Type)

    Injects the component.

    Declaration
    public IMockerBlazorTestHelpers<T> InjectComponent(Type type)
    Parameters
    Type Name Description
    Type type

    The type.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    InjectComponent(Type, Type)

    Injects the component.

    Declaration
    public IMockerBlazorTestHelpers<T> InjectComponent(Type type, Type injectAttribute)
    Parameters
    Type Name Description
    Type type

    The type.

    Type injectAttribute

    The inject attribute.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    InjectComponent<TComponent>()

    Injects the component.

    Declaration
    public IMockerBlazorTestHelpers<T> InjectComponent<TComponent>()
    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    InjectComponent<TComponent, TInjectAttribute>()

    Injects the component.

    Declaration
    public IMockerBlazorTestHelpers<T> InjectComponent<TComponent, TInjectAttribute>() where TInjectAttribute : Attribute
    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    TInjectAttribute

    The type of the t inject attribute.

    IsExists(string, bool)

    Determines whether the specified CSS selector is exists.

    Declaration
    public bool IsExists(string cssSelector, bool throwOnNotExist = false)
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    bool throwOnNotExist

    if set to true [throw on not exist].

    Returns
    Type Description
    bool

    true if the specified CSS selector is exists; otherwise, false.

    OnAuthorizedClaimsChanged(object?, MockerObservableCollectionChangedEventArgs?)

    Handles the AuthorizedClaimsChanged event.

    Declaration
    protected void OnAuthorizedClaimsChanged(object? o = null, MockerObservableCollectionChangedEventArgs? mockerObservableCollectionChangedEventArgs = null)
    Parameters
    Type Name Description
    object o

    The o.

    MockerObservableCollectionChangedEventArgs mockerObservableCollectionChangedEventArgs

    The FastMoq.Collections.MockerObservableCollectionChangedEventArgs instance containing the event data.

    OnAuthorizedPoliciesChanged(object?, MockerObservableCollectionChangedEventArgs?)

    Handles the AuthorizedPoliciesChanged event.

    Declaration
    protected void OnAuthorizedPoliciesChanged(object? o = null, MockerObservableCollectionChangedEventArgs? mockerObservableCollectionChangedEventArgs = null)
    Parameters
    Type Name Description
    object o

    The o.

    MockerObservableCollectionChangedEventArgs mockerObservableCollectionChangedEventArgs

    The FastMoq.Collections.MockerObservableCollectionChangedEventArgs instance containing the event data.

    OnAuthorizedRolesChanged(object?, MockerObservableCollectionChangedEventArgs?)

    Handles the AuthorizedRolesChanged event.

    Declaration
    protected void OnAuthorizedRolesChanged(object? o = null, MockerObservableCollectionChangedEventArgs? mockerObservableCollectionChangedEventArgs = null)
    Parameters
    Type Name Description
    object o

    The o.

    MockerObservableCollectionChangedEventArgs mockerObservableCollectionChangedEventArgs

    The FastMoq.Collections.MockerObservableCollectionChangedEventArgs instance containing the event data.

    RenderComponent(Action<ComponentParameterCollectionBuilder<T>>, bool)

    Renders the component. If the component is already rendered, it will act like a stateChanged.

    Declaration
    public IRenderedComponent<T> RenderComponent(Action<ComponentParameterCollectionBuilder<T>> parameterBuilder, bool forceNew = false)
    Parameters
    Type Name Description
    Action<ComponentParameterCollectionBuilder<T>> parameterBuilder

    The parameter builder.

    bool forceNew

    if set to true [force new].

    Returns
    Type Description
    IRenderedComponent<T>

    IRenderedComponent<T>.

    Examples

    Render again with parameters without losing context.

    RenderComponent(b => b.Add(x => x.WeatherService, Mocks.GetObject<IWeatherForecastService>()));

    Force an initial render with parameters.

    RenderComponent(b => b.Add(x => x.WeatherService, Mocks.GetObject<IWeatherForecastService>()), true);

    RenderComponent(bool)

    Renders the component. If the component is already rendered, it will act like a stateChanged.

    Declaration
    public IRenderedComponent<T> RenderComponent(bool forceNew = false)
    Parameters
    Type Name Description
    bool forceNew

    if set to true [force new].

    Returns
    Type Description
    IRenderedComponent<T>

    IRenderedComponent<T>.

    Examples

    Render again without losing context. This honors any parameters already configured in RenderParameters.

    RenderComponent();

    Force a fresh initial render.

    RenderComponent(true);

    SetAutoComplete(string, string, Func<bool>, string)

    Sets the automatic complete.

    Declaration
    public Task SetAutoComplete(string cssSelector, string filterText, Func<bool> waitFunc, string itemCssSelector = ".b-is-autocomplete-suggestion")
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    string filterText

    The filter text.

    Func<bool> waitFunc

    The wait function.

    string itemCssSelector

    The item CSS selector.

    Returns
    Type Description
    Task

    Task.

    SetElementCheck<TComponent>(string, bool, Func<bool>, TimeSpan?, IRenderedFragment?)

    Sets the element check.

    Declaration
    public IMockerBlazorTestHelpers<T> SetElementCheck<TComponent>(string cssSelector, bool isChecked, Func<bool> waitFunc, TimeSpan? waitTimeout = null, IRenderedFragment? startingPoint = null) where TComponent : class, IComponent
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    bool isChecked

    if set to true [is checked].

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    IRenderedFragment startingPoint

    The starting point.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Exceptions
    Type Condition
    ArgumentNullException

    cssSelector

    ElementNotFoundException

    SetElementSwitch<TComponent>(string, bool, Func<bool>, TimeSpan?, IRenderedFragment?)

    Sets the element switch.

    Declaration
    public IMockerBlazorTestHelpers<T> SetElementSwitch<TComponent>(string cssSelector, bool isChecked, Func<bool> waitFunc, TimeSpan? waitTimeout = null, IRenderedFragment? startingPoint = null) where TComponent : class, IComponent
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    bool isChecked

    if set to true [is checked].

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    IRenderedFragment startingPoint

    The starting point.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Type Parameters
    Name Description
    TComponent

    The type of the t component.

    Exceptions
    Type Condition
    ArgumentNullException

    cssSelector

    SetElementText(IElement, string, Func<bool>, TimeSpan?)

    Sets the element text.

    Declaration
    public IMockerBlazorTestHelpers<T> SetElementText(IElement element, string text, Func<bool> waitFunc, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    IElement element

    The element.

    string text

    The text.

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    SetElementText(string, string, Func<bool>, TimeSpan?, IRenderedFragment?)

    Sets the element text.

    Declaration
    public IMockerBlazorTestHelpers<T> SetElementText(string cssSelector, string text, Func<bool> waitFunc, TimeSpan? waitTimeout = null, IRenderedFragment? startingPoint = null)
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    string text

    The text.

    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    IRenderedFragment startingPoint

    The starting point.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    Exceptions
    Type Condition
    ArgumentNullException

    cssSelector

    Setup(InvocationMatcher?, bool)

    Setup and create component.

    Declaration
    protected void Setup(InvocationMatcher? jsInvocationMatcher = null, bool isCatchAllMatcher = false)
    Parameters
    Type Name Description
    InvocationMatcher jsInvocationMatcher
    bool isCatchAllMatcher

    SetupAuthorization()

    Setups the authorization.

    Declaration
    protected virtual void SetupAuthorization()
    See Also
    AuthorizedClaims
    AuthorizedPolicies
    AuthorizedRoles
    AuthContext
    AuthUsername

    SetupJsInterop(BunitJSInterop, InvocationMatcher?, bool)

    Adds the utilities.

    Declaration
    public virtual void SetupJsInterop(BunitJSInterop jsInterop, InvocationMatcher? jsInvocationMatcher, bool isCatchAll)
    Parameters
    Type Name Description
    BunitJSInterop jsInterop

    The js interop.

    InvocationMatcher jsInvocationMatcher

    The js invocation matcher.

    bool isCatchAll

    if set to true [is catch all].

    SetupMocks()

    Setups the mocks.

    Declaration
    protected virtual void SetupMocks()

    SetupServices()

    Setups the services.

    Declaration
    protected virtual void SetupServices()
    Exceptions
    Type Condition
    InvalidDataException

    Unable to get {nameof(IConfigurationRoot)} object.

    WaitDelay(TimeSpan?)

    Waits the delay time. Use only when absolutely needed. Prefer use of WaitForState, WaitForExists, or
    

    WaitForNotExists.

    Declaration
    public IMockerBlazorTestHelpers<T> WaitDelay(TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    WaitForExists(string, TimeSpan?)

    Waits for exists.

    Declaration
    public IMockerBlazorTestHelpers<T> WaitForExists(string cssSelector, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    WaitForNotExists(string, TimeSpan?)

    Waits for not exists.

    Declaration
    public IMockerBlazorTestHelpers<T> WaitForNotExists(string cssSelector, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    string cssSelector

    The CSS selector.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    IMockerBlazorTestHelpers<T>.

    WaitForState(Func<bool>, TimeSpan?)

    Waits for state.

    Declaration
    public IMockerBlazorTestHelpers<T> WaitForState(Func<bool> waitFunc, TimeSpan? waitTimeout = null)
    Parameters
    Type Name Description
    Func<bool> waitFunc

    The wait function.

    TimeSpan? waitTimeout

    The wait timeout.

    Returns
    Type Description
    IMockerBlazorTestHelpers<T>

    true if XXXX, false otherwise.

    Implements

    IDisposable
    IMockerBlazorTestHelpers<T>

    Extension Methods

    ObjectExtensions.RaiseIfNull<T>(T?, string?, string?, int?, string?)
    TestClassExtensions.GetFieldValue<TObject>(TObject, string, TObject?)
    TestClassExtensions.GetField<TObject>(TObject, string)
    TestClassExtensions.GetMemberName<T, TValue>(T, Expression<Func<T, TValue>>)
    TestClassExtensions.GetMember<T, TValue>(T, Expression<Func<T, TValue>>)
    TestClassExtensions.GetMethodValue<TObject>(TObject, string, object?, params object[])
    TestClassExtensions.GetMethod<TObject>(TObject, string)
    TestClassExtensions.GetPropertyValue<TObject>(TObject, string, object?)
    TestClassExtensions.GetProperty<TObject>(TObject, string)
    TestClassExtensions.SetFieldValue<TObject>(TObject, string, object?)
    TestClassExtensions.SetPropertyValue<TObject>(TObject, string, object?)
    MockerHttpMoqExtensions.SetupHttpMessage(object, Func<HttpResponseMessage>, Expression?, Expression?)
    MockerHttpMoqExtensions.SetupMessageAsync<TMock, TReturn>(object, Expression<Func<TMock, Task<TReturn>>>, Func<TReturn>)
    MockerHttpMoqExtensions.SetupMessageProtectedAsync<TMock, TReturn>(object, string, Func<TReturn>, params object?[]?)
    MockerHttpMoqExtensions.SetupMessageProtected<TMock, TReturn>(object, string, Func<TReturn>, params object?[]?)
    MockerHttpMoqExtensions.SetupMessage<TMock, TReturn>(object, Expression<Func<TMock, TReturn>>, Func<TReturn>)
    TestClassExtensions.GetFieldInfo<TType>(object, string)
    TestClassExtensions.GetFieldValue<T>(object?, FieldInfo)
    TestClassExtensions.GetFieldValue<T, TType>(object, string)

    See Also

    IMockerBlazorTestHelpers<T>
    ComponentBase
    In this article
    Back to top
    Generated 2026-04-08 00:16 UTC