Created
June 29, 2013 03:53
-
-
Save dtchepak/5889648 to your computer and use it in GitHub Desktop.
Example of NSubstitute type mismatch exception for nested returns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can not return value of type IFooProxy for IFoo.set_SomeString (expected type Void). | |
Make sure you called Returns() after calling your substitute (for example: mySub.SomeMethod().Returns(value)), | |
and that you are not configuring other substitutes within Returns() (for example, avoid this: mySub.SomeMethod().Returns(ConfigOtherSub())). | |
If you substituted for a class rather than an interface, check that the call to your substitute was on a virtual/abstract member. | |
Return values cannot be configured for non-virtual/non-abstract members. | |
Correct use: | |
mySub.SomeMethod().Returns(returnValue); | |
Potentially problematic use: | |
mySub.SomeMethod().Returns(ConfigOtherSub()); | |
Instead try: | |
var returnValue = ConfigOtherSub(); | |
mySub.SomeMethod().Returns(returnValue); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment