FastMoq
Search Results for

    Show / Hide Table of Contents

    Class PropertyStateExtensions

    Provides first-party helpers for lightweight stateful interface properties without relying on provider-specific SetupAllProperties() behavior.

    Inheritance
    object
    PropertyStateExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastMoq.Extensions
    Assembly: FastMoq.Core.dll
    Syntax
    public static class PropertyStateExtensions

    Methods

    AddPropertyState<TService>(Mocker, PropertyStateMode, bool)

    Replaces the current interface registration with a proxy that preserves assignments for all readable and writable non-indexer properties while forwarding unrelated members to the previously resolved instance.

    Declaration
    public static TService AddPropertyState<TService>(this Mocker mocker, PropertyStateMode mode, bool replace = true) where TService : class
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    PropertyStateMode mode

    Controls whether property assignments also write through to the wrapped inner instance or stay on the proxy only.

    bool replace

    True to replace an existing registration for TService. Defaults to true because the helper intentionally swaps in a property-state proxy.

    Returns
    Type Description
    TService

    The proxy-backed instance now registered for TService.

    Type Parameters
    Name Description
    TService

    The interface type to wrap.

    Remarks

    Use ProxyOnly when the test needs detached property state on the proxy registration without mutating the previously wrapped instance.

    When you use this helper from a MockerTestBase<TComponent>-based test, add the helper during the setup phase or call CreateComponent() after the registration change so the component is rebuilt against the proxy-wrapped dependency.

    Examples
    var channel = Mocks.AddPropertyState<IOrderSubmissionChannel>(PropertyStateMode.ProxyOnly);
    CreateComponent();
    
    await Component.SubmitAsync("order-42", expedited: true, CancellationToken.None);
    
    channel.Mode.Should().Be("fast");

    AddPropertyState<TService>(Mocker, bool)

    Replaces the current interface registration with a proxy that preserves assignments for all readable and writable non-indexer properties while forwarding unrelated members to the previously resolved instance.

    Declaration
    public static TService AddPropertyState<TService>(this Mocker mocker, bool replace = true) where TService : class
    Parameters
    Type Name Description
    Mocker mocker

    The current Mocker instance.

    bool replace

    True to replace an existing registration for TService. Defaults to true because the helper intentionally swaps in a property-state proxy.

    Returns
    Type Description
    TService

    The proxy-backed instance now registered for TService.

    Type Parameters
    Name Description
    TService

    The interface type to wrap.

    Remarks

    This overload preserves the original write-through behavior by using WriteThrough.

    When you use this helper from a MockerTestBase<TComponent>-based test, add the helper during the setup phase or call CreateComponent() after the registration change so the component is rebuilt against the proxy-wrapped dependency.

    Examples
    var channel = Mocks.AddPropertyState<IOrderSubmissionChannel>();
    CreateComponent();
    
    await Component.SubmitAsync("order-42", expedited: true, CancellationToken.None);
    
    channel.Mode.Should().Be("fast");
    In this article
    Back to top
    Generated 2026-04-29 03:53 UTC