I'm not sure if these problems are related, but they appear together, so I'll post them together.
I have a natural mock setup. The recorded mocks look like this:
MockManager.Init();
List<MessageInfo> noMessages = new List<MessageInfo>();
List<TimesheetComments> noComments = new List<TimesheetComments>();
Timesheet timesheet1 = timesheets[0]; // previously initialized
Timesheet timesheet2 = timesheets[1];
Timesheet timesheet3 = timesheets[2];
PayPeriod payPeriod1 =
PayPeriod.GetInstance("run1", DateTime.Now.AddDays(-28), DateTime.Now.AddDays(-35), PayRunStatus.Open, null, DateTime.Now.AddDays(-15), "USER", DateTime.Now);
PayPeriod payPeriod2 =
PayPeriod.GetInstance("run2", DateTime.Now.AddDays(-14), DateTime.Now.AddDays(-27), PayRunStatus.Open, null, DateTime.Now.AddDays(-1), "USER2", DateTime.Now);
PayPeriodCollection collection = new PayPeriodCollection();
collection.AddRange(new PayPeriod[] { payPeriod1, payPeriod2 });
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
Validator.Validate(null, null);
recorder.Return(noMessages).RepeatAlways();
TimesheetCommentDataStore commentDataStore;
TimesheetDataStore dataStore;
// Validate the timesheets
dataStore = new TimesheetDataStore();
dataStore.GetTimesheet(DateTime.Now, null, null, false);
recorder.Return(timesheet1);
commentDataStore = new TimesheetCommentDataStore();
commentDataStore.GetCommentsForTimesheet(null);
recorder.Return(noComments);
dataStore = new TimesheetDataStore();
dataStore.GetTimesheet(DateTime.Now, null, null, false);
recorder.Return(timesheet2);
commentDataStore = new TimesheetCommentDataStore();
commentDataStore.GetCommentsForTimesheet(null);
recorder.Return(noComments);
dataStore = new TimesheetDataStore();
dataStore.GetTimesheet(DateTime.Now, null, null, false);
recorder.Return(timesheet3);
commentDataStore = new TimesheetCommentDataStore();
commentDataStore.GetCommentsForTimesheet(null);
recorder.Return(noComments);
}
I also have a few reflective mocks set up afterwards.
When I trace the code through TypeMock, it seems to think that it needs to mock the "Timesheet" type 3 times once the using block has completed. It doesn't seem like that should be happening within the using() block, yet I don't set up mocks anywhere else.
I'm also getting this exception, which has appeared with this test failing:
System.TypeLoadException: Could not load type 'System.Nullable`1' from assembly 'TimeEntryClient, Version=0.2007.4.13, Culture=neutral, PublicKeyToken=null'.
at Corporate.TimeEntry.Client.UploadTimesheetsForm.AttemptEnumeratorMoveNext(IEnumerator enumerator)
at Corporate.TimeEntry.Client.UploadTimesheetsForm.validationBackgroundWorker_DoWork(Object sender, DoWorkEventArgs e) in C:Documents and SettingscedpjjoMy DocumentsVisual Studio 2005ProjectsTimeEntryTimeEntryClientUploadTimesheetsForm.cs:line 261
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
I believe this is related to the erroneous mocks of Timesheet.
This has happened in v4.0.3. I'm using VS2005.