Ok,
This could have quite a few implementations here is one:
// create fake data crawlers
mockDataCrawlers.Add(element1);
mockDataCrawlers.Add(element2);
using (RecordExpectations rec = RecorderManager.StartRecording())
{
// mock reportNotes (is created in method)
ReportNotes mockedReport = new ReportNotes();
// mock the elements
rec.ExpectAndReturn(element1.id,1);
data dataOfElement1 = element1.getData(); // keep mocked data
rec.Return(...);
rec.ExpectAndReturn(element1.id,2);
data dataOfElement2 = element2.getData(); // keep mocked data
rec.Return(...);
// make sure that the reports is called correctly
mockedReport.AddToReport(1, dataOfElement1, time1);
rec.CheckArguments();
mockedReport.AddToReport(2, dataOfElement2, time2);
rec.CheckArguments();
}
:arrow: Notice the
CheckArguments() this will tell TypeMock to fail if the arguments passed are not the same as expected and we expect AddToReport to be called the first time with 1, element1 and time1. Because element1 is mocked, TypeMock will check that the mock was passed!
:idea: There might be a case where you won't want to validate the time argument. We can then use:
mockedReport.AddToReport(0, null, null);
rec.CheckArguments(1,Check.IsMock(dataOfElement1), Check.IsAny());
mockedReport.AddToReport(0, null, null);
rec.CheckArguments(2,Check.IsMock(dataOfElement2), Check.IsAny());
:arrow: Notice that we now pass the arguments to the CheckArguments method, this give us more control on the argument checks.
See
Check.IsMock, this will verify that the argument passed is the actual mock.