Skip to content

Mocking an interface that has a sealed implementation of a method #1334

Closed as not planned

Description

@ricardo-noyolalozano
public interface MyInterface
{
    public sealed Task SealedMethod(Foo foo) => UnsealedMethod(foo.Name);
}

When I mock this interface and inject into the class I am testing, I get an exception thrown about it missing the sealed method. I was wondering whether there would be any support for this kind of interface.

Back this issue
Back this issue

Activity

  1. stakx commented on Mar 1, 2023

    @stakx
    Contributor

    This has to happen over at DynamicProxy's repo, see their issue at castleproject/Core#447.

  2. github-actions commented on Aug 24, 2024

    @github-actions

    Due to lack of recent activity, this issue has been labeled as 'stale'.
    It will be closed if no further activity occurs within 30 more days.
    Any new comment will remove the label.

  3. weitzhandler commented on Apr 1, 2025

    @weitzhandler
    Contributor

    Please add support for interface default implementation, not just sealed members. For example:

    public interface IInterface
    {
        int Value { get; }
        string FormattedValue => Value.ToString();
    }
    
    var mock = new Mock<IInterface>();
    mock.SetupGet(inter => inter.Value).Returns(5);
    IInterface interObj = mock.Object;
    
    var result = interObj.FormattedValue; // Expected "5", Actual null

    FormattedValue should also work for MockBehavior.Strict.

  4. github-actions commented on Sep 29, 2025

    @github-actions

    Due to lack of recent activity, this issue has been labeled as 'stale'.
    It will be closed if no further activity occurs within 30 more days.
    Any new comment will remove the label.

  5. weitzhandler commented on Sep 29, 2025

    @weitzhandler
    Contributor

    This is a relatively new C# feature, but still important.

  6. github-actions commented on Mar 29, 2026

    @github-actions

    Due to lack of recent activity, this issue has been labeled as 'stale'.
    It will be closed if no further activity occurs within 30 more days.
    Any new comment will remove the label.

  7. github-actions commented on Apr 28, 2026

    @github-actions

    This issue will now be closed since it has been labeled 'stale' without activity for 30 days.

  8. locked and limited conversation to collaborators on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions