-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hi
Thank you for this helpful project. I have been using it for a while, and the experience is very good.
Recently written a test that is supposed to make sure an error is logged when a conditions is met.
The error appears to be logged (stepping through with the debugger i see it) but VerifyLog(..) fails the test anyway.
The call to the log looks like this:
private void Alert() { logger.LogError(50100, "the description of the error goes here"); }
and the verifylog assertion looks like this
Mock.Get(logger).VerifyLog(l => l.LogError(50100, It.IsAny<string>()), Times.Once(), "an error must be logged");
the test output is strange:
Message:
Moq.VerifyLogException : an error must be logged
Expected invocation on the mock once, but was 0 times: l => l.LogError((EventId)50100, It.IsAny(), new[] { })
---- Moq.MockException : an error must be logged
Expected invocation on the mock once, but was 0 times: logger => logger.Log<It.IsAnyType>(LogLevel.Error, 50100, It.Is<It.IsAnyType>((v, t) => True), It.IsAny(), (Func<It.IsAnyType, Exception, string>)It.IsAny())
Performed invocations:
MockILogger:2 (logger):
ILogger.Log<FormattedLogValues>(LogLevel.Information, 0, KeepAliveMonitor started., null, Func<FormattedLogValues, Exception, string>)
ILogger.Log<FormattedLogValues>(LogLevel.Error, 50100, the description of the error goes here, null, Func<FormattedLogValues, Exception, string>)
Stack Trace:
VerifyLogExtensions.Verify[T](Mock1 loggerMock, Expression1 expression, Nullable1 times, Func1 timesFunc, String failMessage)
VerifyLogExtensions.VerifyLog(Mock1 loggerMock, Expression1 expression, Times times, String failMessage)
KeepAliveMonitorTest.Test_Alert_Fired(Int32 i) line 45
InvokeStub_KeepAliveMonitorTest.Test_Alert_Fired(Object, Span1) MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) ----- Inner Stack Trace ----- Mock.Verify(Mock mock, LambdaExpression expression, Times times, String failMessage) line 332 Mock1.Verify(Expression1 expression, Times times, String failMessage) line 770 VerifyLogExtensions.Verify[T](Mock1 loggerMock, Expression1 expression, Nullable1 times, Func`1 timesFunc, String failMessage)
why is the assertion failing the test ?