-
Notifications
You must be signed in to change notification settings - Fork 277
Description
From #152 (comment):
Stumbled upon this while attempting to validate a call into
Microsoft.Extensions.Logging.ILogger.The logger interface takes a
Tstate, but the "public" APIs (i.e. common extension methods) do not expose this directly.For example, consumer code calls it like this:
logger.Critical("A critical problem has occurred!");This is translated into a call to the interface's method, which has this signature:
public void Log<TState>( LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)The
stringparameter that represents the message in the original call is not passed directly into this method, but instead is wrapped in an internal type and passed asstate. Thus, it is actually impossible to perform an assertion onILogger, since you cannot specify theinternaltype without getting a compilation error.I actually solved this before by creating an
abstractTestableLoggerthat exposes a non-generic version of the base interface method and then redirecting the implementation to it, and then using.Receivedon top of that new method. Obviously, this is extremely convoluted.I'd really appreciate if NSubstitute provided a way to specify
Any<AnyType>()that would check for any generic argument on a given parameter.