Class DbContextMockerExtensions
Entity Framework-specific FastMoq helpers.
Inherited Members
Namespace: FastMoq
Assembly: FastMoq.Database.dll
Syntax
public static class DbContextMockerExtensions
Methods
CreateLegacyDbContextMock(Type, MockBehavior, object?[])
Creates the legacy Moq-based DbContext mock used by the database helper package.
Declaration
public static Mock? CreateLegacyDbContextMock(Type requestedType, MockBehavior behavior, object?[] constructorArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | requestedType | The DbContext runtime type to mock. |
| MockBehavior | behavior | The Moq behavior that should be applied to the created mock. |
| object[] | constructorArgs | The constructor arguments to pass through when a DbContext constructor requires them. |
Returns
| Type | Description |
|---|---|
| Mock | A legacy Moq.Mock instance for the requested DbContext type. |
GetDbContextHandle<TContext>(Mocker, DbContextHandleOptions<TContext>?)
Creates or returns a DbContext test handle using the requested provisioning mode.
Declaration
public static DbContextHandle<TContext> GetDbContextHandle<TContext>(this Mocker mocker, DbContextHandleOptions<TContext>? options = null) where TContext : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | |
| DbContextHandleOptions<TContext> | options |
Returns
| Type | Description |
|---|---|
| DbContextHandle<TContext> |
Type Parameters
| Name | Description |
|---|---|
| TContext |
GetMockDbContext(Mocker, Type)
Creates or returns the tracked DbContext mock for the requested context type.
Declaration
public static Mock GetMockDbContext(this Mocker mocker, Type dbContextType)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | |
| Type | dbContextType |
Returns
| Type | Description |
|---|---|
| Mock |
GetMockDbContext<TContext>(Mocker)
Creates or returns the tracked DbContext mock for the requested context type.
Declaration
public static DbContextMock<TContext> GetMockDbContext<TContext>(this Mocker mocker) where TContext : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker |
Returns
| Type | Description |
|---|---|
| DbContextMock<TContext> |
Type Parameters
| Name | Description |
|---|---|
| TContext |
TryCreateManagedDbContextInstance(Mocker, Type, out object?)
Attempts to create and track a managed DbContext instance for the requested type when the type represents an Entity Framework DbContext that is not already tracked.
Declaration
public static bool TryCreateManagedDbContextInstance(Mocker mocker, Type requestedType, out object? instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The mocker that should own the tracked DbContext instance. |
| Type | requestedType | The requested runtime type. |
| object | instance | When this method returns true, contains the tracked DbContext instance. |
Returns
| Type | Description |
|---|---|
| bool | true when a managed DbContext instance was created; otherwise, false. |