NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Re-entrant sub creation causes LastCallRouter to be incorrectly cleared

Open dtchepak opened this issue 15 years ago • 1 comments

Setting a Returns() within a Returns() leads to global LastCallRouter being incorrect. May need to look at using a stack for LastCallRouter so we can handle this.

Example of bug: sub.SomeCall().Returns(CreateASub2()); ... ISub2 CreateASub2() { var sub2 = Substitute.For<ISub2>(); sub2.OtherCall().Returns(3); // <--- Problem here }

Working example thanks to Xerx: ~http://github.com/xerxesb/NSubstitute/commit/e9e2e3d2cedf2319045ebf9c529cee890b0e061d~

https://github.com/nsubstitute/NSubstitute/blob/f7fc2727ac2f35cbf2a69458fe710087a8c5a565/tests/NSubstitute.Acceptance.Specs/SubstituteTimingAndInteractions.cs#L60

dtchepak avatar Sep 15 '10 00:09 dtchepak

@dtchepak I've referenced this from a commit above. It's very naive/wrong and quite likely no help at all, but thought it was worth pushing in case it sparked an idea for you ;)

robdmoore avatar Dec 29 '12 03:12 robdmoore