Class MethodResultExtensions
Provides narrow provider-first helpers for exact-call fixed method results.
Inherited Members
Namespace: FastMoq.Extensions
Assembly: FastMoq.Core.dll
Syntax
public static class MethodResultExtensions
Methods
AddMethodCallbackAsync<TService>(Mocker, Expression<Func<TService, Task>>, Action, bool)
Replaces the current interface registration with a proxy that runs the supplied callback and returns a completed Task for the specified exact asynchronous method call expression.
Declaration
public static TService AddMethodCallbackAsync<TService>(this Mocker mocker, Expression<Func<TService, Task>> callExpression, Action callback, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, Task>> | callExpression | The exact asynchronous method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| Action | callback | The side effect to execute when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
AddMethodCallback<TService>(Mocker, Expression<Action<TService>>, Action, bool)
Replaces the current interface registration with a proxy that runs the supplied callback for the specified exact void method call expression.
Declaration
public static TService AddMethodCallback<TService>(this Mocker mocker, Expression<Action<TService>> callExpression, Action callback, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Action<TService>> | callExpression | The exact void method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| Action | callback | The side effect to execute when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
AddMethodCompletionAsync<TService>(Mocker, Expression<Func<TService, Task>>, bool)
Replaces the current interface registration with a proxy that returns a completed Task for the specified asynchronous method call expression.
Declaration
public static TService AddMethodCompletionAsync<TService>(this Mocker mocker, Expression<Func<TService, Task>> callExpression, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, Task>> | callExpression | The exact asynchronous method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
AddMethodExceptionAsync<TService>(Mocker, Expression<Func<TService, Task>>, Exception, bool)
Replaces the current interface registration with a proxy that returns a faulted Task for the specified asynchronous method call expression.
Declaration
public static TService AddMethodExceptionAsync<TService>(this Mocker mocker, Expression<Func<TService, Task>> callExpression, Exception exception, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, Task>> | callExpression | The exact asynchronous method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| Exception | exception | The exception to surface through the returned faulted task when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
AddMethodExceptionAsync<TService, TResult>(Mocker, Expression<Func<TService, Task<TResult>>>, Exception, bool)
Replaces the current interface registration with a proxy that returns a faulted Task<TResult> for the specified asynchronous method call expression.
Declaration
public static TService AddMethodExceptionAsync<TService, TResult>(this Mocker mocker, Expression<Func<TService, Task<TResult>>> callExpression, Exception exception, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, Task<TResult>>> | callExpression | The exact asynchronous method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| Exception | exception | The exception to surface through the returned faulted task when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
| TResult | The logical result type produced by the asynchronous method. |
AddMethodException<TService>(Mocker, Expression<Action<TService>>, Exception, bool)
Replaces the current interface registration with a proxy that throws the supplied exception for the specified void method call expression.
Declaration
public static TService AddMethodException<TService>(this Mocker mocker, Expression<Action<TService>> callExpression, Exception exception, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Action<TService>> | callExpression | The exact void method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| Exception | exception | The exception to throw when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
AddMethodException<TService, TResult>(Mocker, Expression<Func<TService, TResult>>, Exception, bool)
Replaces the current interface registration with a proxy that throws the supplied exception for the specified method call expression.
Declaration
public static TService AddMethodException<TService, TResult>(this Mocker mocker, Expression<Func<TService, TResult>> callExpression, Exception exception, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, TResult>> | callExpression | The exact method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| Exception | exception | The exception to throw when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
| TResult | The synchronous result type declared by the configured method. |
AddMethodResultAsync<TService, TResult>(Mocker, Expression<Func<TService, Task<TResult>>>, TResult, bool)
Replaces the current interface registration with a proxy that returns a completed Task<TResult> for the specified async method call expression.
Declaration
public static TService AddMethodResultAsync<TService, TResult>(this Mocker mocker, Expression<Func<TService, Task<TResult>>> callExpression, TResult value, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, Task<TResult>>> | callExpression | The exact asynchronous method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| TResult | value | The logical result value to wrap in a completed Task<TResult>. |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
| TResult | The logical result type produced by the asynchronous method. |
Examples
var gateway = Mocks.AddMethodResultAsync<IInventoryGateway, InventoryItem>(
x => x.LoadAsync("alpha", CancellationToken.None),
new InventoryItem("alpha"));
(await gateway.LoadAsync("alpha", CancellationToken.None)).Sku.Should().Be("alpha");
AddMethodResult<TService, TResult>(Mocker, Expression<Func<TService, TResult>>, TResult, bool)
Replaces the current interface registration with a proxy that returns a fixed value for the specified method call expression.
Declaration
public static TService AddMethodResult<TService, TResult>(this Mocker mocker, Expression<Func<TService, TResult>> callExpression, TResult value, bool replace = true) where TService : class
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Expression<Func<TService, TResult>> | callExpression | The exact method call expression to intercept. FastMoq matcher markers such as FastArg are supported. |
| TResult | value | The fixed value to return when the call matches |
| bool | replace | True to replace an existing registration for |
Returns
| Type | Description |
|---|---|
| TService | The proxy-backed instance now registered for |
Type Parameters
| Name | Description |
|---|---|
| TService | The interface type to wrap. |
| TResult | The synchronous result type returned by the configured method. |
Examples
var gateway = Mocks.AddMethodResult<IInventoryGateway, InventoryItem>(
x => x.Load("alpha"),
new InventoryItem("alpha"));
gateway.Load("alpha").Sku.Should().Be("alpha");