devlooped / moq

The most popular and friendly mocking framework for .NET
Other
5.94k stars 802 forks source link

Moq should use CallBase to call default method from interfaces #1345

Closed alex-fomin closed 1 year ago

alex-fomin commented 1 year ago

The code example fails and there is no possibility to use default interface implementation in a mock.

void Main()
{
    var m = new Mock<IFoo>(MockBehavior.Strict)
    {
        CallBase = true
    };

    m.SetupGet(x => x.Bar).Returns(5);

// UserQuery.IFoo.Baz invocation failed with mock behavior Strict.
// All invocations on the mock must have a corresponding setup.
    Console.WriteLine(m.Object.Baz);
}

public interface IFoo {
    int Bar { get; }
    int Baz => Bar + 1;
}
alex-fomin commented 1 year ago

Sorry, duplicate with #1334