Hi there. I have created a dummy class and am testing both in natural and reflective mocks.
How come I need to define an expected call in the reflective mock example when I don't need to to define it in the natural mock?
EDIT: I am refering to why do i need to add the extra appleStackMock.ExpectCall("Push", 10); call?
Class
public static class AppleTree
{
private static Stack<Apple> apples;
public static void NewSeason()
{
apples = new Stack<Apple>();
for (int i = 0; i < 10; i++)
{
apples.Push(new Apple());
}
}
public static Apple PickApple()
{
if(apples.Count > 0)
{
return apples.Pop();
}
else
{
throw new AppleException("There are no more apples to pick!");
}
}
}
Natural Mock
[Test, VerifyMocks]
[ExpectedException(typeof(AppleException))]
public void TestExceptionIsThrownWhenThereAreNoMoreApplesToPick()
{
using (RecordExpectations rec = RecorderManager.StartRecording())
{
Stack<Apple> apples2 = new Stack<Apple>();
rec.ExpectAndReturn(apples2.Count, 0);
}
AppleTree.NewSeason();
AppleTree.PickApple();
}
Reflective Mock
[Test, VerifyMocks]
[ExpectedException(typeof(AppleException))]
public void ReflectiveMocks_TestExceptionIsThrownWhenThereAreNoMoreApplesToPick()
{
MockManager.Init();
Mock appleStackMock = MockManager.Mock(typeof(Stack<Apple>));
appleStackMock.ExpectCall("Push", 10);
appleStackMock.ExpectGet("Count", 0);
AppleTree.NewSeason();
AppleTree.PickApple();
}
Thanks!