-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Feature request: enable verification of extension-methods calls #1045
Comments
If you want to do this the right way, it's basically impossible, unless you use the CLR's unmanaged Profiling API; but then you sacrifice portability (think e.g. Mono) so that's currently a no-go.
That's very similar to how expression reconstruction works for That approach has several downsides, basically it only works correctly under very specific conditions. If we used that approach to support extension methods, we'd have to assume that extension methods deterministically call exactly one virtual, overridable method on the IMHO it's best not to go there... this will complicate Moq internals quite a bit, make Moq's LINQ expression tree handling less precise, and it'll be a fragile feature at best. As such is begging for support questions and false bug reports. |
Your kind and comprehensive answer makes a lot of sense. |
Why doesn't this work: It.IsAny<Func<It.IsAnyType, Exception, string>>() Whereas this one does? It.Is<Func<It.IsAnyType, Exception, string>>((func, type) => true))
|
Hi,
I often come across mocks that expose complex methods with multiple complex parameters of lambdas etc.
Those methods are provided with companion methods that enable passing just one or two primitive-type arguments delegate them to the actual complex method.
Let's use the
Microsoft.Extensions.Logging.ILogger.Log
method as an example. It has the following signature:Pretty complex, but in essence you would almost never call it directly and would instead call the various extension methods in
LoggerExtensions
.I wonder how hard it could be enabling verification through extension methods.
One way could be (and I'm sure there would be other, better, ideas), when calling
LogWarning
(LogWarning (this ILogger logger, string message, params object[] args);
, could we internally prepare a verification expectation by recording what's being called downstream on a similar dummy mock, so that we could then verify it was called on the actual mock?That would enable us to write
which is what we actually want to verify, instead of the one that's so tedious and taking so long to figure out and make it work
I'm willing to contribute.
The text was updated successfully, but these errors were encountered: