I have a class that receives an ILogger and I want to mock the LogInformation calls but this is an extension method. How do I make the appropiate setup call for this?
See Question&Answers more detail:osI have a class that receives an ILogger and I want to mock the LogInformation calls but this is an extension method. How do I make the appropiate setup call for this?
See Question&Answers more detail:osIf you're using Moq >= 4.13, here is a way to mock ILogger
:
logger.Verify(x => x.Log(
It.IsAny<LogLevel>(),
It.IsAny<EventId>(),
It.IsAny<It.IsAnyType>(),
It.IsAny<Exception>(),
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()));
You can change the It.IsAny<LogLevel>()
, It.IsAny<EventId>()
, and It.IsAny<Exception>()
stubs to be more specific, but using It.IsAnyType
is necessary because FormattedLogValues
is now internal
.
Reference: TState in ILogger.Log used to be object, now FormattedLogValues