FastMoq
Search Results for

    Show / Hide Table of Contents

    Class Mocker

    Core mock coordinator (provider-based creation integrated).

    Inheritance
    object
    Mocker
    Implements
    IDisposable
    IAsyncDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastMoq
    Assembly: FastMoq.Core.dll
    Syntax
    public class Mocker : IDisposable, IAsyncDisposable
    Remarks

    Resolution Hierarchy (v4)

    FastMoq uses consistent resolution hierarchies across different APIs:

    GetObject<T>() - Dependency Injection (Property/Field/Constructor)

    1. Custom registration via AddType<T>() or AddKnownType<T>()
    2. Built-in known instances (e.g., IFileSystem returns in-memory file system)
    3. Tracked mocks via GetOrCreateFastMock (get-or-create paradigm)
    4. Default value (null or type default)

    GetObject respects all custom configurations and auto-creates mocks when needed.

    GetMock<T>() / GetOrCreateMock<T>() - Test Setup (Mock-Only Path)

    1. Tracked mocks only (get-or-create tracked mock, no custom registrations applied)
    2. Mocks are preconfigured via SetupFastMock (e.g., IFileSystem delegates to built-in)

    GetMock/GetOrCreateMock always return tracked mocks for test setup, bypassing custom AddType registrations. This is intentional: AddType is for runtime instances, while GetMock is for test mocks. For setup values, use AddMock() or component constructor parameters instead.

    GetParameter() - Constructor Parameter Resolution

    1. Custom type mapping (AddType<TInterface, TImpl>())
    2. Falls back to GetObject for all other resolution

    Constructor parameters follow the same hierarchy as GetObject after type mapping.

    Examples

    Use Mocker as the main test composition root when you want provider-first arrangement based on concrete registrations and policy-driven construction.

    var fileSystem = new MockFileSystem();
    fileSystem.AddFile(@"c:\orders\42.json", new MockFileData("{ \"id\": 42, \"total\": 125.50 }"));
    

    var mocker = new Mocker() .AddType<IFileSystem>(fileSystem);

    var resolvedFileSystem = mocker.GetRequiredObject<IFileSystem>();

    resolvedFileSystem.File.Exists(@"c:\orders\42.json").Should().BeTrue(); resolvedFileSystem.Should().BeSameAs(fileSystem);

    Constructors

    Mocker()

    Initializes a new Mocker instance with a no-op external logging callback.

    Declaration
    public Mocker()

    Mocker(Action<LogLevel, EventId, string, Exception?>)

    Initializes a new Mocker instance with an exception-aware logging callback.

    Declaration
    public Mocker(Action<LogLevel, EventId, string, Exception?> loggingCallback)
    Parameters
    Type Name Description
    Action<LogLevel, EventId, string, Exception> loggingCallback

    Callback invoked for log entries emitted by this mocker.

    Mocker(Action<LogLevel, EventId, string>)

    Initializes a new Mocker instance with a three-parameter logging callback.

    Declaration
    public Mocker(Action<LogLevel, EventId, string> loggingCallback)
    Parameters
    Type Name Description
    Action<LogLevel, EventId, string> loggingCallback

    Callback invoked for log entries emitted by this mocker.

    Mocker(Dictionary<Type, IInstanceModel>)

    Initializes a new Mocker instance with an existing type map.

    Declaration
    public Mocker(Dictionary<Type, IInstanceModel> map)
    Parameters
    Type Name Description
    Dictionary<Type, IInstanceModel> map

    The preconfigured type registrations to seed into the mocker.

    Mocker(Dictionary<Type, IInstanceModel>, Action<LogLevel, EventId, string, Exception?>)

    Initializes a new Mocker instance with an existing type map and an exception-aware logging callback.

    Declaration
    public Mocker(Dictionary<Type, IInstanceModel> map, Action<LogLevel, EventId, string, Exception?> loggingCallback)
    Parameters
    Type Name Description
    Dictionary<Type, IInstanceModel> map

    The preconfigured type registrations to seed into the mocker.

    Action<LogLevel, EventId, string, Exception> loggingCallback

    Callback invoked for log entries emitted by this mocker.

    Mocker(Dictionary<Type, IInstanceModel>, Action<LogLevel, EventId, string>)

    Initializes a new Mocker instance with an existing type map and a three-parameter logging callback.

    Declaration
    public Mocker(Dictionary<Type, IInstanceModel> map, Action<LogLevel, EventId, string> loggingCallback)
    Parameters
    Type Name Description
    Dictionary<Type, IInstanceModel> map

    The preconfigured type registrations to seed into the mocker.

    Action<LogLevel, EventId, string> loggingCallback

    Callback invoked for log entries emitted by this mocker.

    Fields

    creatingTypeList

    Tracks types currently being created so recursive resolution can short-circuit circular member population.

    Declaration
    protected readonly List<Type> creatingTypeList
    Field Value
    Type Description
    List<Type>

    fileSystem

    The shared in-memory file system used by built-in file-system resolution helpers.

    Declaration
    public readonly MockFileSystem fileSystem
    Field Value
    Type Description
    MockFileSystem

    mockCollection

    Stores the tracked mock models for this Mocker instance.

    Declaration
    protected readonly List<MockModel> mockCollection
    Field Value
    Type Description
    List<MockModel>

    Properties

    Behavior

    Feature flag container controlling behavior such as base-call usage, dependency injection, nested member population, logging capture, and strict verification.

    Declaration
    public MockBehaviorOptions Behavior { get; set; }
    Property Value
    Type Description
    MockBehaviorOptions

    ConstructorHistory

    Tracks constructor-selection history for created instances.

    Declaration
    public ConstructorHistory ConstructorHistory { get; }
    Property Value
    Type Description
    ConstructorHistory

    ExceptionLog

    Captured exception messages observed during resolution and invocation helper flows.

    Declaration
    public ObservableExceptionLog ExceptionLog { get; }
    Property Value
    Type Description
    ObservableExceptionLog

    HttpClient

    The shared HttpClient created for this mocker instance.

    Declaration
    public HttpClient HttpClient { get; }
    Property Value
    Type Description
    HttpClient

    LogEntries

    Captured log entries observed through this mocker instance.

    Declaration
    public ObservableLogEntries LogEntries { get; }
    Property Value
    Type Description
    ObservableLogEntries

    LoggingCallback

    Callback invoked when FastMoq captures a log entry through this mocker instance.

    Declaration
    public Action<LogLevel, EventId, string, Exception?> LoggingCallback { get; }
    Property Value
    Type Description
    Action<LogLevel, EventId, string, Exception>

    OptionalParameterResolution

    Controls how optional constructor and invocation parameters are resolved when values are not supplied explicitly.

    Declaration
    public OptionalParameterResolutionMode OptionalParameterResolution { get; set; }
    Property Value
    Type Description
    OptionalParameterResolutionMode

    Policy

    Policy settings that control built-in type resolution and constructor fallback behavior.

    Declaration
    public MockerPolicyOptions Policy { get; }
    Property Value
    Type Description
    MockerPolicyOptions

    Uri

    The base URI associated with the shared HttpClient.

    Declaration
    public Uri Uri { get; }
    Property Value
    Type Description
    Uri

    Methods

    AddFileSystemAbstractionMapping()

    Registers the standard System.IO.Abstractions mappings backed by the current mock file system.

    Declaration
    public void AddFileSystemAbstractionMapping()

    AddInjections<T>(T, Type?)

    Populates injectable fields and properties on the supplied object using the current resolution pipeline.

    Declaration
    public T AddInjections<T>(T obj, Type? referenceType = null) where T : class?
    Parameters
    Type Name Description
    T obj

    The object whose injectable members should be populated.

    Type referenceType

    Optional type used to discover injectable members instead of the runtime type.

    Returns
    Type Description
    T

    The same object instance after injection.

    Type Parameters
    Name Description
    T

    The object type to update.

    AddKeyedType(Type, object, Type, Func<Mocker, object>?, bool, params object?[]?)

    Adds a keyed type registration for this Mocker instance.

    Declaration
    public Mocker AddKeyedType(Type tInterface, object serviceKey, Type tClass, Func<Mocker, object>? createFunc = null, bool replace = false, params object?[]? args)
    Parameters
    Type Name Description
    Type tInterface
    object serviceKey
    Type tClass
    Func<Mocker, object> createFunc
    bool replace
    object[] args
    Returns
    Type Description
    Mocker

    AddKeyedType<T>(object, Func<Mocker, T>?, bool, params object?[]?)

    Adds a keyed concrete registration with factory for this Mocker instance.

    Declaration
    public Mocker AddKeyedType<T>(object serviceKey, Func<Mocker, T>? createFunc = null, bool replace = false, params object?[]? args) where T : class
    Parameters
    Type Name Description
    object serviceKey
    Func<Mocker, T> createFunc
    bool replace
    object[] args
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    T

    AddKeyedType<T>(object, T, bool)

    Adds a keyed concrete value for this Mocker instance.

    Declaration
    public Mocker AddKeyedType<T>(object serviceKey, T value, bool replace = false)
    Parameters
    Type Name Description
    object serviceKey
    T value
    bool replace
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    T

    AddKeyedType<TInterface, TClass>(object, bool, params object?[]?)

    Adds a keyed interface-to-concrete registration for this Mocker instance.

    Declaration
    public Mocker AddKeyedType<TInterface, TClass>(object serviceKey, bool replace = false, params object?[]? args) where TInterface : class where TClass : class
    Parameters
    Type Name Description
    object serviceKey
    bool replace
    object[] args
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    TInterface
    TClass

    AddKeyedType<TInterface, TClass>(object, Func<Mocker, TClass>?, bool, params object?[]?)

    Adds a keyed interface-to-concrete registration with factory for this Mocker instance.

    Declaration
    public Mocker AddKeyedType<TInterface, TClass>(object serviceKey, Func<Mocker, TClass>? createFunc, bool replace = false, params object?[]? args) where TInterface : class where TClass : class
    Parameters
    Type Name Description
    object serviceKey
    Func<Mocker, TClass> createFunc
    bool replace
    object[] args
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    TInterface
    TClass

    AddKnownType(KnownTypeRegistration, bool)

    Adds a custom known-type registration for this Mocker instance. This is the extensibility point for framework-like types that need special resolution or setup behavior.

    Declaration
    public Mocker AddKnownType(KnownTypeRegistration registration, bool replace = false)
    Parameters
    Type Name Description
    KnownTypeRegistration registration
    bool replace
    Returns
    Type Description
    Mocker

    AddKnownType<TKnown>(Func<Mocker, Type, TKnown?>?, Func<Mocker, Type, TKnown?>?, Action<Mocker, Type, IFastMock>?, Action<Mocker, TKnown>?, bool, bool)

    Adds a typed custom known-type registration for this Mocker instance.

    Declaration
    public Mocker AddKnownType<TKnown>(Func<Mocker, Type, TKnown?>? directInstanceFactory = null, Func<Mocker, Type, TKnown?>? managedInstanceFactory = null, Action<Mocker, Type, IFastMock>? configureMock = null, Action<Mocker, TKnown>? applyObjectDefaults = null, bool includeDerivedTypes = false, bool replace = false)
    Parameters
    Type Name Description
    Func<Mocker, Type, TKnown> directInstanceFactory
    Func<Mocker, Type, TKnown> managedInstanceFactory
    Action<Mocker, Type, IFastMock> configureMock
    Action<Mocker, TKnown> applyObjectDefaults
    bool includeDerivedTypes
    bool replace
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    TKnown

    AddProperties(Type, object?, params KeyValuePair<string, object>[])

    Populates readable properties on an object using either explicit values or resolved dependencies.

    Declaration
    public object? AddProperties(Type type, object? obj, params KeyValuePair<string, object>[] data)
    Parameters
    Type Name Description
    Type type
    object obj
    KeyValuePair<string, object>[] data
    Returns
    Type Description
    object

    AddProperties<T>(T, params KeyValuePair<string, object>[])

    Populates readable properties on an object using either explicit values or resolved dependencies.

    Declaration
    public T? AddProperties<T>(T obj, params KeyValuePair<string, object>[] data)
    Parameters
    Type Name Description
    T obj
    KeyValuePair<string, object>[] data
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    AddType(Type, Type, Func<Mocker, object>?, bool, params object?[]?)

    Registers an interface-to-concrete mapping for object resolution.

    Declaration
    public Mocker AddType(Type tInterface, Type tClass, Func<Mocker, object>? createFunc = null, bool replace = false, params object?[]? args)
    Parameters
    Type Name Description
    Type tInterface

    The service or abstraction type to resolve.

    Type tClass

    The concrete implementation type to construct.

    Func<Mocker, object> createFunc

    Optional factory used instead of the default constructor path.

    bool replace

    True to replace an existing registration for the same service type.

    object[] args

    Optional constructor or factory arguments associated with the registration.

    Returns
    Type Description
    Mocker

    The current Mocker instance.

    AddType<T>(Func<Mocker, T>?, bool, params object?[]?)

    Registers a concrete type using an optional typed factory.

    Declaration
    public Mocker AddType<T>(Func<Mocker, T>? createFunc = null, bool replace = false, params object?[]? args) where T : class
    Parameters
    Type Name Description
    Func<Mocker, T> createFunc
    bool replace
    object[] args
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    T

    AddType<T>(T, bool)

    Registers a concrete instance so future object resolution returns that instance instead of auto-creating a mock.

    Declaration
    public Mocker AddType<T>(T value, bool replace = false)
    Parameters
    Type Name Description
    T value
    bool replace
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    T
    Examples

    Use this overload when a dependency should be a known runtime object rather than a tracked mock.

    var fileSystem = new MockFileSystem();
    

    var mocker = new Mocker() .AddType<IFileSystem>(fileSystem);

    var resolvedFileSystem = mocker.GetRequiredObject<IFileSystem>(); resolvedFileSystem.Should().BeSameAs(fileSystem);

    AddType<TInterface, TClass>(bool, params object?[]?)

    Registers a type as its own implementation for future resolution.

    Declaration
    public Mocker AddType<TInterface, TClass>(bool replace = false, params object?[]? args) where TInterface : class where TClass : class
    Parameters
    Type Name Description
    bool replace
    object[] args
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    TInterface
    TClass

    AddType<TInterface, TClass>(Func<Mocker, TClass>?, bool, params object?[]?)

    Registers a type mapping that uses a typed factory during resolution.

    Declaration
    public Mocker AddType<TInterface, TClass>(Func<Mocker, TClass>? createFunc, bool replace = false, params object?[]? args) where TInterface : class where TClass : class
    Parameters
    Type Name Description
    Func<Mocker, TClass> createFunc
    bool replace
    object[] args
    Returns
    Type Description
    Mocker
    Type Parameters
    Name Description
    TInterface
    TClass

    BuildExpression<T>()

    Builds a wildcard predicate expression for expression-valued arguments. Prefer AnyExpression<T>() in new code.

    Declaration
    public static Expression<Func<T, bool>> BuildExpression<T>()
    Returns
    Type Description
    Expression<Func<T, bool>>
    Type Parameters
    Name Description
    T

    CallMethod(InvocationOptions?, Action, params object?[])

    Invokes an action using the supplied invocation options.

    Declaration
    public void CallMethod(InvocationOptions? options, Action action, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    Action action
    object[] args

    CallMethod(InvocationOptions?, Delegate, params object?[])

    Invokes a delegate without using its return value and with explicit invocation options.

    Declaration
    public void CallMethod(InvocationOptions? options, Delegate del, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    Delegate del
    object[] args

    CallMethod(Action, params object?[])

    Invokes an action using the mocker's current invocation defaults.

    Declaration
    public void CallMethod(Action action, params object?[] args)
    Parameters
    Type Name Description
    Action action
    object[] args

    CallMethod(Delegate, params object?[])

    Invokes a delegate without using its return value.

    Declaration
    public void CallMethod(Delegate del, params object?[] args)
    Parameters
    Type Name Description
    Delegate del
    object[] args

    CallMethodAsync<TReturn>(InvocationOptions?, Delegate, params object?[])

    Invokes a delegate and awaits a task result using the supplied invocation options.

    Declaration
    public Task<TReturn> CallMethodAsync<TReturn>(InvocationOptions? options, Delegate del, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    Delegate del
    object[] args
    Returns
    Type Description
    Task<TReturn>
    Type Parameters
    Name Description
    TReturn

    CallMethodAsync<TReturn>(Delegate, params object?[])

    Invokes a delegate and awaits a task result using the mocker's current invocation defaults.

    Declaration
    public Task<TReturn> CallMethodAsync<TReturn>(Delegate del, params object?[] args)
    Parameters
    Type Name Description
    Delegate del
    object[] args
    Returns
    Type Description
    Task<TReturn>
    Type Parameters
    Name Description
    TReturn

    CallMethod<TReturn>(InvocationOptions?, Delegate, params object?[])

    Invokes a delegate and returns its result using the supplied invocation options.

    Declaration
    public TReturn CallMethod<TReturn>(InvocationOptions? options, Delegate del, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    Delegate del
    object[] args
    Returns
    Type Description
    TReturn
    Type Parameters
    Name Description
    TReturn

    CallMethod<TReturn>(InvocationOptions?, Func<TReturn>, params object?[])

    Invokes a function and returns its result using the supplied invocation options.

    Declaration
    public TReturn CallMethod<TReturn>(InvocationOptions? options, Func<TReturn> func, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    Func<TReturn> func
    object[] args
    Returns
    Type Description
    TReturn
    Type Parameters
    Name Description
    TReturn

    CallMethod<TReturn>(Delegate, params object?[])

    Invokes a delegate and returns its result using the mocker's current invocation defaults.

    Declaration
    public TReturn CallMethod<TReturn>(Delegate del, params object?[] args)
    Parameters
    Type Name Description
    Delegate del
    object[] args
    Returns
    Type Description
    TReturn
    Type Parameters
    Name Description
    TReturn

    CallMethod<TReturn>(Func<TReturn>, params object?[])

    Invokes a function and returns its result using the mocker's current invocation defaults.

    Declaration
    public TReturn CallMethod<TReturn>(Func<TReturn> func, params object?[] args)
    Parameters
    Type Name Description
    Func<TReturn> func
    object[] args
    Returns
    Type Description
    TReturn
    Type Parameters
    Name Description
    TReturn

    CreateFastMock<T>(MockCreationOptions?)

    Creates a provider-first mock and registers it.

    Declaration
    public IFastMock<T> CreateFastMock<T>(MockCreationOptions? options = null) where T : class
    Parameters
    Type Name Description
    MockCreationOptions options
    Returns
    Type Description
    IFastMock<T>
    Type Parameters
    Name Description
    T

    CreateInstanceByType<T>(InstanceCreationFlags, params Type?[])

    Creates an instance of T by selecting a constructor that matches the supplied parameter types and creation flags.

    Declaration
    public T? CreateInstanceByType<T>(InstanceCreationFlags flags, params Type?[] parameterTypes) where T : class
    Parameters
    Type Name Description
    InstanceCreationFlags flags
    Type[] parameterTypes
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    CreateInstanceByType<T>(params Type?[])

    Creates an instance of T by selecting a constructor that matches the supplied parameter types.

    Declaration
    public T? CreateInstanceByType<T>(params Type?[] parameterTypes) where T : class
    Parameters
    Type Name Description
    Type[] parameterTypes
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    CreateInstance<T>(InstanceCreationFlags, params object?[])

    Creates an instance of T using the supplied per-call construction flags.

    Declaration
    public T? CreateInstance<T>(InstanceCreationFlags flags, params object?[] args) where T : class
    Parameters
    Type Name Description
    InstanceCreationFlags flags
    object[] args
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    CreateInstance<T>(params object?[])

    Creates an instance of T using the current component-construction defaults.

    Declaration
    public T? CreateInstance<T>(params object?[] args) where T : class
    Parameters
    Type Name Description
    object[] args
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    CreateStandaloneFastMock(Type, MockCreationOptions?)

    Creates a provider-first mock handle for the supplied runtime type without registering it into this Mocker instance.

    Declaration
    public IFastMock CreateStandaloneFastMock(Type type, MockCreationOptions? options = null)
    Parameters
    Type Name Description
    Type type
    MockCreationOptions options
    Returns
    Type Description
    IFastMock
    Remarks

    Use this when the test needs a provider-selected standalone mock handle but does not want the mock tracked by the parent Mocker.

    CreateStandaloneFastMock<T>(MockCreationOptions?)

    Creates a provider-first mock handle without registering it into this Mocker instance.

    Declaration
    public IFastMock<T> CreateStandaloneFastMock<T>(MockCreationOptions? options = null) where T : class
    Parameters
    Type Name Description
    MockCreationOptions options
    Returns
    Type Description
    IFastMock<T>
    Type Parameters
    Name Description
    T
    Remarks

    Use this when the test needs an additional independent mock of the same service type, or when the mock will be wired manually instead of tracked through GetOrCreateMock<T>(MockRequestOptions?). Provider selection still flows through Default, but the returned handle is not added to the parent tracked mock collection.

    Dispose()

    Releases helper-owned disposable registrations created by this Mocker instance.

    Declaration
    public void Dispose()

    Dispose(bool)

    Releases managed resources owned by this Mocker instance. Derived types overriding this method should call the base implementation.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    true when called from Dispose(); otherwise, false.

    DisposeAsync()

    Asynchronously releases helper-owned disposable registrations created by this Mocker instance.

    Declaration
    public ValueTask DisposeAsync()
    Returns
    Type Description
    ValueTask

    A task that completes when owned registrations are disposed.

    DisposeAsyncCore()

    Asynchronously releases resources owned by this Mocker instance. Derived types overriding this method should call the base implementation.

    Declaration
    protected virtual ValueTask DisposeAsyncCore()
    Returns
    Type Description
    ValueTask

    A task that completes when asynchronous cleanup has finished.

    GetArgData<T>()

    Builds constructor argument data for T using the mocker's current optional-parameter policy.

    Declaration
    public object?[] GetArgData<T>() where T : class
    Returns
    Type Description
    object[]
    Type Parameters
    Name Description
    T

    GetArgData<T>(InstanceCreationFlags)

    Builds constructor argument data for T using the supplied creation flags.

    Declaration
    public object?[] GetArgData<T>(InstanceCreationFlags flags) where T : class
    Parameters
    Type Name Description
    InstanceCreationFlags flags
    Returns
    Type Description
    object[]
    Type Parameters
    Name Description
    T

    GetArgData<T>(OptionalParameterResolutionMode)

    Builds constructor argument data for T using the supplied optional-parameter policy.

    Declaration
    public object?[] GetArgData<T>(OptionalParameterResolutionMode optionalParameterResolution) where T : class
    Parameters
    Type Name Description
    OptionalParameterResolutionMode optionalParameterResolution
    Returns
    Type Description
    object[]
    Type Parameters
    Name Description
    T

    GetFileSystem()

    Returns the shared mock file system.

    Declaration
    public IFileSystem GetFileSystem()
    Returns
    Type Description
    IFileSystem

    GetFileSystem(Action<MockFileSystem>?)

    Returns the shared mock file system after optionally applying additional configuration.

    Declaration
    public IFileSystem GetFileSystem(Action<MockFileSystem>? configure = null)
    Parameters
    Type Name Description
    Action<MockFileSystem> configure
    Returns
    Type Description
    IFileSystem

    GetKeyedObject(Type, object, Action<object?>?)

    Resolves a keyed object for the specified service type.

    Declaration
    public object? GetKeyedObject(Type type, object serviceKey, Action<object?>? initAction = null)
    Parameters
    Type Name Description
    Type type
    object serviceKey
    Action<object> initAction
    Returns
    Type Description
    object

    GetKeyedObject<T>(object)

    Resolves a keyed object using the supplied service key.

    Declaration
    public T? GetKeyedObject<T>(object serviceKey) where T : class
    Parameters
    Type Name Description
    object serviceKey
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetKeyedObject<T>(object, Action<T?>)

    Resolves a keyed object and invokes an initialization callback with the typed result.

    Declaration
    public T? GetKeyedObject<T>(object serviceKey, Action<T?> init) where T : class
    Parameters
    Type Name Description
    object serviceKey
    Action<T> init
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetList<T>(int, Func<int, T>)

    Creates a list by invoking the supplied indexed factory a fixed number of times.

    Declaration
    public static List<T> GetList<T>(int count, Func<int, T> factory)
    Parameters
    Type Name Description
    int count
    Func<int, T> factory
    Returns
    Type Description
    List<T>
    Type Parameters
    Name Description
    T

    GetList<T>(int, Func<int, T>, Action<int, T>)

    Creates a list by invoking the supplied indexed factory and initializer a fixed number of times.

    Declaration
    public static List<T> GetList<T>(int count, Func<int, T> factory, Action<int, T> init)
    Parameters
    Type Name Description
    int count
    Func<int, T> factory
    Action<int, T> init
    Returns
    Type Description
    List<T>
    Type Parameters
    Name Description
    T

    GetList<T>(int, Func<T>)

    Creates a list by invoking the supplied factory a fixed number of times.

    Declaration
    public static List<T> GetList<T>(int count, Func<T> factory)
    Parameters
    Type Name Description
    int count
    Func<T> factory
    Returns
    Type Description
    List<T>
    Type Parameters
    Name Description
    T

    GetMethodArgData(MethodBase?)

    Builds invocation arguments for a method using the mocker's current optional-parameter policy.

    Declaration
    public object?[] GetMethodArgData(MethodBase? method)
    Parameters
    Type Name Description
    MethodBase method
    Returns
    Type Description
    object[]

    GetMethodArgData(MethodBase?, InvocationOptions?)

    Builds invocation arguments for a method using the supplied invocation options.

    Declaration
    public object?[] GetMethodArgData(MethodBase? method, InvocationOptions? options)
    Parameters
    Type Name Description
    MethodBase method
    InvocationOptions options
    Returns
    Type Description
    object[]

    GetMethodDefaultData(MethodBase?)

    Builds invocation arguments that contain only default values for the supplied method.

    Declaration
    public object?[] GetMethodDefaultData(MethodBase? method)
    Parameters
    Type Name Description
    MethodBase method
    Returns
    Type Description
    object[]

    GetMockModel<T>()

    Gets the tracked mock model for the supplied type parameter.

    Declaration
    public MockModel<T> GetMockModel<T>() where T : class
    Returns
    Type Description
    MockModel<T>
    Type Parameters
    Name Description
    T

    GetNativeMock(Type)

    Gets the provider-native mock object for the supplied runtime type. Prefer GetOrCreateMock(Type, MockRequestOptions?) plus provider-typed escape hatches when the test intentionally needs provider-specific APIs, and prefer GetObject(Type, Action<object?>?) or GetOrCreateMock(Type, MockRequestOptions?) for provider-first flows.

    Declaration
    public object GetNativeMock(Type type)
    Parameters
    Type Name Description
    Type type
    Returns
    Type Description
    object

    GetNativeMock<T>(params object?[])

    Gets the provider-native mock object for the supplied type parameter. Prefer GetOrCreateMock<T>(MockRequestOptions?) plus provider-typed escape hatches such as AsMoq() or AsNSubstitute() when the test intentionally needs a provider-specific API surface.

    Declaration
    public object GetNativeMock<T>(params object?[] args) where T : class
    Parameters
    Type Name Description
    object[] args
    Returns
    Type Description
    object
    Type Parameters
    Name Description
    T

    GetObject(ParameterInfo)

    Resolves a value for the supplied parameter using the mocker's constructor and object-resolution rules.

    Declaration
    public object? GetObject(ParameterInfo info)
    Parameters
    Type Name Description
    ParameterInfo info

    The parameter to resolve.

    Returns
    Type Description
    object

    The resolved value, or the parameter type default when resolution fails.

    GetObject(Type, Action<object?>?)

    Resolves an object using custom registrations, known types, tracked mocks, and default fallbacks.

    Declaration
    public object? GetObject(Type type, Action<object?>? initAction = null)
    Parameters
    Type Name Description
    Type type

    The requested service or concrete type.

    Action<object> initAction

    Optional callback invoked with the resolved value before it is returned.

    Returns
    Type Description
    object

    The resolved object instance, or the type default when no value can be created.

    GetObject<T>()

    Resolves an object using FastMoq's runtime resolution pipeline.

    Declaration
    public T? GetObject<T>() where T : class
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Examples

    Use GetObject<T>() when older code only needed GetMock<T>().Object and does not need the tracked mock handle itself.

    var mocker = new Mocker();
    var gateway = mocker.GetObject<IOrderGateway>();

    Resolve a dependency after configuring a concrete registration through the provider-first pipeline.

    var fileSystem = new MockFileSystem();
    fileSystem.AddDirectory(@"c:\exports");
    

    var mocker = new Mocker() .AddType<IFileSystem>(fileSystem);

    var resolvedFileSystem = mocker.GetRequiredObject<IFileSystem>();

    resolvedFileSystem.Directory.Exists(@"c:\exports").Should().BeTrue();

    GetObject<T>(Action<T?>)

    Resolves an object and invokes an initialization callback with the typed result.

    Declaration
    public T? GetObject<T>(Action<T?> init) where T : class
    Parameters
    Type Name Description
    Action<T> init
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetObject<T>(object?[])

    Creates an instance of T using the supplied constructor arguments.

    Declaration
    public T? GetObject<T>(object?[] args) where T : class
    Parameters
    Type Name Description
    object[] args
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetOrCreateMock(Type, MockRequestOptions?)

    Gets an existing tracked provider-backed mock or creates and tracks one when it does not yet exist. Use the returned IFastMock when the test needs the tracked handle itself, and prefer GetObject(Type, Action<object?>?) when only the instance is needed.

    Declaration
    public IFastMock GetOrCreateMock(Type type, MockRequestOptions? options = null)
    Parameters
    Type Name Description
    Type type
    MockRequestOptions options
    Returns
    Type Description
    IFastMock

    GetOrCreateMockWithConstructorArgs(Type, params object?[])

    Gets an existing tracked provider-backed mock or creates and tracks one when it does not yet exist, using the supplied constructor arguments for concrete mock creation.

    Declaration
    public IFastMock GetOrCreateMockWithConstructorArgs(Type type, params object?[] constructorArgs)
    Parameters
    Type Name Description
    Type type
    object[] constructorArgs
    Returns
    Type Description
    IFastMock
    Remarks

    This is a convenience wrapper for GetOrCreateMock(Type, MockRequestOptions?) when the request only needs constructor arguments. Use GetOrCreateMock(Type, MockRequestOptions?) when also setting a service key or non-public constructor behavior.

    GetOrCreateMockWithConstructorArgs<T>(params object?[])

    Gets an existing tracked provider-backed mock or creates and tracks one when it does not yet exist, using the supplied constructor arguments for concrete mock creation.

    Declaration
    public IFastMock<T> GetOrCreateMockWithConstructorArgs<T>(params object?[] constructorArgs) where T : class
    Parameters
    Type Name Description
    object[] constructorArgs
    Returns
    Type Description
    IFastMock<T>
    Type Parameters
    Name Description
    T
    Remarks

    This is a convenience wrapper for GetOrCreateMock<T>(MockRequestOptions?) when the request only needs constructor arguments. Use GetOrCreateMock<T>(MockRequestOptions?) when also setting a service key or non-public constructor behavior.

    GetOrCreateMock<T>(MockRequestOptions?)

    Gets an existing tracked provider-backed mock or creates and tracks one when it does not yet exist.

    Declaration
    public IFastMock<T> GetOrCreateMock<T>(MockRequestOptions? options = null) where T : class
    Parameters
    Type Name Description
    MockRequestOptions options
    Returns
    Type Description
    IFastMock<T>
    Type Parameters
    Name Description
    T
    Examples

    Use GetOrCreateMock<T>(MockRequestOptions?) when the test needs the tracked mock handle itself, not just automatic constructor resolution.

    fastMock.Instance is the provider-first replacement for older GetMock<T>().Object access when the test still wants the tracked handle.

    GetOrCreateMock uses the active FastMoq provider. It does not require the Moq provider to be selected unless the test later calls Moq-specific extensions such as AsMoq(), Setup(...), or Protected().

    var mocker = new Mocker();
    var gateway = mocker.GetOrCreateMock<IOrderGateway>();
    

    var submitter = new OrderSubmitter(gateway.Instance); submitter.Submit(42);

    mocker.Verify<IOrderGateway>(x => x.Publish(42), TimesSpec.Once); mocker.VerifyNoOtherCalls<IOrderGateway>();

    Provider-neutral usage works the same way under the reflection provider because the tracked handle is still an IFastMock<T>.

    using var providerScope = MockingProviderRegistry.Push("reflection");
    

    var mocker = new Mocker(); var dependency = mocker.GetOrCreateMock<IOrderGateway>();

    var submitter = new OrderSubmitter(dependency.Instance); submitter.Submit(42);

    mocker.Verify<IOrderGateway>(x => x.Publish(42), TimesSpec.Once);

    Typical reasons to call it explicitly are: passing Instance into custom component construction, reusing the same tracked mock across calls, resetting it, or using keyed MockRequestOptions. If the test needs Moq-specific setup or verification APIs, select the Moq provider for that test assembly before calling those extensions.

    GetRequiredObject<T>()

    Resolves a required object and throws when no instance can be produced.

    Declaration
    public T GetRequiredObject<T>() where T : class
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetRequiredTrackedMock(Type)

    Gets an already tracked provider-backed mock for the supplied runtime type and throws when no tracked mock exists.

    Declaration
    public IFastMock GetRequiredTrackedMock(Type type)
    Parameters
    Type Name Description
    Type type
    Returns
    Type Description
    IFastMock

    GetRequiredTrackedMock(Type, object)

    Gets an already tracked keyed provider-backed mock for the supplied runtime type and throws when no tracked mock exists for the supplied service key.

    Declaration
    public IFastMock GetRequiredTrackedMock(Type type, object serviceKey)
    Parameters
    Type Name Description
    Type type
    object serviceKey
    Returns
    Type Description
    IFastMock

    GetRequiredTrackedMock<T>()

    Gets an already tracked provider-backed mock and throws when no tracked mock exists.

    Declaration
    public IFastMock<T> GetRequiredTrackedMock<T>() where T : class
    Returns
    Type Description
    IFastMock<T>
    Type Parameters
    Name Description
    T

    GetRequiredTrackedMock<T>(object)

    Gets an already tracked keyed provider-backed mock and throws when no tracked mock exists for the supplied service key.

    Declaration
    public IFastMock<T> GetRequiredTrackedMock<T>(object serviceKey) where T : class
    Parameters
    Type Name Description
    object serviceKey
    Returns
    Type Description
    IFastMock<T>
    Type Parameters
    Name Description
    T

    GetStringContent(HttpContent?)

    Reads the string content from an HttpContent instance, returning an empty string when the content is null.

    Declaration
    public Task<string> GetStringContent(HttpContent? content)
    Parameters
    Type Name Description
    HttpContent content
    Returns
    Type Description
    Task<string>

    HasParameterlessConstructor(Type, bool)

    Determines whether the supplied type exposes a parameterless constructor.

    Declaration
    public bool HasParameterlessConstructor(Type type, bool nonPublic = false)
    Parameters
    Type Name Description
    Type type
    bool nonPublic
    Returns
    Type Description
    bool

    InvokeMethod(InvocationOptions?, object?, string, bool, params object?[])

    Invokes a method on the supplied instance using the supplied invocation options.

    Declaration
    public object? InvokeMethod(InvocationOptions? options, object? instance, string methodName, bool nonPublic = false, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    object instance
    string methodName
    bool nonPublic
    object[] args
    Returns
    Type Description
    object

    InvokeMethod(object?, string, bool, params object?[])

    Invokes a method on the supplied instance using the mocker's current invocation defaults.

    Declaration
    public object? InvokeMethod(object? instance, string methodName, bool nonPublic = false, params object?[] args)
    Parameters
    Type Name Description
    object instance
    string methodName
    bool nonPublic
    object[] args
    Returns
    Type Description
    object

    InvokeMethod<T>(InvocationOptions?, object?, string, bool, params object?[])

    Invokes a method declared on T using the supplied invocation options.

    Declaration
    public object? InvokeMethod<T>(InvocationOptions? options, object? instance, string methodName, bool nonPublic = false, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    object instance
    string methodName
    bool nonPublic
    object[] args
    Returns
    Type Description
    object
    Type Parameters
    Name Description
    T

    InvokeMethod<T>(InvocationOptions?, string, bool, params object?[])

    Invokes a method declared on T without an explicit instance parameter using the supplied invocation options.

    Declaration
    public object? InvokeMethod<T>(InvocationOptions? options, string methodName, bool nonPublic = false, params object?[] args)
    Parameters
    Type Name Description
    InvocationOptions options
    string methodName
    bool nonPublic
    object[] args
    Returns
    Type Description
    object
    Type Parameters
    Name Description
    T

    InvokeMethod<T>(object?, string, bool, params object?[])

    Invokes a method declared on T using the mocker's current invocation defaults.

    Declaration
    public object? InvokeMethod<T>(object? instance, string methodName, bool nonPublic = false, params object?[] args)
    Parameters
    Type Name Description
    object instance
    string methodName
    bool nonPublic
    object[] args
    Returns
    Type Description
    object
    Type Parameters
    Name Description
    T

    InvokeMethod<T>(string, bool, params object?[])

    Invokes a method declared on T without an explicit instance parameter.

    Declaration
    public object? InvokeMethod<T>(string methodName, bool nonPublic = false, params object?[] args)
    Parameters
    Type Name Description
    string methodName
    bool nonPublic
    object[] args
    Returns
    Type Description
    object
    Type Parameters
    Name Description
    T

    Scenario<T>(T?)

    Creates a new fluent scenario builder for the specified component type using provider-first creation.

    Declaration
    public ScenarioBuilder<T> Scenario<T>(T? instance = null) where T : class
    Parameters
    Type Name Description
    T instance
    Returns
    Type Description
    ScenarioBuilder<T>
    Type Parameters
    Name Description
    T

    TryGetTrackedMock(Type, out IFastMock?)

    Attempts to get an already tracked provider-backed mock for the supplied runtime type without creating one.

    Declaration
    public bool TryGetTrackedMock(Type type, out IFastMock? mock)
    Parameters
    Type Name Description
    Type type
    IFastMock mock
    Returns
    Type Description
    bool

    TryGetTrackedMock(Type, object, out IFastMock?)

    Attempts to get an already tracked keyed provider-backed mock for the supplied runtime type without creating one.

    Declaration
    public bool TryGetTrackedMock(Type type, object serviceKey, out IFastMock? mock)
    Parameters
    Type Name Description
    Type type
    object serviceKey
    IFastMock mock
    Returns
    Type Description
    bool

    TryGetTrackedMock<T>(out IFastMock<T>?)

    Attempts to get an already tracked provider-backed mock without creating one.

    Declaration
    public bool TryGetTrackedMock<T>(out IFastMock<T>? mock) where T : class
    Parameters
    Type Name Description
    IFastMock<T> mock
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    TryGetTrackedMock<T>(object, out IFastMock<T>?)

    Attempts to get an already tracked keyed provider-backed mock without creating one.

    Declaration
    public bool TryGetTrackedMock<T>(object serviceKey, out IFastMock<T>? mock) where T : class
    Parameters
    Type Name Description
    object serviceKey
    IFastMock<T> mock
    Returns
    Type Description
    bool
    Type Parameters
    Name Description
    T

    UseLenientPreset()

    Applies the predefined lenient behavior preset. This is broader than disabling FailOnUnconfigured alone.

    Declaration
    public void UseLenientPreset()

    UseStrictPreset()

    Applies the predefined strict behavior preset. This is broader than FastMoq.Mocker.Strict, which is retained for backward compatibility.

    Declaration
    public void UseStrictPreset()

    VerifyAnyArgs<T>(string, TimesSpec?, params Type[])

    Verifies calls to the named method while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyAnyArgs<T>(string methodName, TimesSpec? times = null, params Type[] parameterTypes) where T : class
    Parameters
    Type Name Description
    string methodName

    The instance method name to verify.

    TimesSpec? times

    The expected invocation count. When omitted, the helper expects at least one matching call.

    Type[] parameterTypes

    Optional parameter types used to disambiguate overloaded methods.

    Type Parameters
    Name Description
    T

    The tracked mock type to verify.

    Remarks

    Use this helper when a provider-neutral verification would otherwise require a long list of repeated Any<T>() markers. If the target method is overloaded, supply parameterTypes to choose the intended signature explicitly.

    VerifyAnyArgs<T, TDelegate>(Func<T, TDelegate>, TimesSpec?)

    Verifies calls to the selected method while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyAnyArgs<T, TDelegate>(Func<T, TDelegate> methodSelector, TimesSpec? times = null) where T : class where TDelegate : Delegate
    Parameters
    Type Name Description
    Func<T, TDelegate> methodSelector

    A method-group selector such as x => x.Publish.

    TimesSpec? times

    The expected invocation count. When omitted, the helper expects at least one matching call.

    Type Parameters
    Name Description
    T

    The tracked mock type to verify.

    TDelegate

    The delegate type used to identify the selected method.

    Remarks

    Prefer this overload when the method is not overloaded and you want compiler-verified member selection. For overloaded methods, use VerifyAnyArgs<T>(string, TimesSpec?, params Type[]) with explicit parameter types.

    VerifyCalledAtLeastAnyArgs<T>(string, int, params Type[])

    Verifies that the named method was called at least the supplied number of times while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledAtLeastAnyArgs<T>(string methodName, int times, params Type[] parameterTypes) where T : class
    Parameters
    Type Name Description
    string methodName
    int times
    Type[] parameterTypes
    Type Parameters
    Name Description
    T

    VerifyCalledAtLeastAnyArgs<T, TDelegate>(Func<T, TDelegate>, int)

    Verifies that the selected method was called at least the supplied number of times while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledAtLeastAnyArgs<T, TDelegate>(Func<T, TDelegate> methodSelector, int times) where T : class where TDelegate : Delegate
    Parameters
    Type Name Description
    Func<T, TDelegate> methodSelector
    int times
    Type Parameters
    Name Description
    T
    TDelegate

    VerifyCalledAtLeast<T>(Expression<Action<T>>, int)

    Verifies that the specified invocation occurred at least the supplied number of times on the tracked mock.

    Declaration
    public void VerifyCalledAtLeast<T>(Expression<Action<T>> expression, int times) where T : class
    Parameters
    Type Name Description
    Expression<Action<T>> expression
    int times
    Type Parameters
    Name Description
    T

    VerifyCalledAtMostAnyArgs<T>(string, int, params Type[])

    Verifies that the named method was called at most the supplied number of times while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledAtMostAnyArgs<T>(string methodName, int times, params Type[] parameterTypes) where T : class
    Parameters
    Type Name Description
    string methodName
    int times
    Type[] parameterTypes
    Type Parameters
    Name Description
    T

    VerifyCalledAtMostAnyArgs<T, TDelegate>(Func<T, TDelegate>, int)

    Verifies that the selected method was called at most the supplied number of times while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledAtMostAnyArgs<T, TDelegate>(Func<T, TDelegate> methodSelector, int times) where T : class where TDelegate : Delegate
    Parameters
    Type Name Description
    Func<T, TDelegate> methodSelector
    int times
    Type Parameters
    Name Description
    T
    TDelegate

    VerifyCalledAtMost<T>(Expression<Action<T>>, int)

    Verifies that the specified invocation occurred at most the supplied number of times on the tracked mock.

    Declaration
    public void VerifyCalledAtMost<T>(Expression<Action<T>> expression, int times) where T : class
    Parameters
    Type Name Description
    Expression<Action<T>> expression
    int times
    Type Parameters
    Name Description
    T

    VerifyCalledExactlyAnyArgs<T>(string, int, params Type[])

    Verifies that the named method was called exactly the supplied number of times while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledExactlyAnyArgs<T>(string methodName, int times, params Type[] parameterTypes) where T : class
    Parameters
    Type Name Description
    string methodName
    int times
    Type[] parameterTypes
    Type Parameters
    Name Description
    T

    VerifyCalledExactlyAnyArgs<T, TDelegate>(Func<T, TDelegate>, int)

    Verifies that the selected method was called exactly the supplied number of times while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledExactlyAnyArgs<T, TDelegate>(Func<T, TDelegate> methodSelector, int times) where T : class where TDelegate : Delegate
    Parameters
    Type Name Description
    Func<T, TDelegate> methodSelector
    int times
    Type Parameters
    Name Description
    T
    TDelegate

    VerifyCalledExactly<T>(Expression<Action<T>>, int)

    Verifies that the specified invocation occurred exactly the supplied number of times on the tracked mock.

    Declaration
    public void VerifyCalledExactly<T>(Expression<Action<T>> expression, int times) where T : class
    Parameters
    Type Name Description
    Expression<Action<T>> expression
    int times
    Type Parameters
    Name Description
    T

    VerifyCalledOnceAnyArgs<T>(string, params Type[])

    Verifies that the named method was called exactly once while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledOnceAnyArgs<T>(string methodName, params Type[] parameterTypes) where T : class
    Parameters
    Type Name Description
    string methodName
    Type[] parameterTypes
    Type Parameters
    Name Description
    T

    VerifyCalledOnceAnyArgs<T, TDelegate>(Func<T, TDelegate>)

    Verifies that the selected method was called exactly once while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyCalledOnceAnyArgs<T, TDelegate>(Func<T, TDelegate> methodSelector) where T : class where TDelegate : Delegate
    Parameters
    Type Name Description
    Func<T, TDelegate> methodSelector
    Type Parameters
    Name Description
    T
    TDelegate

    VerifyCalledOnce<T>(Expression<Action<T>>)

    Verifies that the specified invocation occurred exactly once on the tracked mock.

    Declaration
    public void VerifyCalledOnce<T>(Expression<Action<T>> expression) where T : class
    Parameters
    Type Name Description
    Expression<Action<T>> expression
    Type Parameters
    Name Description
    T

    VerifyNoOtherCalls<T>()

    Ensures no other calls were made for a given mock (provider-first only).

    Declaration
    public void VerifyNoOtherCalls<T>() where T : class
    Type Parameters
    Name Description
    T

    VerifyNotCalledAnyArgs<T>(string, params Type[])

    Verifies that the named method was never called while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyNotCalledAnyArgs<T>(string methodName, params Type[] parameterTypes) where T : class
    Parameters
    Type Name Description
    string methodName
    Type[] parameterTypes
    Type Parameters
    Name Description
    T

    VerifyNotCalledAnyArgs<T, TDelegate>(Func<T, TDelegate>)

    Verifies that the selected method was never called while treating every argument as a wildcard matcher.

    Declaration
    public void VerifyNotCalledAnyArgs<T, TDelegate>(Func<T, TDelegate> methodSelector) where T : class where TDelegate : Delegate
    Parameters
    Type Name Description
    Func<T, TDelegate> methodSelector
    Type Parameters
    Name Description
    T
    TDelegate

    VerifyNotCalled<T>(Expression<Action<T>>)

    Verifies that the specified invocation never occurred on the tracked mock.

    Declaration
    public void VerifyNotCalled<T>(Expression<Action<T>> expression) where T : class
    Parameters
    Type Name Description
    Expression<Action<T>> expression
    Type Parameters
    Name Description
    T

    Verify<T>(Expression<Action<T>>, TimesSpec?)

    Provider-first verification helper (provider agnostic).

    Declaration
    public void Verify<T>(Expression<Action<T>> expression, TimesSpec? times = null) where T : class
    Parameters
    Type Name Description
    Expression<Action<T>> expression
    TimesSpec? times
    Type Parameters
    Name Description
    T

    Implements

    IDisposable
    IAsyncDisposable

    Extension Methods

    DbContextMockerExtensions.GetDbContextHandle<TContext>(Mocker, DbContextHandleOptions<TContext>?)
    DbContextMockerExtensions.GetMockDbContext(Mocker, Type)
    DbContextMockerExtensions.GetMockDbContext<TContext>(Mocker)
    LoggingTestExtensions.AddCapturedLoggerFactory(Mocker, ILoggerProvider, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddCapturedLoggerFactory(Mocker, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddCapturedLoggerFactory(Mocker, Action<LogLevel, EventId, string, Exception?>, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddCapturedLoggerFactory(Mocker, Action<string>, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddLoggerFactory(Mocker, ILoggerFactory, bool)
    LoggingTestExtensions.AddLoggerFactory(Mocker, ILoggerProvider, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddLoggerFactory(Mocker, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddLoggerFactory(Mocker, Action<LogLevel, EventId, string, Exception?>, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.AddLoggerFactory(Mocker, Action<string>, Action<ILoggingBuilder>?, bool)
    LoggingTestExtensions.CreateLoggerFactory(Mocker, ILoggerProvider, Action<ILoggingBuilder>?)
    LoggingTestExtensions.CreateLoggerFactory(Mocker, Action<ILoggingBuilder>?)
    LoggingTestExtensions.CreateLoggerFactory(Mocker, Action<LogLevel, EventId, string, Exception?>, Action<ILoggingBuilder>?)
    LoggingTestExtensions.CreateLoggerFactory(Mocker, Action<string>, Action<ILoggingBuilder>?)
    LoggingTestExtensions.SetupLoggerCallback(Mocker, Action<LogLevel, EventId, string, Exception?>)
    LoggingTestExtensions.SetupLoggerCallback(Mocker, Action<LogLevel, EventId, string>)
    MethodResultExtensions.AddMethodCallbackAsync<TService>(Mocker, Expression<Func<TService, Task>>, Action, bool)
    MethodResultExtensions.AddMethodCallback<TService>(Mocker, Expression<Action<TService>>, Action, bool)
    MethodResultExtensions.AddMethodCompletionAsync<TService>(Mocker, Expression<Func<TService, Task>>, bool)
    MethodResultExtensions.AddMethodExceptionAsync<TService>(Mocker, Expression<Func<TService, Task>>, Exception, bool)
    MethodResultExtensions.AddMethodExceptionAsync<TService, TResult>(Mocker, Expression<Func<TService, Task<TResult>>>, Exception, bool)
    MethodResultExtensions.AddMethodException<TService>(Mocker, Expression<Action<TService>>, Exception, bool)
    MethodResultExtensions.AddMethodException<TService, TResult>(Mocker, Expression<Func<TService, TResult>>, Exception, bool)
    MethodResultExtensions.AddMethodResultAsync<TService, TResult>(Mocker, Expression<Func<TService, Task<TResult>>>, TResult, bool)
    MethodResultExtensions.AddMethodResult<TService, TResult>(Mocker, Expression<Func<TService, TResult>>, TResult, bool)
    MockerBooleanExtensions.Contains(Mocker, Type)
    MockerBooleanExtensions.Contains<T>(Mocker)
    MockerCreationExtensions.CreateInstance<T, TParam1>(Mocker, InstanceCreationFlags, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1>(Mocker, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2>(Mocker, InstanceCreationFlags, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2>(Mocker, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2, TParam3>(Mocker, InstanceCreationFlags, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2, TParam3>(Mocker, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2, TParam3, TParam4>(Mocker, InstanceCreationFlags, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2, TParam3, TParam4>(Mocker, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2, TParam3, TParam4, TParam5>(Mocker, InstanceCreationFlags, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateInstance<T, TParam1, TParam2, TParam3, TParam4, TParam5>(Mocker, Dictionary<Type, object?>)
    MockerCreationExtensions.CreateMockInternal(Mocker, Type, IReadOnlyCollection<object?>?, bool, bool)
    MockerCreationExtensions.CreateMockInternal<T>(Mocker, bool)
    MockerDiagnosticsExtensions.CreateDiagnosticsSnapshot(Mocker)
    MockerHttpExtensions.ConfigureHttpClient(Mocker, string, HttpStatusCode, string)
    MockerHttpExtensions.CreateHttpClient(Mocker, string, string, HttpStatusCode, string)
    MockerHttpExtensions.WhenHttpRequest(Mocker, Func<HttpRequestMessage, bool>, Func<HttpResponseMessage>)
    MockerHttpExtensions.WhenHttpRequest(Mocker, HttpMethod, string, Func<HttpResponseMessage>)
    MockerHttpExtensions.WhenHttpRequestJson(Mocker, HttpMethod, string, string, HttpStatusCode)
    ObjectExtensions.RaiseIfNull<T>(T?, string?, string?, int?, string?)
    OptionsTestExtensions.SetupOptions<T>(Mocker, bool)
    OptionsTestExtensions.SetupOptions<T>(Mocker, Func<T>, bool)
    OptionsTestExtensions.SetupOptions<T>(Mocker, T, bool)
    PropertySetterCaptureExtensions.AddPropertySetterCapture<TService, TValue>(Mocker, Expression<Func<TService, TValue>>, PropertyValueCapture<TValue>, bool)
    PropertySetterCaptureExtensions.AddPropertySetterCapture<TService, TValue>(Mocker, Expression<Func<TService, TValue>>, bool)
    PropertyStateExtensions.AddPropertyState<TService>(Mocker, PropertyStateMode, bool)
    PropertyStateExtensions.AddPropertyState<TService>(Mocker, bool)
    ServiceProviderTestExtensions.AddServiceProvider(Mocker, Action<IServiceCollection>?, bool, bool)
    ServiceProviderTestExtensions.AddServiceProvider(Mocker, IServiceProvider, bool)
    ServiceProviderTestExtensions.AddServiceScope(Mocker, IServiceScope, bool)
    ServiceProviderTestExtensions.AddServiceScope(Mocker, Action<IServiceCollection>?, bool, bool)
    ServiceProviderTestExtensions.AddServiceScope(Mocker, IServiceProvider, bool)
    ServiceProviderTestExtensions.AddTypedServiceProvider(Mocker, Action<IServiceCollection>?, bool, bool)
    ServiceProviderTestExtensions.AddTypedServiceScope(Mocker, Action<IServiceCollection>?, bool, bool)
    ServiceProviderTestExtensions.CreateTypedServiceProvider(Mocker, Action<IServiceCollection>?, bool)
    ServiceProviderTestExtensions.CreateTypedServiceScope(Mocker, Action<IServiceCollection>?, bool)
    TestClassExtensions.GetAmbiguousConstructorImplementationException(Mocker, Type)
    TestClassExtensions.GetAmbiguousImplementationException(Mocker, string)
    TestClassExtensions.GetAmbiguousImplementationException(Mocker, Type, ICollection<Type>?)
    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.GetTypeFromInterface(Mocker, Type, List<Type>?)
    TestClassExtensions.SetFieldValue<TObject>(TObject, string, object?)
    TestClassExtensions.SetPropertyValue<TObject>(TObject, string, object?)
    TestClassExtensions.VerifyLogged(Mocker, LogLevel, string)
    TestClassExtensions.VerifyLogged(Mocker, LogLevel, string, TimesSpec)
    TestClassExtensions.VerifyLogged(Mocker, LogLevel, string, Exception?, int?)
    TestClassExtensions.VerifyLogged(Mocker, LogLevel, string, Exception?, int?, int)
    TestClassExtensions.VerifyLogged(Mocker, LogLevel, string, Exception?, int?, TimesSpec?)
    TestClassExtensions.VerifyLogged(Mocker, LogLevel, string, int)
    TestClassExtensions.VerifyLoggedOnce(Mocker, LogLevel, string)
    TestClassExtensions.VerifyLoggedOnce(Mocker, LogLevel, string, Exception?, int?)
    TestClassExtensions.VerifyNotLogged(Mocker, LogLevel, string)
    TestClassExtensions.VerifyNotLogged(Mocker, LogLevel, string, Exception?, int?)
    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)
    In this article
    Back to top
    Generated 2026-04-29 03:53 UTC