Class TestServiceProvider
Backward-compatible wrapper around Bunit.BunitServiceProvider for FastMoq Blazor helpers.
Implements
Inherited Members
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 |
|
| 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 |
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 |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
| ArgumentException | The number of elements in the source ICollection<T> is greater than the available space from |
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 -or- null if there is no service object of type |
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 |
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 |
| ServiceDescriptor | item | The object to insert into the IList<T>. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| 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 |
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 |
|
| 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. |