I have several tests that when run in VS 2010 complete fine, but when run in VS 2013 fails with the following exception. The exception traces back to Isolate.WhenCalled lines, but only occur if the Isolate.Fake.Instance call is inside of the TestInitialize method and not locally done in the TestMethod.
For example, in the below code _calc is set in the TestInitialize method calc is set locally. The test fails when it hits the Isolate.WhenCalled() line for _calc. I am running 8.2.0.44 version of TypeMock, this was not an issue with 7.5.1.1.
private Calculator _calc;
[TestInitialize, Isolated]
public void InitializeIsolatedFakes()
{
_calc = Isolate.Fake.Instance<Calculator>(Members.ReturnRecursiveFakes);
}
[TestMethod, Isolated]
public void TestMethod1()
{
int resultStub = 10;
var calc = Isolate.Fake.Instance<Calculator>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => calc.Add(1, 2)).WillReturn(resultStub);
Isolate.WhenCalled(() => _calc.Add(1, 2)).WillReturn(resultStub);
var result = calc.Add(1, 2);
Assert.AreEqual(10, result);
}
TypeMock.TypeMockException :
*** Exception throw while recording calls. Please check:
* Are you trying to fake a field instead of a property? try to set field or use Isolate.Invoke.StaticConstructor
InnerException
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values.
at HoraceMann.Listbill.Test.Unit.Web.Business.McCamishFile.McCamishFileSenderTest.TestMethod2() in c:devALGCommonSAWMainHoraceMann.Listbill.Test.UnitWebBusinessMcCamishFileMcCamishFileSenderTest.cs:line 263
at HoraceMann.Listbill.Test.Unit.Web.Business.McCamishFile.McCamishFileSenderTest.TestMethod2() in c:devALGCommonSAWMainHoraceMann.Listbill.Test.UnitWebBusinessMcCamishFileMcCamishFileSenderTest.cs:line 0
--TargetInvocationException
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at TypeMock.ArrangeActAssert.BehaviorRecordingEngine.PerformRecording()
at TypeMock.ArrangeActAssert.RecordingEngineBase.Record(Boolean checkForEmptyRecordingBlock)
--ArgumentOutOfRangeException
at Mock0000IEaiFtpServiceClient.TriggerEaiFtpService(String fileName)
at HoraceMann.Listbill.Test.Unit.Web.Business.McCamishFile.McCamishFileSenderTest.<>c__DisplayClass2a.<TestMethod2>b__29() in c:devALGCommonSAWMainHoraceMann.Listbill.Test.UnitWebBusinessMcCamishFileMcCamishFileSenderTest.cs:line 263