FastMoq
Search Results for

    Show / Hide Table of Contents

    Class TestServiceProvider

    Backward-compatible wrapper around Bunit.BunitServiceProvider for FastMoq Blazor helpers.

    Inheritance
    object
    TestServiceProvider
    Implements
    IServiceCollection
    IList<ServiceDescriptor>
    ICollection<ServiceDescriptor>
    IEnumerable<ServiceDescriptor>
    IEnumerable
    IServiceProvider
    IDisposable
    IAsyncDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Bunit
    Assembly: FastMoq.Web.dll
    Syntax
    public sealed class TestServiceProvider : IServiceCollection, IList<ServiceDescriptor>, ICollection<ServiceDescriptor>, IEnumerable<ServiceDescriptor>, IEnumerable, IServiceProvider, IDisposable, IAsyncDisposable
    Remarks

    Keep this wrapper when migrating existing FastMoq Blazor tests with minimal churn. It preserves the older helper name while delegating to the current bUnit 2 service-provider implementation.

    Constructors

    TestServiceProvider(BunitServiceProvider)

    Initializes a new instance of the TestServiceProvider class.

    Declaration
    public TestServiceProvider(BunitServiceProvider inner)
    Parameters
    Type Name Description
    BunitServiceProvider inner

    The underlying bUnit service provider.

    Properties

    Count

    Gets the number of elements contained in the ICollection<T>.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    int

    The number of elements contained in the ICollection<T>.

    InnerProvider

    Gets the underlying bUnit service provider.

    Declaration
    public BunitServiceProvider InnerProvider { get; }
    Property Value
    Type Description
    BunitServiceProvider

    IsProviderInitialized

    Gets a value indicating whether the underlying provider has been initialized.

    Declaration
    public bool IsProviderInitialized { get; }
    Property Value
    Type Description
    bool

    IsReadOnly

    Gets a value indicating whether the ICollection<T> is read-only.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    bool

    true if the ICollection<T> is read-only; otherwise, false.

    this[int]

    Gets or sets the element at the specified index.

    Declaration
    public ServiceDescriptor this[int index] { get; set; }
    Parameters
    Type Name Description
    int index

    The zero-based index of the element to get or set.

    Property Value
    Type Description
    ServiceDescriptor

    The element at the specified index.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    index is not a valid index in the IList<T>.

    NotSupportedException

    The property is set and the IList<T> is read-only.

    Options

    Gets or sets the service provider options.

    Declaration
    public ServiceProviderOptions Options { get; set; }
    Property Value
    Type Description
    ServiceProviderOptions

    Methods

    Add(ServiceDescriptor)

    Adds an item to the ICollection<T>.

    Declaration
    public void Add(ServiceDescriptor item)
    Parameters
    Type Name Description
    ServiceDescriptor item

    The object to add to the ICollection<T>.

    Exceptions
    Type Condition
    NotSupportedException

    The ICollection<T> is read-only.

    AddFallbackServiceProvider(IServiceProvider)

    Adds a fallback service provider.

    Declaration
    public void AddFallbackServiceProvider(IServiceProvider fallbackServiceProvider)
    Parameters
    Type Name Description
    IServiceProvider fallbackServiceProvider

    The fallback provider.

    Clear()

    Removes all items from the ICollection<T>.

    Declaration
    public void Clear()
    Exceptions
    Type Condition
    NotSupportedException

    The ICollection<T> is read-only.

    Contains(ServiceDescriptor)

    Determines whether the ICollection<T> contains a specific value.

    Declaration
    public bool Contains(ServiceDescriptor item)
    Parameters
    Type Name Description
    ServiceDescriptor item

    The object to locate in the ICollection<T>.

    Returns
    Type Description
    bool

    true if item is found in the ICollection<T>; otherwise, false.

    CopyTo(ServiceDescriptor[], int)

    Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

    Declaration
    public void CopyTo(ServiceDescriptor[] array, int arrayIndex)
    Parameters
    Type Name Description
    ServiceDescriptor[] array

    The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.

    int arrayIndex

    The zero-based index in array at which copying begins.

    Exceptions
    Type Condition
    ArgumentNullException

    array is null.

    ArgumentOutOfRangeException

    arrayIndex is less than 0.

    ArgumentException

    The number of elements in the source ICollection<T> is greater than the available space from arrayIndex to the end of the destination array.

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

    Declaration
    public void Dispose()

    DisposeAsync()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

    Declaration
    public ValueTask DisposeAsync()
    Returns
    Type Description
    ValueTask

    A task that represents the asynchronous dispose operation.

    GetEnumerator()

    Returns an enumerator that iterates through the collection.

    Declaration
    public IEnumerator<ServiceDescriptor> GetEnumerator()
    Returns
    Type Description
    IEnumerator<ServiceDescriptor>

    An enumerator that can be used to iterate through the collection.

    GetKeyedService(Type, object)

    Gets a keyed service from the underlying provider.

    Declaration
    public object? GetKeyedService(Type serviceType, object serviceKey)
    Parameters
    Type Name Description
    Type serviceType

    The service type.

    object serviceKey

    The service key.

    Returns
    Type Description
    object

    The resolved service, if available.

    GetRequiredKeyedService(Type, object)

    Gets a required keyed service from the underlying provider.

    Declaration
    public object GetRequiredKeyedService(Type serviceType, object serviceKey)
    Parameters
    Type Name Description
    Type serviceType

    The service type.

    object serviceKey

    The service key.

    Returns
    Type Description
    object

    The resolved service.

    GetService(Type)

    Gets the service object of the specified type.

    Declaration
    public object? GetService(Type serviceType)
    Parameters
    Type Name Description
    Type serviceType

    An object that specifies the type of service object to get.

    Returns
    Type Description
    object

    A service object of type serviceType.

    -or-

    null if there is no service object of type serviceType.

    GetService<TService>()

    Gets a service from the underlying provider.

    Declaration
    public TService? GetService<TService>()
    Returns
    Type Description
    TService

    The resolved service, if available.

    Type Parameters
    Name Description
    TService

    The service type.

    IndexOf(ServiceDescriptor)

    Determines the index of a specific item in the IList<T>.

    Declaration
    public int IndexOf(ServiceDescriptor item)
    Parameters
    Type Name Description
    ServiceDescriptor item

    The object to locate in the IList<T>.

    Returns
    Type Description
    int

    The index of item if found in the list; otherwise, -1.

    InitializeProvider()

    Initializes the underlying provider.

    Declaration
    public void InitializeProvider()
    Remarks

    bUnit 2 no longer exposes the exact same initialization path as earlier versions. FastMoq keeps this method so existing helper code can continue to force provider initialization when needed.

    Insert(int, ServiceDescriptor)

    Inserts an item to the IList<T> at the specified index.

    Declaration
    public void Insert(int index, ServiceDescriptor item)
    Parameters
    Type Name Description
    int index

    The zero-based index at which item should be inserted.

    ServiceDescriptor item

    The object to insert into the IList<T>.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    index is not a valid index in the IList<T>.

    NotSupportedException

    The IList<T> is read-only.

    Remove(ServiceDescriptor)

    Removes the first occurrence of a specific object from the ICollection<T>.

    Declaration
    public bool Remove(ServiceDescriptor item)
    Parameters
    Type Name Description
    ServiceDescriptor item

    The object to remove from the ICollection<T>.

    Returns
    Type Description
    bool

    true if item was successfully removed from the ICollection<T>; otherwise, false. This method also returns false if item is not found in the original ICollection<T>.

    Exceptions
    Type Condition
    NotSupportedException

    The ICollection<T> is read-only.

    RemoveAt(int)

    Removes the IList<T> item at the specified index.

    Declaration
    public void RemoveAt(int index)
    Parameters
    Type Name Description
    int index

    The zero-based index of the item to remove.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    index is not a valid index in the IList<T>.

    NotSupportedException

    The IList<T> is read-only.

    UseServiceProviderFactory(Func<IServiceCollection, IServiceProvider>)

    Configures the underlying service provider factory.

    Declaration
    public void UseServiceProviderFactory(Func<IServiceCollection, IServiceProvider> serviceProviderFactory)
    Parameters
    Type Name Description
    Func<IServiceCollection, IServiceProvider> serviceProviderFactory

    The factory used to create the provider.

    UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder>, Action<TContainerBuilder>)

    Configures the underlying service provider factory.

    Declaration
    public void UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> serviceProviderFactory, Action<TContainerBuilder> configureContainer) where TContainerBuilder : notnull
    Parameters
    Type Name Description
    IServiceProviderFactory<TContainerBuilder> serviceProviderFactory

    The service provider factory.

    Action<TContainerBuilder> configureContainer

    The container configuration callback.

    Type Parameters
    Name Description
    TContainerBuilder

    The container builder type.

    Implements

    IServiceCollection
    IList<T>
    ICollection<T>
    IEnumerable<T>
    IEnumerable
    IServiceProvider
    IDisposable
    IAsyncDisposable

    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)
    In this article
    Back to top
    Generated 2026-04-29 03:53 UTC