question: is it possible to clear the call history of a mock (or stub)?
( and with call history I don't mean the expected / recorded behaviour.)
The details:
I currently want am writing the following code with tests according the AAA syntax using NUnit and Rhino mocks.
public abstract class MockA
{
private bool _firstTime = true;
public void DoSomething()
{
if (_firstTime)
{
OnFirstDoSomething();
_firstTime = false;
}
}
public abstract void OnFirstDoSomething();
}
[TestFixture]
public class MockATest
{
[Test]
public void DoSomethingShouldSkipInitializationForSequentialCalls()
{
// Arrange
var mockA = MockRepository.GeneratePartialMock<MockA>();
mockA.Expect(x => x.OnFirstDoSomething()).Repeat.Any();
mockA.DoSomething(); // -> OnFirstDoSomething() is called
// here I want clear the call history of mockA
//Act
mockA.DoSomething(); // -> OnFirstDoSomething should NOT be called
mockA.DoSomething(); // -> OnFirstDoSomething should NOT be called
//assert
mockA.AssertWasNotCalled(x => x.OnFirstDoSomething());
}
}
For the readability I always try to focus the calls in the Assert section on the changes that occur within the Act section.
However, the arrange section in this test, contains a (required) action that influence the call history of mockA.
As a result the assert fails.
I known I could catch a 'change' in the call history using the construction below, but it makes the expected behaviour of this test less readable.
{
...
mockA.AssertWasCalled(x => x.OnFirstDoSomething(), opt => opt.Repeat.Once());
//Act
mockA.DoSomething();
//Assert
mockA.AssertWasCalled(x => x.OnFirstDoSomething(), opt => opt.Repeat.Once());
}
My question: is it possible to clear the call history of a mock (not recorded Expectations)?