Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes between versions 4.2.1402.2112 and 4.2.1409.1722 broken setup property #164

Closed
justmara opened this issue Mar 23, 2015 · 2 comments
Labels

Comments

@justmara
Copy link

public interface ILogger
{
    bool IsDebugEnabled { get; }

    void Debug(object message);
}

public class LogWrapper : ILogger
{
        public virtual bool IsDebugEnabled
        {
            get { return true; }
        }

        public void Debug(object message)
        {
            if (IsDebugEnabled)
            {
                Console.WriteLine(message);
            }
        }
}

private void Checker(ILogger log)
{
    log.Debug("some message");
}

[TestMethod]
public void PropertyFails()
{
    var mock = new Mock<NLogWrapper>("fakelog");
    mock.Setup(o => o.IsDebugEnabled).Returns(false).Verifiable();
    Checker(mock.Object);
    mock.Verify(log => log.IsDebugEnabled, Times.Exactly(1));
}

This test works on 4.2.1402.2112 and fails on 4.2.1409.1722 and higher:

Result Message: 
Test method Ozon.Api.Common.Logging.Nlog.Test.Wrapper.PropertyFails threw exception: 
Moq.MockException: 
Expected invocation on the mock exactly 1 times, but was 0 times: log => log.IsDebugEnabled
No setups configured.

Performed invocations:
ILogger.Debug("some message", System.Object[])
Result StackTrace:  
at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable`1 setups, IEnumerable`1 actualCalls, Expression expression, Times times, Int32 callCount)
   at Moq.Mock.VerifyCalls(Interceptor targetInterceptor, MethodCall expected, Expression expression, Times times)
   at Moq.Mock.VerifyGet[T,TProperty](Mock`1 mock, Expression`1 expression, Times times, String failMessage)
   at Moq.Mock.Verify[T,TResult](Mock`1 mock, Expression`1 expression, Times times, String failMessage)
   at Moq.Mock`1.Verify[TResult](Expression`1 expression, Times times)
   at Ozon.Api.Common.Logging.Nlog.Test.Wrapper.PropertyFails()
@justmara
Copy link
Author

Direct call on mock.Object works. Problems begin when it is cast to interface while passed to Checker method.
Even simple (mock.Object as ILogger).Debug("some message"); makes it fail now.

@stakx stakx added the bug label Jun 20, 2017
@stakx stakx changed the title Changes between versions 4.2.1402.2112 and 4.2.1409.1722 broken setup ptoperty Changes between versions 4.2.1402.2112 and 4.2.1409.1722 broken setup property Jun 20, 2017
@stakx
Copy link
Contributor

stakx commented Jun 20, 2017

Fixed in Moq 4.7.58.

@stakx stakx closed this as completed Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants