-
-
Notifications
You must be signed in to change notification settings - Fork 805
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
add It.Ignore for AnyMatcher #790
Conversation
Hi @helloserve, thanks for raising this issue (well, PR actually). I'll review it soon and look at .NET Core 3 a little more closely. In the meantime, remember that you don't need to wait for Moq to have a suitable matcher, you can simply create a custom matcher yourself, using static T Ignore<T>()
{
return Match.Create(x => true, () => Ignore<T>());
} |
Ah right. Now I feel kinda dumb. I did not know about Custom matchers. Thanks! |
@helloserve, sorry for the long silence, I've actually been looking into this several weeks ago and seen that custom matchers don't help in your case, after all. I can see how this PR would help solve some situations that Moq currently doesn't have any other solution for. On the other hand, I'd really prefer that we didn't have to add this I've been thinking that we might add it but keep it from showing up in IntelliSense using Do you see any other solutions for what you want to achieve? |
I completely feel the same way about it. Having to ignore a parameter seems counter intuitive to setting up a mock, and matching invocations specifically is crucial to prevent false-positive results. Or at least, I can totally see how false positives can occur when using I think the only really clean solution here is if C# can introduce the So while we wait for that, Personally I don't believe that Moq itself has a larger problem to solve here. The implementation policies of the Core framework is what is changing and causing this, after all. That said, the guy that responded to my issue on the abstraction package said
How to do that without having |
I believe that #343 is about just that.
Agreed. And as such, we shouldn't add it to Moq because once added, it will no longer be able to stay "temporary"—removing it again will be a breaking change. I suggest that we don't merge this PR for the above reasons and instead keep at #343. |
While experimenting with .NET Core 3.0 preview I ran into a problem where they were no longer boxing an internal class to
object
to theILogger.Log<TState>
abstraction. This means that I can no longerSetup
orVerify
against that abstraction, sinceIt.IsAny<>()
has to exactly match the invocation types. See dotnet/extensions#1319 for the details on this. And really, as we discover more changes in 3.0 Preview I expect to see more of these decisions impacting us.The only solution I can think of is to have a way to completely short-circuit on specific parameters (who's types you cannot see) by explicitly choosing to do so via a new
It.Ignore<>()
method.I don't expect you to merge this in to 4.0 at all, but rather to see it as a feature request for 5.0 via implementation. However if 3.0 is finalized and lands before Moq 5.0 ships I expect a few projects will be broken when they upgrade. At least then you'll have this to decide to include or not.