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
Implicitly implement substituted interfaces #250
Comments
Hi @jcansdale, If these are the only two methods on the interface (or the only two that return |
Arg, that's a shame. I'm substituting some pretty big and complex interfaces. 😢 The trick I was using with TypeMock was to create an interface that implements all of my target interfaces and mock that. Something like this: using EnvDTE;
public interface MyCodeClass : CodeClass, CodeElement, CodeType
{
} Alas this doesn't work with NSubstitute and CodeClass, CodeElement, CodeType end up with separate implementations. Apart from this the conversion has gone very smoothly! 😄 |
Sorry the final mile hasn't been that smooth, but happy to hear things went pretty well in general. :) If you need to do a lot of this you could try hacking something up with reflection.
This would be pretty terrible for test performance I'm guessing, but I think it would work. I'm not sure how to support this feature properly from NSubstitute. :-\ I'm open to any ideas :) |
Thanks for your reply. I just had another look to see what I could come up with. I've stumbled across a workaround that, while not pretty, isn't error prone like what I was doing before (defining returns individually for each interface). If I define a new abstract class like this: public abstract class ACodeClass : CodeClass, CodeElement, CodeType
{
} Ctrl-. offers an option that I'd never seen before: "Implement interface abstractly". If I do this and then substitute for this abstract class, the interfaces will be implemented implicitly. Although verbose, this works out fine. 😄 Ideally this behavior would be the default when doing Thanks again for your work on NSubstitute. It really has been a pleasure to use. 😄 BTW, I've been working on a library for mocking static methods, that has ended up integrating perfectly with NSubstitute. If you're interested, I've put a simple getting started page up here: |
Closing as part of a general cleanup of issues. Please re-open if any action is required. |
Hello,
Is there any way to implicitly implement the methods of substituted interfaces?
For example the following test current fails. Is there any way to make it pass without duplicating the
Returns
?It looks like the substituted class will look something like this:
Unfortunately this make the substituting of some COM interfaces particularly awkward.
The text was updated successfully, but these errors were encountered: