-
Notifications
You must be signed in to change notification settings - Fork 7
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
Verfying an error was logged fails #16
Comments
Hi, thanks for logging the issue. I am trying to reproduce in the following PR, but I am not able to do so. The only difference I see between your output and the output of a failing test in that branch is the concrete type used by the ILogger generic one. In your case is |
Thanks for taking the time to look!
I will try and provide more details tomorrow
…On Mon, 16 Sept 2024, 20:23 Adrian Iftode, ***@***.***> wrote:
Hi, thanks for logging the issue.
I am trying to reproduce in the following PR, but I am not able to do so.
The only difference I see between your output and the output of a failing
test in that branch
<https://ci.appveyor.com/project/adrianiftode/moq-ilogger/builds/50611739/tests>
is the concrete type used by the ILogger generic one. In your case is
FormattedLogValues which is a bit odd. Possible to provide more context,
maybe the setupt of the Mock?
—
Reply to this email directly, view it on GitHub
<#16 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLOIH7XHYTDFK4APPL2U33ZW4HZRAVCNFSM6AAAAABOHSXR72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJTGQ4TKNJSGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
firs of all , i am using the Microsoft provided dependency injection library in testing (too). so, to create a logger that will be a
and plug it in the DI like this and the test method looks like this:
|
Do you have tests that pass? |
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:
---- 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):
Stack Trace:
VerifyLogExtensions.Verify[T](Mock
1 loggerMock, Expression
1 expression, Nullable1 times, Func
1 timesFunc, String failMessage)VerifyLogExtensions.VerifyLog(Mock
1 loggerMock, Expression
1 expression, Times times, String failMessage)KeepAliveMonitorTest.Test_Alert_Fired(Int32 i) line 45
InvokeStub_KeepAliveMonitorTest.Test_Alert_Fired(Object, Span
1) 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 Mock
1.Verify(Expression1 expression, Times times, String failMessage) line 770 VerifyLogExtensions.Verify[T](Mock
1 loggerMock, Expression1 expression, Nullable
1 times, Func`1 timesFunc, String failMessage)why is the assertion failing the test ?
The text was updated successfully, but these errors were encountered: