FastMoq
Search Results for

    Show / Hide Table of Contents

    Class DbContextMock<TEntity>

    Wrapper for Mock. Implements the Moq.Mock<T>

    Inheritance
    object
    Mock
    Mock<TEntity>
    DbContextMock<TEntity>
    Implements
    IMock<TEntity>
    IDbContextMock<TEntity>
    IDbContextMock
    Inherited Members
    Mock<TEntity>.ToString()
    Mock<TEntity>.OnGetObject()
    Mock<TEntity>.As<TInterface>()
    Mock<TEntity>.Setup(Expression<Action<TEntity>>)
    Mock<TEntity>.Setup<TResult>(Expression<Func<TEntity, TResult>>)
    Mock<TEntity>.SetupGet<TProperty>(Expression<Func<TEntity, TProperty>>)
    Mock<TEntity>.SetupSet<TProperty>(Action<TEntity>)
    Mock<TEntity>.SetupSet(Action<TEntity>)
    Mock<TEntity>.SetupAdd(Action<TEntity>)
    Mock<TEntity>.SetupRemove(Action<TEntity>)
    Mock<TEntity>.SetupProperty<TProperty>(Expression<Func<TEntity, TProperty>>)
    Mock<TEntity>.SetupProperty<TProperty>(Expression<Func<TEntity, TProperty>>, TProperty)
    Mock<TEntity>.SetupAllProperties()
    Mock<TEntity>.SetupSequence<TResult>(Expression<Func<TEntity, TResult>>)
    Mock<TEntity>.SetupSequence(Expression<Action<TEntity>>)
    Mock<TEntity>.When(Func<bool>)
    Mock<TEntity>.Verify(Expression<Action<TEntity>>)
    Mock<TEntity>.Verify(Expression<Action<TEntity>>, Times)
    Mock<TEntity>.Verify(Expression<Action<TEntity>>, Func<Times>)
    Mock<TEntity>.Verify(Expression<Action<TEntity>>, string)
    Mock<TEntity>.Verify(Expression<Action<TEntity>>, Times, string)
    Mock<TEntity>.Verify(Expression<Action<TEntity>>, Func<Times>, string)
    Mock<TEntity>.Verify<TResult>(Expression<Func<TEntity, TResult>>)
    Mock<TEntity>.Verify<TResult>(Expression<Func<TEntity, TResult>>, Times)
    Mock<TEntity>.Verify<TResult>(Expression<Func<TEntity, TResult>>, Func<Times>)
    Mock<TEntity>.Verify<TResult>(Expression<Func<TEntity, TResult>>, string)
    Mock<TEntity>.Verify<TResult>(Expression<Func<TEntity, TResult>>, Times, string)
    Mock<TEntity>.VerifyGet<TProperty>(Expression<Func<TEntity, TProperty>>)
    Mock<TEntity>.VerifyGet<TProperty>(Expression<Func<TEntity, TProperty>>, Times)
    Mock<TEntity>.VerifyGet<TProperty>(Expression<Func<TEntity, TProperty>>, Func<Times>)
    Mock<TEntity>.VerifyGet<TProperty>(Expression<Func<TEntity, TProperty>>, string)
    Mock<TEntity>.VerifyGet<TProperty>(Expression<Func<TEntity, TProperty>>, Times, string)
    Mock<TEntity>.VerifyGet<TProperty>(Expression<Func<TEntity, TProperty>>, Func<Times>, string)
    Mock<TEntity>.VerifySet(Action<TEntity>)
    Mock<TEntity>.VerifySet(Action<TEntity>, Times)
    Mock<TEntity>.VerifySet(Action<TEntity>, Func<Times>)
    Mock<TEntity>.VerifySet(Action<TEntity>, string)
    Mock<TEntity>.VerifySet(Action<TEntity>, Times, string)
    Mock<TEntity>.VerifySet(Action<TEntity>, Func<Times>, string)
    Mock<TEntity>.VerifyAdd(Action<TEntity>)
    Mock<TEntity>.VerifyAdd(Action<TEntity>, Times)
    Mock<TEntity>.VerifyAdd(Action<TEntity>, Func<Times>)
    Mock<TEntity>.VerifyAdd(Action<TEntity>, string)
    Mock<TEntity>.VerifyAdd(Action<TEntity>, Times, string)
    Mock<TEntity>.VerifyAdd(Action<TEntity>, Func<Times>, string)
    Mock<TEntity>.VerifyRemove(Action<TEntity>)
    Mock<TEntity>.VerifyRemove(Action<TEntity>, Times)
    Mock<TEntity>.VerifyRemove(Action<TEntity>, Func<Times>)
    Mock<TEntity>.VerifyRemove(Action<TEntity>, string)
    Mock<TEntity>.VerifyRemove(Action<TEntity>, Times, string)
    Mock<TEntity>.VerifyRemove(Action<TEntity>, Func<Times>, string)
    Mock<TEntity>.VerifyNoOtherCalls()
    Mock<TEntity>.Raise(Action<TEntity>, EventArgs)
    Mock<TEntity>.Raise(Action<TEntity>, params object[])
    Mock<TEntity>.Behavior
    Mock<TEntity>.DefaultValueProvider
    Mock<TEntity>.Object
    Mock<TEntity>.Name
    Mock<TEntity>.Switches
    Mock.Of<T>()
    Mock.Of<T>(MockBehavior)
    Mock.Of<T>(Expression<Func<T, bool>>)
    Mock.Of<T>(Expression<Func<T, bool>>, MockBehavior)
    Mock.Get<T>(T)
    Mock.Verify(params Mock[])
    Mock.VerifyAll(params Mock[])
    Mock.Verify()
    Mock.VerifyAll()
    Mock.SetReturnsDefault<TReturn>(TReturn)
    Mock.DefaultValue
    Mock.Invocations
    Mock.Setups
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: FastMoq.Models
    Assembly: FastMoq.Database.dll
    Syntax
    public class DbContextMock<TEntity> : Mock<TEntity>, IMock<TEntity>, IDbContextMock<TEntity>, IDbContextMock where TEntity : DbContext
    Type Parameters
    Name Description
    TEntity

    The type of the t entity.

    Constructors

    DbContextMock()

    Initializes an instance of the mock with Moq.MockBehavior.Default behavior.

    Declaration
    public DbContextMock()
    Examples
    var mock = new Mock<IFormatProvider>();

    DbContextMock(MockBehavior)

    Initializes an instance of the mock with the specified Moq.MockBehavior behavior.

    Declaration
    public DbContextMock(MockBehavior behavior)
    Parameters
    Type Name Description
    MockBehavior behavior

    Behavior of the mock.

    Examples
    var mock = new Mock<IFormatProvider>(MockBehavior.Strict);

    DbContextMock(MockBehavior, params object[])

    Initializes an instance of the mock with a specific Moq.MockBehavior behavior and with the given constructor arguments for the class.

    Declaration
    public DbContextMock(MockBehavior behavior, params object[] args)
    Parameters
    Type Name Description
    MockBehavior behavior

    Behavior of the mock.

    object[] args

    Optional constructor arguments if the mocked type is a class.

    Remarks

    The mock will try to find the best match constructor given the constructor arguments, and invoke that to initialize the instance. This applies only to classes, not interfaces.

    DbContextMock(Expression<Func<TEntity>>, MockBehavior)

    Initializes an instance of the mock using the given constructor call including its argument values and with a specific Moq.MockBehavior behavior.

    Declaration
    public DbContextMock(Expression<Func<TEntity>> newExpression, MockBehavior behavior = MockBehavior.Default)
    Parameters
    Type Name Description
    Expression<Func<TEntity>> newExpression

    Lambda expression that creates an instance of T.

    MockBehavior behavior

    Behavior of the mock.

    Examples
    var mock = new Mock<MyProvider>(() => new MyProvider(someArgument, 25), MockBehavior.Loose);

    DbContextMock(params object[])

    Initializes an instance of the mock with Moq.MockBehavior.Default behavior and with the given constructor arguments for the class. (Only valid when T is a class.)

    Declaration
    public DbContextMock(params object[] args)
    Parameters
    Type Name Description
    object[] args

    Optional constructor arguments if the mocked type is a class.

    Remarks

    The mock will try to find the best match constructor given the constructor arguments, and invoke that to initialize the instance.This applies only for classes, not interfaces.

    Examples
    var mock = new Mock<MyProvider>(someArgument, 25);

    Properties

    CallBase

    Whether the base member virtual implementation will be called for mocked classes if no setup is matched. Defaults to false.

    Declaration
    public override bool CallBase { get; set; }
    Property Value
    Type Description
    bool
    Overrides
    Moq.Mock<TEntity>.CallBase

    Methods

    SetupDbContextSetMethods(PropertyInfo)

    Configures the Set<TEntity> style methods on the mocked DbContext for the supplied DbSet property.

    Declaration
    public void SetupDbContextSetMethods(PropertyInfo propertyInfo)
    Parameters
    Type Name Description
    PropertyInfo propertyInfo

    The DbSet property being mapped back to the corresponding Set<TEntity> methods.

    SetupDbSetProperties(PropertyInfo, object)

    Configures DbSet-related properties on the mocked DbContext.

    Declaration
    public virtual void SetupDbSetProperties(PropertyInfo propertyInfo, object value)
    Parameters
    Type Name Description
    PropertyInfo propertyInfo

    The DbSet property to configure.

    object value

    The value the property should return.

    SetupDbSetPropertyGet(PropertyInfo, object)

    Configures the getter for a DbSet property on the mocked DbContext.

    Declaration
    public void SetupDbSetPropertyGet(PropertyInfo propertyInfo, object value)
    Parameters
    Type Name Description
    PropertyInfo propertyInfo

    The DbSet property whose getter should be configured.

    object value

    The value the getter should return.

    SetupDbSets(Mocker)

    Configures all DbSet properties and related helper methods for the current DbContext mock.

    Declaration
    public DbContextMock<TEntity> SetupDbSets(Mocker mocks)
    Parameters
    Type Name Description
    Mocker mocks

    The owning mocker used to resolve nested set dependencies.

    Returns
    Type Description
    DbContextMock<TEntity>

    The current DbContext mock instance for fluent chaining.

    SetupSetMethod(Type, Delegate, Type[]?, object?[]?)

    Configures the generic Set<TEntity> method for the supplied entity type.

    Declaration
    public void SetupSetMethod(Type setType, Delegate propValueDelegate, Type[]? types = null, object?[]? parameters = null)
    Parameters
    Type Name Description
    Type setType

    The entity type represented by the configured DbSet.

    Delegate propValueDelegate

    A delegate that returns the DbSet instance for the configured entity type.

    Type[] types

    Optional generic type arguments to apply when building the setup expression.

    object[] parameters

    Optional method parameters to use while building the setup expression.

    Implements

    Moq.IMock<T>
    IDbContextMock<TEntity>
    IDbContextMock

    Extension Methods

    ObjectExtensions.RaiseIfNull<T>(T?, string?, string?, int?, string?)
    TestClassExtensions.GetFieldValue<TObject>(TObject, string, TObject?)
    TestClassExtensions.GetField<TObject>(TObject, string)
    TestClassExtensions.GetMemberName<T, TValue>(T, Expression<Func<T, TValue>>)
    TestClassExtensions.GetMember<T, TValue>(T, Expression<Func<T, TValue>>)
    TestClassExtensions.GetMethodValue<TObject>(TObject, string, object?, params object[])
    TestClassExtensions.GetMethod<TObject>(TObject, string)
    TestClassExtensions.GetPropertyValue<TObject>(TObject, string, object?)
    TestClassExtensions.GetProperty<TObject>(TObject, string)
    TestClassExtensions.SetFieldValue<TObject>(TObject, string, object?)
    TestClassExtensions.SetPropertyValue<TObject>(TObject, string, object?)
    MockerCreationExtensions.SetupMockProperty<TMock>(Mock<TMock>, Expression<Func<TMock, object>>, object)
    MockerCreationExtensions.SetupMockProperty<TMock>(Mock<TMock>, PropertyInfo, object)
    MockerCreationExtensions.SetupMockProperty<TMock>(Mock<TMock>, string, object)
    MockerHttpMoqExtensions.SetupHttpMessage(object, Func<HttpResponseMessage>, Expression?, Expression?)
    MockerHttpMoqExtensions.SetupMessageAsync<TMock, TReturn>(object, Expression<Func<TMock, Task<TReturn>>>, Func<TReturn>)
    MockerHttpMoqExtensions.SetupMessageProtectedAsync<TMock, TReturn>(object, string, Func<TReturn>, params object?[]?)
    MockerHttpMoqExtensions.SetupMessageProtected<TMock, TReturn>(object, string, Func<TReturn>, params object?[]?)
    MockerHttpMoqExtensions.SetupMessage<TMock, TReturn>(object, Expression<Func<TMock, TReturn>>, Func<TReturn>)
    TestClassExtensions.GetFieldInfo<TType>(object, string)
    TestClassExtensions.GetFieldValue<T>(object?, FieldInfo)
    TestClassExtensions.GetFieldValue<T, TType>(object, string)

    See Also

    Mock<T>
    In this article
    Back to top
    Generated 2026-04-29 03:53 UTC