Why not build new Fakes for each test? That will solve the problem.
If setting up the new fake every time is a complicated chunk of code, write a helper function to setup the new fake.
Pregunta
I use fake it easy to generate fakes for my object. Now I test if some of the methods on the fake objects where called. The thing is I want for each unit test to reset the state of the fake back to original state.
I need this because I generate the fakes once for each unit test class so I would need to somehow reset the call state.
This is how my code looks like:
[Test]
public void Test_Process_SampleMessageNEW_Should_Call_ISampleMessageConverter_GetRouteObject()
{
//Arrange
//should reset the state of the fakes, _sampleRouteConvertor and _orderDalcMock are fakes
_sampleRouteConvertor.BackToRecord();
_orderDalcMock.BackToRecord();
A.CallTo(() => _orderDalcMock.GetOrder(A<IRQOrderIDCriteria>.Ignored))
.Returns(new OrderDTO() {Id = nextId++});
SampleMessage sampleMessage = SampleMessageTestHelpers.GetSavedSampleMessage();
sampleMessage.MaterialId = CacheMaterials.GetMaterials()[0].Code;
sampleMessage.MessageType = "NEW";
//Act
SampleMessageProcessor sampleMessageProcessor = new SampleMessageProcessor(sampleMessage);
sampleMessageProcessor.Process();
//Assert
A.CallTo(() => _sampleRouteConvertor.GetRouteObject(A<RoutineSample>.Ignored, A<List<ICacheTrackArea>>.Ignored))
.MustHaveHappened(Repeated.Exactly.Once);
}
Solución
Why not build new Fakes for each test? That will solve the problem.
If setting up the new fake every time is a complicated chunk of code, write a helper function to setup the new fake.