Class OptionsTestExtensions
Provides convenience helpers for registering IOptions<TOptions> dependencies in tests.
Inherited Members
Namespace: FastMoq.Extensions
Assembly: FastMoq.Core.dll
Syntax
public static class OptionsTestExtensions
Methods
SetupOptions<T>(Mocker, bool)
Registers a default IOptions<TOptions> value created from a new instance of T.
Declaration
public static Mocker SetupOptions<T>(this Mocker mocker, bool replace = false) where T : class, new()
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| bool | replace | True to replace an existing options registration. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The options type to register. |
Examples
var mocker = new Mocker()
.SetupOptions<MyOptions>();
SetupOptions<T>(Mocker, Func<T>, bool)
Creates and registers a concrete IOptions<TOptions> value from a factory.
Declaration
public static Mocker SetupOptions<T>(this Mocker mocker, Func<T> create, bool replace = false) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Func<T> | create | The factory used to create the options value each time IOptions<TOptions> is resolved. |
| bool | replace | True to replace an existing options registration. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The options type to register. |
SetupOptions<T>(Mocker, T, bool)
Registers a concrete IOptions<TOptions> value.
Declaration
public static Mocker SetupOptions<T>(this Mocker mocker, T value, bool replace = false) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| T | value | The options value to wrap in Create<TOptions>(TOptions). |
| bool | replace | True to replace an existing options registration. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The options type to register. |
Examples
var mocker = new Mocker()
.SetupOptions(new CheckoutOptions { TimeoutSeconds = 30 });