Help!
This code works fine on my local VS2010 with TypeMock, however fails on our build server, when ran through NCover.
My code:
using (RecordExpectations expect = RecorderManager.StartRecording())
{
74: RequestDataLayer.GetAllUsers();
75: expect.Return(DatabaseUsers);
// other definitions to follow
}
Yields this error on a CruiseControl.Net environment:
Execute
TypeMock.TypeMockException:
*** Cannot use Return in this sequence, there must be a mocked statement first
Perhaps you are trying to mock a method from mscorlib
at TypeMock.RecordExpectations.b(String A_0)
at TypeMock.RecordExpectations.a(String A_0)
at TypeMock.RecordExpectations.Return(Object returnValue)
at Request.UserSyncTest.SyncData() in UserSyncTest.cs:line 75
The source for the method I try to mock is:
public class RequestDataLayer
{
public static User[] GetAllUsers()
{
// some LINQ magic to get users out of DB, then a .ToArray()
// returns an object array
}
}
So there isn't anything special to it, apart from the fact the method is static. Since then I refactored the method to make it nonstatic, effects on the bottom of this page.
I had a similar issue previously, this was to do with exploiting the Isolate<> syntax of TypeMock, I ran into the same scenario, of tests working fine locally (through Gallio test runner), but failing on the build server (CC.Net, Gallio, TypeMock, NCover).
I'm running 6.0.4.0 of TypeMock on both dev and build boxes.
Also, what seems to have worked was moving lines 74 and 75 down in the RecordExpectations block - the error didn't show, BUT the method call simply wasn't mocked silently.
Ideas welcome.
OK, we found out what the problem was - embarassingly enough TypeMock wasn't properly called through the NAnt script.
This is still a mystery however why we didn't simply see the "TypeMock" is not enabled error message, but this weird behaviour instead.