You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
The text was updated successfully, but these errors were encountered:
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
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
This test works on 4.2.1402.2112 and fails on 4.2.1409.1722 and higher:
The text was updated successfully, but these errors were encountered: