Created
September 10, 2011 13:05
-
-
Save xerxesb/1208285 to your computer and use it in GitHub Desktop.
NSubstitute: Stack Empty exception
This file contains 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
Bug or am i doing something stupid? Want to pretend that the first call to menu.PrintMenu() in GetSelection never happened by clearing received calls from the sub itself. | |
[TestFixture] | |
public class NSubBug | |
{ | |
public interface IMenu | |
{ | |
void PrintMenu(); | |
string GetUserSelection(); | |
} | |
public void GetSelection(IMenu menu) | |
{ | |
menu.PrintMenu(); | |
var userSelection = menu.GetUserSelection(); | |
if (userSelection == "m") | |
{ | |
menu.PrintMenu(); | |
} | |
} | |
[Test] | |
public void WhenUserSelectsPrintMenu() | |
{ | |
var menu = Substitute.For<IMenu>(); | |
menu.When(x => x.GetUserSelection()).Do(c => menu.ClearReceivedCalls()); | |
menu.GetUserSelection().Returns("m"); | |
GetSelection(menu); | |
menu.Received().PrintMenu(); //Expect only called once | |
} | |
} | |
==== Results in: | |
System.InvalidOperationException : Stack empty. | |
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) | |
at System.Collections.Generic.Stack`1.Pop() | |
at NSubstitute.Core.CallStack.Pop() | |
at NSubstitute.Core.ResultSetter.SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs) | |
at NSubstitute.Core.CallRouter.LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) | |
at NSubstitute.Core.SubstitutionContext.LastCallShouldReturn(IReturn value, MatchArgs matchArgs) | |
at NSubstitute.SubstituteExtensions.Returns[T](MatchArgs matchArgs, T returnThis, T[] returnThese) | |
at NSubstitute.SubstituteExtensions.Returns[T](T value, T returnThis, T[] returnThese) | |
at PuzzleGame.GameTests.MakeUserSelection(String menuOption) in c:\Users\Administrator\AppData\Local\NCrunch\3752\3\Game.cs:line 134 | |
at PuzzleGame.GameTests.WhenUserSelectsPrintMenu() in c:\Users\Administrator\AppData\Local\NCrunch\3752\3\Game.cs:line 112 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment