I'm calling MockManager.Mock() within a foreach loop to set up expectations for a set number of instances of a particular type, as follows:
foreach (ApplicantType applicant in Applicants)
{
Mock employmentTypeMock = MockManager.Mock(typeof(EmploymentType), Constructor.Mocked);
employmentTypeMock.ExpectGet("EmploymentTypeId", new DynamicReturnValue(delegate(object[] parameters, object context) { return new int?(applicant.EmploymentTypeId); }));
}
The problem I'm having is that the tests will pass the majority of times, but occasionally will fail. It appears that the first mock is getting lost somewhere.
How can I go about tracking down the culprit here?