NSubstitute
NSubstitute copied to clipboard
Check for Moq Arguments and Throw
Is your feature request related to a problem? Please describe.
I frequently switch between NSubstitute and Moq depending on which project I'm working on. It's quite easy, to get the Arg.Any<T> and It.IsAny<T> syntax of NSub and Moq mixed up. This doesn't generate any errors and can take a while to spot. I wasted two hours on this today and it ain't the first time.
To be clear, this is definitely user error but it would be an easy QoL improvement.
Describe the solution you'd like
When looking at method calls on substitutes, if we spot an It.IsX<T> argument, we should assume it's an error and throw a descriptive error telling the user they've accidentally used Moq syntax.
Describe alternatives you've considered In an ideal world, we shouldn't have both Moq and NSub installed in the same project, however, with IDEs getting smarter and smarter, it's often only a chord press to install a missing package for a type and a lot of us do that habitually as soon as we get a squiggly.
@hughesjs Sorry for the delay in replying. This is a good idea! Do you have time to attempt a PR? @tpodolak What do you think of an analyser for this? (in addition to runtime check in NSub)
How should we do this without making a dependency on Moq?