-
Notifications
You must be signed in to change notification settings - Fork 264
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
Setting returnvalue to a substitute, previously configured in a AutoFixture.Register() call - throws CouldNotSetReturnDueToNoLastCallException #602
Comments
Thanks for the excellent repro case. 👍 Confirmed this behaviour on Mac, dotnetcore 2.0, NSub 4.2.1, AutoFixture 4.11.0. I'm not sure exactly why this is happening from a quick look, but I think it is related to nested substitute configuration. Setting For the
Hope this helps get your test working again until I can get a better answer for you. |
Thanks @MagnusMikkelsen for the nicely crafted scenario and @dtchepak for the brilliant analysis you did. The reasoning is exactly as described above. Upon receiving a call, NSubstitute remembers it as a "last" call, so that it could be configured by a subsequent call. In your case, the sequence is following:
This is an architectural issue which is quite hard to solve. That's why we introduced the It's very unpleasant side-effect on AutoFixture-NSubstitute boundary, but hopefully workaround helps to mitigate it. |
@MagnusMikkelsen Thanks! Let us know if you still need our assistance. |
Description
When setting the return value for a substitute method, where:
AutoFixture.Register()
callthe first Returns() method (
foo.GiveMeBar().Returns(bar)
in the example) throws a NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException.It is possible to workaround the problem by either
I have included these workarounds in the reproduction code as comments.
To Reproduce
Expected behaviour
I did not expect any exception, because I called Returns() after calling my substitute, and I am not configuring other substitutes within Returns().
Environment:
The text was updated successfully, but these errors were encountered: