Class TestServiceProvider
- Namespace
- Bunit
- Assembly
- Bunit.Core.dll
Represents a IServiceProvider and IServiceCollection as a single type used for test purposes.
public sealed class TestServiceProvider : IServiceProvider, IServiceCollection, IList<ServiceDescriptor>, ICollection<ServiceDescriptor>, IEnumerable<ServiceDescriptor>, IEnumerable, IDisposable, IAsyncDisposable
- Inheritance
-
TestServiceProvider
- Implements
- Inherited Members
- Extension Methods
Constructors
TestServiceProvider(IServiceCollection?)
Initializes a new instance of the TestServiceProvider class
and sets its service collection to the provided initialServiceCollection
, if any.
public TestServiceProvider(IServiceCollection? initialServiceCollection = null)
Parameters
initialServiceCollection
IServiceCollection
Properties
Count
public int Count { get; }
Property Value
IsProviderInitialized
Gets a value indicating whether this TestServiceProvider has been initialized, and
no longer will accept calls to the AddService
's methods.
public bool IsProviderInitialized { get; }
Property Value
IsReadOnly
public bool IsReadOnly { get; }
Property Value
this[int]
public ServiceDescriptor this[int index] { get; set; }
Parameters
index
int
Property Value
Options
Gets or sets the ServiceProviderOptions used when the IServiceProvider is created.
public ServiceProviderOptions Options { get; set; }
Property Value
Methods
Add(ServiceDescriptor)
public void Add(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
AddFallbackServiceProvider(IServiceProvider)
Add a fall back service provider that provides services when the default returns null.
public void AddFallbackServiceProvider(IServiceProvider serviceProvider)
Parameters
serviceProvider
IServiceProviderThe fallback service provider.
Clear()
public void Clear()
Contains(ServiceDescriptor)
public bool Contains(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
Returns
CopyTo(ServiceDescriptor[], int)
public void CopyTo(ServiceDescriptor[] array, int arrayIndex)
Parameters
array
ServiceDescriptor[]arrayIndex
int
Dispose()
public void Dispose()
DisposeAsync()
public ValueTask DisposeAsync()
Returns
GetEnumerator()
public IEnumerator<ServiceDescriptor> GetEnumerator()
Returns
GetKeyedService(Type, object?)
public object? GetKeyedService(Type serviceType, object? serviceKey)
Parameters
Returns
GetRequiredKeyedService(Type, object?)
public object GetRequiredKeyedService(Type serviceType, object? serviceKey)
Parameters
Returns
GetService(Type)
public object? GetService(Type serviceType)
Parameters
serviceType
Type
Returns
GetService<TService>()
Get service of type T from the test provider.
public TService? GetService<TService>()
Returns
- TService
A service object of type T or null if there is no such service.
Type Parameters
TService
The type of service object to get.
IndexOf(ServiceDescriptor)
public int IndexOf(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
Returns
Insert(int, ServiceDescriptor)
public void Insert(int index, ServiceDescriptor item)
Parameters
index
intitem
ServiceDescriptor
Remove(ServiceDescriptor)
public bool Remove(ServiceDescriptor item)
Parameters
item
ServiceDescriptor
Returns
RemoveAt(int)
public void RemoveAt(int index)
Parameters
index
int
UseServiceProviderFactory(Func<IServiceCollection, IServiceProvider>)
Use a custom service provider factory for creating the underlying IServiceProvider.
public void UseServiceProviderFactory(Func<IServiceCollection, IServiceProvider> serviceProviderFactory)
Parameters
serviceProviderFactory
Func<IServiceCollection, IServiceProvider>custom service provider factory
UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder>, Action<TContainerBuilder>?)
Use a custom service provider factory for creating the underlying IServiceProvider.
public void UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> serviceProviderFactory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull
Parameters
serviceProviderFactory
IServiceProviderFactory<TContainerBuilder>custom service provider factory
configure
Action<TContainerBuilder>builder configuration action
Type Parameters
TContainerBuilder
Type of the container builder. See IServiceProviderFactory<TContainerBuilder>