moq
moq copied to clipboard
Mocking an interface that has a sealed implementation of a method
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.
This has to happen over at DynamicProxy's repo, see their issue at https://github.com/castleproject/Core/issues/447.
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.
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.
